-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_defs.py
More file actions
49 lines (34 loc) · 1.27 KB
/
update_defs.py
File metadata and controls
49 lines (34 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import sys
import re
import string
import json
tile_file_in = "assets/data/tiles.json"
tile_file_out = "src/manager/tile_defs.h"
item_file_in = "assets/data/items.json"
item_file_out = "src/manager/item_defs.h"
sound_file_in = "assets/data/sounds.json"
sound_file_out = "src/manager/sound_defs.h"
interface_file_in = "assets/data/interfaces.json"
interface_file_out = "src/manager/interface_defs.h"
def parse_file(file_in, file_out, prefix):
with open(file_in) as f:
data = json.load(f)
out_file = open(file_out,"w") #.H OUTPUT FILE NAME
out_file.write("constexpr char %s_NULL = -1;\n" % (prefix))
for item in data:
name = item["name"]
name = name.upper()
name = "_".join(name.split())
id = ""
id = item["id"]
print(name, id)
out_file.write("constexpr char %s_%s = %s;\n" % (prefix, name, id))
out_file.close()
print("Loading tiles from " + tile_file_in)
parse_file(tile_file_in, tile_file_out, "TILE")
print("Loading items from " + item_file_in)
parse_file(item_file_in, item_file_out, "ITEM")
print("Loading sounds from " + sound_file_in)
parse_file(sound_file_in, sound_file_out, "SOUND")
print("Loading interfaces from " + interface_file_in)
parse_file(interface_file_in, interface_file_out, "INTERFACE")