1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import RedHelper
- import FileUtils
- if __name__ == "__main__":
- # init
- print("convert all red file to json...")
- red_helper = RedHelper.RedHelper()
- file_utils = FileUtils.FileUtils()
- file_utils.greet()
- all_level_red_file_full_path = file_utils.get_all_level_red_file_full_paths()
- # print(len(all_level_red_file_full_path), all_level_red_file_full_path)
- level_id_count = 1
- for level_path in all_level_red_file_full_path:
- level_one_raw_data = file_utils.xml_to_py_object(file_utils.get_root_of_red_file(level_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)
- # 看一下condition_selected能容纳的总钉子个数 不满足三消条件要调整
- conditions_selected = red_helper.adjust_conditions_selected(plate_conditions, conditions_selected)
- # 此时 plate_condition 和 conditions_selected 中的数据是下标对应的
- # 这里 +1 是为了对应生成总数量 不加对应condition的下标
- # 盘子情况的顺序最好是钉子数从小到大的 以防万一
- # 给每个盘子分配了随机种类的钉子
- # screw_types_list = [
- # red_helper.generate_screw_types_for_plate(conditions_selected[i] + 1) for i in range(len(conditions_selected))
- # ]
-
- n_screws_of_conditions = red_helper.get_n_screw_of_conditions(plate_conditions, conditions_selected)
- screw_types_list = red_helper.generate_screw_types_for_plates(conditions_selected, n_screws_of_conditions)
- # TODO: 看一下screw_types_list是否每种钉子出现次数为3的倍数 不是的话要调整
- # 如果需要调整 那么需要调整的钉子种类至少是成对出现的 因为之前已经满足钉子总个数为3的倍数
- # 如果一种钉子出现次数不满足3的倍数 势必有其他钉子出现次数也不满足要求
- # 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(str(level_id_count))
- level_id_count += 1
- # print(final_json_file_name)
- file_utils.write_dict_to_json(final_level_config, final_json_file_name)
|