X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=tools%2Fgen_json.py;h=c274f9ce864309548be0b9a89cfc8846fd618de4;hb=a1c561e26fae79ce8a9570c9404975a8a0367d65;hp=bec7ffc2b1228627e02912ad8b00cdb3cb153ee2;hpb=0b5abec00215c76d64da1dfe86b4e333899ebbaa;p=naja.git diff --git a/tools/gen_json.py b/tools/gen_json.py index bec7ffc..c274f9c 100755 --- a/tools/gen_json.py +++ b/tools/gen_json.py @@ -6,16 +6,22 @@ import os def main(update=True): data = os.path.join(os.path.dirname(__file__), '..', 'data') + deck_dir = os.path.join(data, 'location_decks') + convert_to_json(deck_dir, update) + puzzle_dir = os.path.join(deck_dir, 'puzzles') + convert_to_json(puzzle_dir, update) + - for yaml_fn in os.listdir(deck_dir): +def convert_to_json(directory, update=True): + for yaml_fn in os.listdir(directory): basename, extension = os.path.splitext(yaml_fn) if extension != '.yaml': continue json_fn = basename + '.json' - yaml_path = os.path.join(deck_dir, yaml_fn) - json_path = os.path.join(deck_dir, json_fn) + yaml_path = os.path.join(directory, yaml_fn) + json_path = os.path.join(directory, json_fn) if not update and os.path.exists(json_path): continue @@ -23,6 +29,12 @@ def main(update=True): import yaml with open(yaml_path) as yaml_f: obj = yaml.safe_load(yaml_f) + + # These old objects, referenced in cards + for k in obj.keys(): + if k.startswith('_'): + del obj[k] + with open(json_path, 'w') as json_f: json.dump(obj, json_f, indent=2)