import FileUtils import RedHelper if __name__ == '__main__': # 关卡1.red 的路径 level_one_path = "/Users/red/ScrewGame/Resources/res_ScrewGame/关卡/关卡1.red" print("convert one red file to json...") red_helper = RedHelper.RedHelper() file_utils = FileUtils.FileUtils() file_utils.greet() level_one_raw_data = file_utils.xml_to_py_object(file_utils.get_root_of_red_file(level_one_path)) # print(level_one_raw_data) template_id_list = red_helper.get_template_IDs(level_one_raw_data) # print(template_id_list) template_file_full_paths = file_utils.get_template_file_full_path(template_id_list) # print(template_file_full_paths) template_file_data_list = [ file_utils.xml_to_py_object(file_utils.get_root_of_red_file(file_name)) for file_name in template_file_full_paths ] # print(len(template_file_data_list), template_file_data_list) plate_configs_of_this_level = [red_helper.get_plate_configs(template) for template in template_file_data_list] # 最终生成数据的时候还要使用这个 还没生成screw数据 plate_configs_of_this_level = [ plate_config for plates_of_template in plate_configs_of_this_level for plate_config in plates_of_template ] # print(len(plate_configs_of_this_level) , plate_configs_of_this_level) plate_file_full_paths = file_utils.get_plate_file_full_path(plate_configs_of_this_level) # print(plate_file_full_paths) plate_conditions = [ file_utils.xml_to_py_object(file_utils.get_root_of_red_file(file_name)) for file_name in plate_file_full_paths ] # print(plate_conditions) max_screws_of_plate_list = [red_helper.get_max_screws_of_plate(plate_condition) for plate_condition in plate_conditions] # print(max_screws_of_plate_list) # 从这开始模拟C++关卡生成模块 conditions_selected = [red_helper.generate_condition_id(ID) for ID in max_screws_of_plate_list] # print(conditions_selected) # 此时 plate_condition 和 conditions_selected 中的数据是下标对应的 # TODO: 往选取情况的盘子上装钉子 每个盘子分配和情况对应个数的钉子 钉子种类在设置的总种类数范围内随机 # 这里 +1 是为了对应生成总数量 不加对应condition的下标 # 约定一下 盘子情况的顺序是钉子数从小到大的 # 给每个盘子分配了随机种类的钉子 screw_types_list = [ red_helper.generate_screw_types_for_plate(conditions_selected[i] + 1) for i in range(len(conditions_selected)) ] # print(screw_types_list) # print(plate_conditions) # print(conditions_selected) # print(screw_types_list) screw_configs = [ red_helper.generate_screw_configs( plate_conditions[i], conditions_selected[i], screw_types_list[i] ) for i in range(len(plate_conditions)) ] # print(screw_configs) plate_configs_of_this_level = red_helper.correct_plate_zorders(plate_configs_of_this_level) final_level_config = red_helper.generate_final_level_config(plate_configs_of_this_level, screw_configs) # print(final_level_config) final_json_file_name = file_utils.generate_level_json_file_full_path("1") # print(final_json_file_name) file_utils.write_dict_to_json(final_level_config, final_json_file_name)