From a7450f2c8ba98d7c76e4cf43328612d7c535c6dc Mon Sep 17 00:00:00 2001 From: Robert Date: Sun, 26 Dec 2021 15:49:55 +0100 Subject: [PATCH] Laufende Version --- injectTilesetCopyright.py | 61 +++++++++++++++++++++++++++++++++++++-- rechte.json | 46 ++++++++++++++++++++++++++++- 2 files changed, 103 insertions(+), 4 deletions(-) diff --git a/injectTilesetCopyright.py b/injectTilesetCopyright.py index 551224e..5a8016c 100644 --- a/injectTilesetCopyright.py +++ b/injectTilesetCopyright.py @@ -1,8 +1,33 @@ import json +import sys + +# bildname in lizenztext wandeln, daten ist rechte-json +def img2liz(image, daten): + for cpr in daten: + if cpr["name"] in image: + return cpr["copytxt"] + return False + +# lizenz-property einbauen, falls nicht vorhanden +def addLiz(ts, lizTxt): + prop = json.loads('{"name":"tilesetCopyright", "type":"string"}') + prop["value"] = lizTxt + if "properties" in ts: + p = ts["properties"] + # altes falls enthalten entfernen, neues hinzu + for i in range(len(p)): + if p[i]["name"] == "tilesetCopyright": + del p[i] + break + p.append(prop) + else: + ts["properties"] = [ prop ] + + print("Tiled-Editor Copyright-Info nach rc3.world-Vorgaben hinzufügen") print("Datei rechte.json passend befüllen, dann Aufruf") -print("{$0} ") +print(sys.argv[0] + "{$0} ") print("Die wird modifiziert! Vorher eigene Änderungen committen!") print("") @@ -11,6 +36,36 @@ with open("rechte.json", "r") as rechte_file: print("Folgende Rechte wurden zugeordnet:") for recht in rechte: print(recht["name"] + " zu -> " + recht["copytxt"]) - #json.dump(rechte, rechte_file, indent=2) - with open() + if len(sys.argv) <= 1: + print("Du hast vergessen die Tiled-Datei (Json) als Arument anzugeben. Ende.") + exit(1) + + tiledfile = sys.argv[1] + print("Überschreibe jetzt die Datei mit geändertem Inhalt: " + tiledfile) + mapjson = [] + with open(tiledfile, "r") as map_file: + mapjson = json.load(map_file) + try: + tilesets = mapjson["tilesets"] + for ts in tilesets: + print("Bearbeite tileset " + ts["name"]) + image = ts["image"] + lizTxt = img2liz(image, rechte) + if lizTxt: + print("--> verwende Lizenz " + lizTxt) + addLiz(ts, lizTxt) + else: + print("--> keine Lizenz zu " + image + " gefunden") + + + except: + print("fail") + exit(1) + + + with open("zz" + tiledfile, "w") as map_out_file: + json.dump(mapjson, map_out_file, indent=8) + print("geschrieben") + + diff --git a/rechte.json b/rechte.json index 326d7ec..e5a939c 100644 --- a/rechte.json +++ b/rechte.json @@ -1,7 +1,51 @@ [ + { + "name": "fantasy.png", + "copytxt": "CC0" + }, + { + "name": "chaos_zone_shared.png", + "copytxt": "CC0BY ChaosZ0ne Ost" + }, + { + "name": "c3gelb.png", + "copytxt": "CC0" + }, + { + "name": "campfire.png", + "copytxt": "CC0" + }, + { + "name": "tilesets_deviant_milkian_1.png", + "copytxt": "CC0" + }, + { + "name": "tilesets_deviant_milkian_2.png", + "copytxt": "CC0" + }, + { + "name": "tilesets_deviant_milkian_3.png", + "copytxt": "CC0" + }, + { + "name": "bagger.png", + "copytxt": "CC0BY Chaostreff Chemnitz https://chch.it" + }, + { + "name": "WinterCollection.png", + "copytxt": "CC0" + }, + { + "name": "Waschbecken.png", + "copytxt": "CC0BY Chaostreff Chemnitz https://chch.it" + }, + { + "name": "PinguineAntarktis.png", + "copytxt": "CC0BY Chaostreff Chemnitz https://chch.it" + }, { "name": "floortileset.png", - "copytxt": "CC0BY blatut" + "copytxt": "CC0BY unbekannt" }, { "name": "chemnitz_al.png",