From d69151d9785011bec7e0658f2d79729c84a94d13 Mon Sep 17 00:00:00 2001 From: Matuush Date: Mon, 4 Aug 2025 17:11:38 +0200 Subject: [PATCH] Rewrite generator script to Python --- Makefile | 6 ---- cards/config.json | 29 +++++++++++++++ cards/factions.json | 6 ---- cards/lines.json | 5 --- cards/northern-kingdoms/brambor.json | 12 ------- cards/template.json | 8 ----- cards/traits.json | 9 ----- generate.cpp | 53 ---------------------------- generate.py | 51 ++++++++++++++++++++++++++ 9 files changed, 80 insertions(+), 99 deletions(-) create mode 100644 cards/config.json delete mode 100644 cards/factions.json delete mode 100644 cards/lines.json delete mode 100644 cards/northern-kingdoms/brambor.json delete mode 100644 cards/template.json delete mode 100644 cards/traits.json delete mode 100644 generate.cpp create mode 100755 generate.py diff --git a/Makefile b/Makefile index e59b0f7..b84d936 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,3 @@ 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 diff --git a/cards/config.json b/cards/config.json new file mode 100644 index 0000000..8bd8a37 --- /dev/null +++ b/cards/config.json @@ -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": [] + } +} diff --git a/cards/factions.json b/cards/factions.json deleted file mode 100644 index 46db95b..0000000 --- a/cards/factions.json +++ /dev/null @@ -1,6 +0,0 @@ -[ - "northern-kingdoms", - "monsters", - "nilfgaard", - "scoiatael" -] diff --git a/cards/lines.json b/cards/lines.json deleted file mode 100644 index 42fdebf..0000000 --- a/cards/lines.json +++ /dev/null @@ -1,5 +0,0 @@ -[ - "front", - "middle", - "back" -] diff --git a/cards/northern-kingdoms/brambor.json b/cards/northern-kingdoms/brambor.json deleted file mode 100644 index 437fdc9..0000000 --- a/cards/northern-kingdoms/brambor.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "display": "oligarchie", - "faction": "northern-kingdoms", - "line": "front", - "name": "brambor", - "power": 1, - "traits": [ - "spy", - "double", - "call-to-arms" - ] -} diff --git a/cards/template.json b/cards/template.json deleted file mode 100644 index c19def1..0000000 --- a/cards/template.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "card", - "display": "The Name", - "faction": "My Ass", - "line": "balls", - "power": 0, - "traits": [] -} diff --git a/cards/traits.json b/cards/traits.json deleted file mode 100644 index 0ccd866..0000000 --- a/cards/traits.json +++ /dev/null @@ -1,9 +0,0 @@ -[ - "spy", - "double", - "boost", - "call-to-arms", - "horn", - "revive", - "destroy" -] diff --git a/generate.cpp b/generate.cpp deleted file mode 100644 index b0a98a4..0000000 --- a/generate.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include -#include -#include - -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; -} diff --git a/generate.py b/generate.py new file mode 100755 index 0000000..cd59b73 --- /dev/null +++ b/generate.py @@ -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))