Code revision after 2 years
This commit is contained in:
parent
e412e0c173
commit
94f905e917
16 changed files with 114 additions and 148 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
image
|
||||||
|
generate
|
BIN
Bez_nadeje.png
BIN
Bez_nadeje.png
Binary file not shown.
Before Width: | Height: | Size: 85 KiB |
9
Makefile
Normal file
9
Makefile
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
image: image.cpp
|
||||||
|
g++ image.cpp -o image -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs
|
||||||
|
|
||||||
|
generate: generate.cpp
|
||||||
|
g++ generate.cpp -o generate
|
||||||
|
|
||||||
|
folders: cards/factions.json
|
||||||
|
for jmeno in $$(cat cards/factions); do mkdir cards/$$jmeno && mkdir cards/$$jmeno; done
|
1
bruhmbor
1
bruhmbor
|
@ -1 +0,0 @@
|
||||||
bruh
|
|
|
@ -1,5 +1,4 @@
|
||||||
[
|
[
|
||||||
"universal",
|
|
||||||
"northern-kingdoms",
|
"northern-kingdoms",
|
||||||
"monsters",
|
"monsters",
|
||||||
"nilfgaard",
|
"nilfgaard",
|
||||||
|
|
|
@ -4,7 +4,5 @@
|
||||||
"faction": "My Ass",
|
"faction": "My Ass",
|
||||||
"line": "balls",
|
"line": "balls",
|
||||||
"power": 0,
|
"power": 0,
|
||||||
"traits": [
|
"traits": []
|
||||||
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 449 KiB |
|
@ -1,11 +0,0 @@
|
||||||
{
|
|
||||||
"display": "Tester",
|
|
||||||
"faction": "universal",
|
|
||||||
"line": "front",
|
|
||||||
"name": "test",
|
|
||||||
"power": 0,
|
|
||||||
"traits": [
|
|
||||||
"spy",
|
|
||||||
"double"
|
|
||||||
]
|
|
||||||
}
|
|
Binary file not shown.
Before Width: | Height: | Size: 85 KiB |
31
folders.cpp
31
folders.cpp
|
@ -1,31 +0,0 @@
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
using nlohmann::json;
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
std::ifstream f1("cards/template.json");
|
|
||||||
json data = json::parse(f1);
|
|
||||||
|
|
||||||
std::ifstream f2("cards/traits.json");
|
|
||||||
json traits = json::parse(f2);
|
|
||||||
|
|
||||||
|
|
||||||
std::ifstream f3("cards/factions.json");
|
|
||||||
json factions = json::parse(f3);
|
|
||||||
|
|
||||||
std::ifstream f4("cards/lines.json");
|
|
||||||
json lines = json::parse(f4);
|
|
||||||
|
|
||||||
for(auto f : factions) {
|
|
||||||
string command = "mkdir cards/" + string(f) + "/images";
|
|
||||||
std::system(command.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
//std::ofstream out("cards/"+factions[faction]+"/"+name+".json");
|
|
||||||
return 0;
|
|
||||||
}
|
|
BIN
generate
BIN
generate
Binary file not shown.
86
generate.cpp
86
generate.cpp
|
@ -1,51 +1,53 @@
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
int main() {
|
string get(json j, string name) {
|
||||||
std::ifstream f1("cards/template.json");
|
std::cout << name << " (";
|
||||||
json data = json::parse(f1);
|
for(int i = 0; i < j.size(); ++i)
|
||||||
|
std::cout << i << ':' << j[i] << ' ';
|
||||||
std::ifstream f2("cards/traits.json");
|
std::cout << ") : ";
|
||||||
json traits = json::parse(f2);
|
int index; std::cin >> index;
|
||||||
|
if(index < 0 || index >= j.size())
|
||||||
|
return "";
|
||||||
std::ifstream f3("cards/factions.json");
|
return j[index];
|
||||||
json factions = json::parse(f3);
|
}
|
||||||
|
|
||||||
std::ifstream f4("cards/lines.json");
|
int main() {
|
||||||
json lines = json::parse(f4);
|
std::ifstream f1("cards/template.json");
|
||||||
|
json data = json::parse(f1);
|
||||||
std::cout << "Name: ";
|
|
||||||
string name; std::cin >> name; data["name"] = name;
|
std::ifstream f2("cards/traits.json");
|
||||||
|
json traits = json::parse(f2);
|
||||||
std::cout << "Display name: ";
|
|
||||||
std::cin.ignore();
|
std::ifstream f3("cards/factions.json");
|
||||||
string display; std::getline(std::cin, display); data["display"] = display;
|
json factions = json::parse(f3);
|
||||||
|
|
||||||
std::cout << "Faction (0:Universal,1:SK,2:M,3:N,4:S): ";
|
std::ifstream f4("cards/lines.json");
|
||||||
int faction; std::cin >> faction; data["faction"] = factions[faction];
|
json lines = json::parse(f4);
|
||||||
|
|
||||||
std::cout << "Line (0:front, 1:middle, 2:back): ";
|
std::cout << "Name: ";
|
||||||
int line; std::cin >> line; data["line"] = lines[line];
|
std::cin.ignore();
|
||||||
|
string name; std::getline(std::cin, name);
|
||||||
std::cout << "Power: ";
|
data["name"] = name;
|
||||||
int power; std::cin >> power; data["power"] = power;
|
|
||||||
|
data["faction"] = get(factions, "Faction");
|
||||||
std::cout << "Traits (0:End,1:Spy,2:Double,3:Boost,4:Call-to-arms,5:Horn,6:Revive,7:Destroy): ";
|
|
||||||
int trait = -1;
|
data["line"] = get(lines, "Line");
|
||||||
while(trait != 0) {
|
|
||||||
if(trait != -1) data["traits"].push_back(traits[trait-1]);
|
std::cout << "Power: ";
|
||||||
std::cin >> trait;
|
int power; std::cin >> power; data["power"] = power;
|
||||||
}
|
|
||||||
|
for(string trait = get(traits, "Trait"); trait != ""; trait = get(traits, "Trait"))
|
||||||
std::ofstream out("cards/"+string(factions[faction])+"/"+name+".json");
|
if(trait != "")
|
||||||
|
data["traits"].push_back(trait);
|
||||||
out << data.dump(2) << std::endl;
|
|
||||||
return 0;
|
std::ofstream out("cards/"+string(data["faction"])+"/"+name+".json");
|
||||||
|
|
||||||
|
out << data.dump(2) << std::endl;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
1
icom
1
icom
|
@ -1 +0,0 @@
|
||||||
g++ image.cpp -o image -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs
|
|
BIN
image
BIN
image
Binary file not shown.
116
image.cpp
116
image.cpp
|
@ -19,73 +19,73 @@ using std::string;
|
||||||
|
|
||||||
Mat source_image = Mat::zeros(Size(H,W),CV_8UC1);
|
Mat source_image = Mat::zeros(Size(H,W),CV_8UC1);
|
||||||
void render(int i, int j, int y_s, int x_s, Mat *img) {
|
void render(int i, int j, int y_s, int x_s, Mat *img) {
|
||||||
if(i >= y_s && i <= y_s+R-1 && j >= x_s && j <= x_s+R-1) {
|
if(i >= y_s && i <= y_s+R-1 && j >= x_s && j <= x_s+R-1) {
|
||||||
source_image.at<uchar>(i,j)=img->at<uchar>(i-y_s,j-x_s);
|
source_image.at<uchar>(i,j)=img->at<uchar>(i-y_s,j-x_s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
|
||||||
// FACTION
|
// FACTION
|
||||||
int fac;
|
int fac;
|
||||||
if(argc <= 1) {
|
if(argc <= 1) {
|
||||||
std::cout << "0:U,1:SK,2:M,3:N,4:S";
|
std::cout << "0:U,1:SK,2:M,3:N,4:S";
|
||||||
std::cin >> fac;
|
std::cin >> fac;
|
||||||
}
|
}
|
||||||
else fac = std::atoi(argv[1]);
|
else fac = std::atoi(argv[1]);
|
||||||
|
|
||||||
std::ifstream ff("cards/factions.json");
|
std::ifstream ff("cards/factions.json");
|
||||||
json factions = json::parse(ff);
|
json factions = json::parse(ff);
|
||||||
string faction = factions[fac];
|
string faction = factions[fac];
|
||||||
|
|
||||||
// NAME
|
// NAME
|
||||||
string name;
|
string name;
|
||||||
if(argc <= 2) std::cin >> name;
|
if(argc <= 2) std::cin >> name;
|
||||||
else name = argv[2];
|
else name = argv[2];
|
||||||
std::ifstream f("cards/"+faction+"/"+name+".json");
|
std::ifstream f("cards/"+faction+"/"+name+".json");
|
||||||
json data = json::parse(f);
|
json data = json::parse(f);
|
||||||
|
|
||||||
// LOAD IMAGES
|
// LOAD IMAGES
|
||||||
Mat i_look = imread("cards/"+faction+"/images/"+name+".png",IMREAD_GRAYSCALE);
|
Mat i_look = imread("cards/"+faction+"/images/"+name+".png",IMREAD_GRAYSCALE);
|
||||||
Mat i_faction = imread("cards/images/factions/"+faction+".png",IMREAD_GRAYSCALE);
|
Mat i_faction = imread("cards/images/factions/"+faction+".png",IMREAD_GRAYSCALE);
|
||||||
Mat i_line = imread("cards/images/lines/"+string(data["line"])+".png",IMREAD_GRAYSCALE);
|
Mat i_line = imread("cards/images/lines/"+string(data["line"])+".png",IMREAD_GRAYSCALE);
|
||||||
|
|
||||||
// RENDER IMAGES
|
// RENDER IMAGES
|
||||||
std::vector<Mat> i_traits;
|
std::vector<Mat> i_traits;
|
||||||
for(auto trait : data["traits"]) {
|
for(auto trait : data["traits"]) {
|
||||||
i_traits.push_back(imread("cards/images/traits/"+string(trait)+".png",IMREAD_GRAYSCALE));
|
i_traits.push_back(imread("cards/images/traits/"+string(trait)+".png",IMREAD_GRAYSCALE));
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i=0;i<source_image.rows;i++)
|
for(int i=0;i<source_image.rows;i++)
|
||||||
for(int j=0;j<source_image.cols;j++)
|
for(int j=0;j<source_image.cols;j++)
|
||||||
source_image.at<uchar>(i,j)=i_look.at<uchar>(i,j);
|
source_image.at<uchar>(i,j)=i_look.at<uchar>(i,j);
|
||||||
|
|
||||||
// RENDER POWER AND TRAITS
|
// RENDER POWER AND TRAITS
|
||||||
string bruh = std::to_string((int)data["power"]);
|
string bruh = std::to_string((int)data["power"]);
|
||||||
for(int i=0;i<source_image.rows;i++) {
|
for(int i=0;i<source_image.rows;i++) {
|
||||||
for(int j=0;j<source_image.cols;j++) {
|
for(int j=0;j<source_image.cols;j++) {
|
||||||
// Vlevo nahoře sílu
|
// Vlevo nahoře sílu
|
||||||
putText(
|
putText(
|
||||||
source_image,
|
source_image,
|
||||||
bruh,
|
bruh,
|
||||||
Point(M,M),
|
Point(M,M),
|
||||||
FONT_HERSHEY_COMPLEX_SMALL,
|
FONT_HERSHEY_COMPLEX_SMALL,
|
||||||
1,
|
1,
|
||||||
Scalar(0,0,0),
|
Scalar(0,0,0),
|
||||||
2
|
2
|
||||||
);
|
);
|
||||||
|
|
||||||
render(i,j, M,W/2-R/2, &i_faction);
|
render(i,j, M,W/2-R/2, &i_faction);
|
||||||
render(i,j, M,W-M-R, &i_line);
|
render(i,j, M,W-M-R, &i_line);
|
||||||
// Traits
|
// Traits
|
||||||
for(int k = 0; k < i_traits.size(); k++)
|
for(int k = 0; k < i_traits.size(); k++)
|
||||||
render(i,j, H-M-R,W-M-R*(k+1), &i_traits[k]);
|
render(i,j, H-M-R,W-M-R*(k+1), &i_traits[k]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
imshow("Result",source_image);
|
imshow("Result",source_image);
|
||||||
waitKey(0);
|
waitKey(0);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
BIN
notes.xopp
BIN
notes.xopp
Binary file not shown.
Loading…
Reference in a new issue