forked from dculyba/cc_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cc_json_utils.py
89 lines (77 loc) · 3.29 KB
/
cc_json_utils.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import json
import sys
import cc_data
import cc_dat_utils
default_input_json_file = "data/kchhibbe_cc1.json"
default_output_dat_file = "data/kchhibbe_cc1.dat"
# Reading the JSON data in from the input file
with open(default_input_json_file) as json_file:
json_data = json.load(json_file)
#print (json_data)
finalData = cc_data.CCDataFile()
for json_game in json_data:
level = cc_data.CCLevel()
level.level_number = json_game["level_number"]
level.time = json_game["time"]
level.num_chips = json_game["num_chips"]
level.upper_layer = json_game["upper_layer"]
level.lower_layer = json_game["lower_layer"]
optional_fields = json_game["Optional Fields"]
for json_field in optional_fields:
if json_field["type_val"] == 3:
title = json_field["title"]
cc_field = cc_data.CCMapTitleField(title)
level.add_field(cc_field)
elif json_field["type_val"] == 7:
hint = json_field["hint"]
cc_field = cc_data.CCMapHintField(hint)
level.add_field(cc_field)
elif json_field["type_val"] == 6:
password = json_field["password"]
cc_field = cc_data.CCEncodedPasswordField(password)
level.add_field(cc_field)
elif json_field["type_val"] == 10:
json_monsters = json_field["monsters"]
cc_monsters = []
for json_monster in json_monsters:
x = json_monster[0]
y = json_monster[1]
monster_coord = cc_data.CCCoordinate(x,y)
cc_monsters.append(monster_coord)
cc_field = cc_data.CCMonsterMovementField(cc_monsters)
level.add_field(cc_field)
elif json_field["type_val"] == 5:
json_machines = json_field["machine"]
cc_machines = []
for json_machine in json_machines:
c = json_machine["button_coord"][0]
d = json_machine["button_coord"][1]
a = json_machine["machine_coord"][0]
b = json_machine["machine_coord"][1]
machine_control = cc_data.CCCloningMachineControl(c,d,a,b)
cc_machines.append(machine_control)
cc_field = cc_data.CCCloningMachineControlsField(cc_machines)
level.add_field(cc_field)
elif json_field["type_val"] == 4:
json_traps = json_field["traps"]
cc_traps = []
for json_trap in json_traps:
c = json_trap["button_coord"][0]
d = json_trap["button_coord"][1]
a = json_trap["trap_coord"][0]
b = json_trap["trap_coord"][1]
trap_control = cc_data.CCTrapControl(c,d,a,b)
cc_traps.append(trap_control)
cc_field = cc_data.CCTrapControlsField(cc_traps)
level.add_field(cc_field)
finalData.add_level(level)
print(level)
if len(sys.argv) == 3:
input_json_file = sys.argv[1]
output_dat_file = sys.argv[2]
print("Using command line args:", input_json_file, output_dat_file)
else:
input_json_file = default_input_json_file
output_dat_file = default_output_dat_file
print("Unknown command line options. Using default values:", input_json_file, output_dat_file)
cc_dat_utils.write_cc_data_to_dat(finalData,output_dat_file)