def make_levelPack_from_json(json_data): CCLevels = cc_classes.CCLevelPack() for l in json_data: print("KK") myL = cc_classes.CCLevel() myL.level_number = l["level_number"] myL.time = l["time"] myL.num_chips = l["num_chips"] myL.upper_layer = l["upper_layer"] myL.optional_fields = [] opt = l["optional_fields"] for o in opt: if (o["field_type"] == "title"): print(o["title"]) hu = cc_classes.CCMapTitleField(o["title"]) print(hu) myL.add_field(hu) if (o["field_type"] == "passcode"): print("OO") myL.add_field(cc_classes.CCEncodedPasswordField(o["passcode"])) if (o["field_type"] == "hint"): myL.add_field(cc_classes.CCMapHintField(o["hint"])) if (o["field_type"] == "monsters"): cL = [] for c in o["coordinates"]: cL.append(cc_classes.CCCoordinate(c["x"], c["y"])) myL.add_field(cc_classes.CCMonsterMovementField(cL)) CCLevels.add_level(myL) cc_dat_utils.write_cc_level_pack_to_dat(CCLevels, output_dat_file) mycc = cc_dat_utils.make_cc_level_pack_from_dat("data/pjsheeha_cc1.dat") print(mycc)
import cc_dat_utils #Part 1 input_dat_file = "data/pfgd_test.dat" #Use cc_dat_utils.make_cc_level_pack_from_dat() to load the file specified by input_dat_file #print the resulting data print(cc_dat_utils.make_cc_level_pack_from_dat(input_dat_file))
new_monster_field = cc_classes.CCMonsterMovementField(monsters) new_level.add_field(new_monster_field) elif field_type == "traps": traps = [] for json_trap in json_field["traps"]: # new_button_coord = cc_classes.CCCoordinate(json_trap["x_button"], json_trap["y_button"]) # new_trap_coord = cc_classes.CCCoordinate(json_trap["x_trap"], json_trap["y_trap"]) traps.append(cc_classes.CCTrapControl(json_trap["x_button"], json_trap["y_button"], json_trap["x_trap"], json_trap["y_trap"])) new_level.add_field(cc_classes.CCTrapControlsField(traps)) elif field_type == "cloners": cloners = [] for json_cloner in json_field["cloners"]: # new_button_coord = cc_classes.CCCoordinate(json_trap["x_button"], json_trap["y_button"]) # new_cloner_coord = cc_classes.CCCoordinate(json_trap["x_cloner"], json_trap["y_cloner"]) cloners.append(cc_classes.CCCloningMachineControl(json_cloner["x_button"], json_cloner["y_button"], json_cloner["x_cloner"], json_cloner["y_cloner"])) new_level.add_field(cc_classes.CCCloningMachineControlsField(cloners)) new_level_pack.add_level(new_level) # cc_dat_utils.write_cc_level_pack_to_dat(new_level_pack, "data/rchew_cc1.dat") # level_pack_from_dat = cc_dat_utils.make_cc_level_pack_from_dat("data/rchew_cc1.dat") # print(level_pack_from_dat) cc_dat_utils.write_cc_level_pack_to_dat(new_level_pack, "data/rchew_pack.dat") level_pack_from_dat = cc_dat_utils.make_cc_level_pack_from_dat("data/rchew_pack.dat") print(level_pack_from_dat)
import cc_dat_utils #Part 1 input_dat_file = "data/pfgd_test.dat" #Use cc_dat_utils.make_cc_level_pack_from_dat() to load the file specified by input_dat_file #print the resulting data output = cc_dat_utils.make_cc_level_pack_from_dat(input_dat_file) print(output)
new_hint_field = cc_classes.CCMapHintField(json_field["hint"]) new_level.add_field(new_hint_field) elif field_type == "title": new_title_field = cc_classes.CCMapTitleField(json_field["title"]) new_level.add_field(new_title_field) elif field_type == "password": new_password_field = cc_classes.CCEncodedPasswordField( json_field["password"]) new_level.add_field(new_password_field) elif field_type == "monsters": monsters = [] for json_monster in json_field["monsters"]: x = json_monster["x"] y = json_monster["y"] new_monster_coord = cc_classes.CCCoordinate(x, y) monsters.append(new_monster_coord) new_monster_field = cc_classes.CCMonsterMovementField(monsters) new_level.add_field(new_monster_field) new_level_pack.add_level(new_level) cc_dat_utils.write_cc_level_pack_to_dat(new_level_pack, "data/dld_cc1.dat") test_dat = cc_dat_utils.make_cc_level_pack_from_dat("data/dld_cc1.dat") print(test_dat) #level number can NOT be zero #Load your custom JSON file #Convert JSON data to CCLevelPack #Save converted data to DAT file
from cc_dat_utils import make_cc_level_pack_from_dat #Part 1 input_dat_file = "data/pfgd_test.dat" #Use cc_dat_utils.make_cc_level_pack_from_dat() to load the file specified by input_dat_file #print the resulting data pfgd_test = make_cc_level_pack_from_dat(input_dat_file) print(pfgd_test) newfile = open('data/pfgd_test.txt', 'w') #created a new blank file newfile.write(str(pfgd_test)) #placed data into the file newfile.close() #closed the file
new_level.upper_layer = new_level_next["upper_layer"] #looping through json data for optional fields for json_field in new_level_next["optional_fields"]: field_type = json_field["field_type"] if field_type == "hint": new_hint_field = cc_classes.CCMapHintField(json_field["hint"]) new_level.add_field(new_hint_field) elif field_type == "password": new_password_field = cc_classes.CCEncodedPasswordField(json_field["password"]) new_level.add_field(new_password_field) elif field_type == "title": new_title_field = cc_classes.CCMapTitleField(json_field["title"]) new_level.add_field(new_title_field) elif field_type == "monsters": monsters = [] for json_monster in json_field["monsters"]: x = json_monster["x"] y = json_monster["y"] new_monster_coord = cc_classes.CCCoordinate(x, y) monsters.append(new_monster_coord) new_monster_field = cc_classes.CCMonsterMovementField(monsters) new_level.add_field(new_monster_field) new_level_pack.add_level(new_level) #Save converted data to DAT file cc_dat_utils.write_cc_level_pack_to_dat(new_level_pack, "data/tharkare_cc1.dat") test_dat = cc_dat_utils.make_cc_level_pack_from_dat("data/tharkare_cc1.dat") print(test_dat)