Rewrite generator script to Python + unite json files
This commit is contained in:
parent
94f905e917
commit
8755949180
9 changed files with 80 additions and 99 deletions
6
Makefile
6
Makefile
|
@ -1,9 +1,3 @@
|
||||||
|
|
||||||
image: image.cpp
|
image: image.cpp
|
||||||
g++ image.cpp -o image -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs
|
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
|
|
||||||
|
|
29
cards/config.json
Normal file
29
cards/config.json
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
{
|
||||||
|
"lines": [
|
||||||
|
"front",
|
||||||
|
"middle",
|
||||||
|
"back"
|
||||||
|
],
|
||||||
|
"traits": [
|
||||||
|
"spy",
|
||||||
|
"double",
|
||||||
|
"boost",
|
||||||
|
"call-to-arms",
|
||||||
|
"horn",
|
||||||
|
"revive",
|
||||||
|
"destroy"
|
||||||
|
],
|
||||||
|
"factions": [
|
||||||
|
"northern-kingdoms",
|
||||||
|
"monsters",
|
||||||
|
"nilfgaard",
|
||||||
|
"scoiatael"
|
||||||
|
],
|
||||||
|
"template": {
|
||||||
|
"name": "",
|
||||||
|
"faction": "",
|
||||||
|
"line": "",
|
||||||
|
"power": 0,
|
||||||
|
"traits": []
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +0,0 @@
|
||||||
[
|
|
||||||
"northern-kingdoms",
|
|
||||||
"monsters",
|
|
||||||
"nilfgaard",
|
|
||||||
"scoiatael"
|
|
||||||
]
|
|
|
@ -1,5 +0,0 @@
|
||||||
[
|
|
||||||
"front",
|
|
||||||
"middle",
|
|
||||||
"back"
|
|
||||||
]
|
|
|
@ -1,12 +0,0 @@
|
||||||
{
|
|
||||||
"display": "oligarchie",
|
|
||||||
"faction": "northern-kingdoms",
|
|
||||||
"line": "front",
|
|
||||||
"name": "brambor",
|
|
||||||
"power": 1,
|
|
||||||
"traits": [
|
|
||||||
"spy",
|
|
||||||
"double",
|
|
||||||
"call-to-arms"
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
{
|
|
||||||
"name": "card",
|
|
||||||
"display": "The Name",
|
|
||||||
"faction": "My Ass",
|
|
||||||
"line": "balls",
|
|
||||||
"power": 0,
|
|
||||||
"traits": []
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
[
|
|
||||||
"spy",
|
|
||||||
"double",
|
|
||||||
"boost",
|
|
||||||
"call-to-arms",
|
|
||||||
"horn",
|
|
||||||
"revive",
|
|
||||||
"destroy"
|
|
||||||
]
|
|
53
generate.cpp
53
generate.cpp
|
@ -1,53 +0,0 @@
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
using nlohmann::json;
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
string get(json j, string name) {
|
|
||||||
std::cout << name << " (";
|
|
||||||
for(int i = 0; i < j.size(); ++i)
|
|
||||||
std::cout << i << ':' << j[i] << ' ';
|
|
||||||
std::cout << ") : ";
|
|
||||||
int index; std::cin >> index;
|
|
||||||
if(index < 0 || index >= j.size())
|
|
||||||
return "";
|
|
||||||
return j[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
std::cout << "Name: ";
|
|
||||||
std::cin.ignore();
|
|
||||||
string name; std::getline(std::cin, name);
|
|
||||||
data["name"] = name;
|
|
||||||
|
|
||||||
data["faction"] = get(factions, "Faction");
|
|
||||||
|
|
||||||
data["line"] = get(lines, "Line");
|
|
||||||
|
|
||||||
std::cout << "Power: ";
|
|
||||||
int power; std::cin >> power; data["power"] = power;
|
|
||||||
|
|
||||||
for(string trait = get(traits, "Trait"); trait != ""; trait = get(traits, "Trait"))
|
|
||||||
if(trait != "")
|
|
||||||
data["traits"].push_back(trait);
|
|
||||||
|
|
||||||
std::ofstream out("cards/"+string(data["faction"])+"/"+name+".json");
|
|
||||||
|
|
||||||
out << data.dump(2) << std::endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
51
generate.py
Executable file
51
generate.py
Executable file
|
@ -0,0 +1,51 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
import json
|
||||||
|
|
||||||
|
def get(j, name):
|
||||||
|
print(name, '(', *[ str(i)+':'+j[i] for i in range(len(j)) ], '): ', sep = ' ', end=' ')
|
||||||
|
|
||||||
|
index = int(input())
|
||||||
|
if(index < 0 or index >= len(j)):
|
||||||
|
return ''
|
||||||
|
|
||||||
|
return j[index]
|
||||||
|
|
||||||
|
with open("cards/config.json") as f:
|
||||||
|
j = json.loads(f.read())
|
||||||
|
traits = j["traits"]
|
||||||
|
lines = j["lines"]
|
||||||
|
factions = j["factions"]
|
||||||
|
template = j["template"]
|
||||||
|
|
||||||
|
def card():
|
||||||
|
data = template.copy()
|
||||||
|
|
||||||
|
print("Name:", end=' ')
|
||||||
|
data["name"] = input()
|
||||||
|
print(data["name"])
|
||||||
|
if data["name"] == '':
|
||||||
|
return {}
|
||||||
|
|
||||||
|
print("Power:", end=' ')
|
||||||
|
data["power"] = int(input())
|
||||||
|
|
||||||
|
data["faction"] = get(factions, "Faction")
|
||||||
|
|
||||||
|
data["line"] = get(lines, "Line")
|
||||||
|
|
||||||
|
trait = get(traits, "Traits (-1 to stop)")
|
||||||
|
while trait != '':
|
||||||
|
if trait not in data["traits"]:
|
||||||
|
data["traits"].append(trait)
|
||||||
|
trait = get(traits, "Traits (-1 to stop)")
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
cards = []
|
||||||
|
new_card = card()
|
||||||
|
while new_card != {}:
|
||||||
|
cards.append(new_card)
|
||||||
|
new_card = card()
|
||||||
|
|
||||||
|
with open("cards/cards.json") as f:
|
||||||
|
f.write(json.dumps(cards))
|
Loading…
Reference in a new issue