projects
/
naja.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Return is old-school (8-bit?)
[naja.git]
/
tools
/
gen_json.py
diff --git
a/tools/gen_json.py
b/tools/gen_json.py
index 6ae4b514c3302f29d4dddedc728153b355954193..c274f9ce864309548be0b9a89cfc8846fd618de4 100755
(executable)
--- a/
tools/gen_json.py
+++ b/
tools/gen_json.py
@@
-3,24
+3,38
@@
import json
import os
import json
import os
-import yaml
-
-def main():
+def main(update=True):
data = os.path.join(os.path.dirname(__file__), '..', 'data')
data = os.path.join(os.path.dirname(__file__), '..', 'data')
+
deck_dir = os.path.join(data, 'location_decks')
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'
basename, extension = os.path.splitext(yaml_fn)
if extension != '.yaml':
continue
json_fn = basename + '.json'
- yaml_path = os.path.join(d
eck_dir
, yaml_fn)
- json_path = os.path.join(d
eck_dir
, json_fn)
+ yaml_path = os.path.join(d
irectory
, yaml_fn)
+ json_path = os.path.join(d
irectory
, json_fn)
+ if not update and os.path.exists(json_path):
+ continue
+
+ import yaml
with open(yaml_path) as yaml_f:
obj = yaml.safe_load(yaml_f)
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)
with open(json_path, 'w') as json_f:
json.dump(obj, json_f, indent=2)