ConvertOneLevelConfig.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import FileUtils
  2. import RedHelper
  3. if __name__ == '__main__':
  4. # 关卡1.red 的路径
  5. level_one_path = "/Users/red/ScrewGame/Resources/res_ScrewGame/关卡/关卡1.red"
  6. print("convert one red file to json...")
  7. red_helper = RedHelper.RedHelper()
  8. file_utils = FileUtils.FileUtils()
  9. file_utils.greet()
  10. level_one_raw_data = file_utils.xml_to_py_object(file_utils.get_root_of_red_file(level_one_path))
  11. # print(level_one_raw_data)
  12. template_id_list = red_helper.get_template_IDs(level_one_raw_data)
  13. # print(template_id_list)
  14. template_file_full_paths = file_utils.get_template_file_full_path(template_id_list)
  15. # print(template_file_full_paths)
  16. template_file_data_list = [
  17. file_utils.xml_to_py_object(file_utils.get_root_of_red_file(file_name))
  18. for file_name in template_file_full_paths
  19. ]
  20. # print(len(template_file_data_list), template_file_data_list)
  21. plate_configs_of_this_level = [red_helper.get_plate_configs(template) for template in template_file_data_list]
  22. # 最终生成数据的时候还要使用这个 还没生成screw数据
  23. plate_configs_of_this_level = [
  24. plate_config for plates_of_template in plate_configs_of_this_level for plate_config in plates_of_template
  25. ]
  26. # print(len(plate_configs_of_this_level) , plate_configs_of_this_level)
  27. plate_file_full_paths = file_utils.get_plate_file_full_path(plate_configs_of_this_level)
  28. # print(plate_file_full_paths)
  29. plate_conditions = [
  30. file_utils.xml_to_py_object(file_utils.get_root_of_red_file(file_name)) for file_name in plate_file_full_paths
  31. ]
  32. # print(plate_conditions)
  33. max_screws_of_plate_list = [red_helper.get_max_screws_of_plate(plate_condition) for plate_condition in
  34. plate_conditions]
  35. # print(max_screws_of_plate_list)
  36. # 从这开始模拟C++关卡生成模块
  37. conditions_selected = [red_helper.generate_condition_id(ID) for ID in max_screws_of_plate_list]
  38. # print(conditions_selected)
  39. # 此时 plate_condition 和 conditions_selected 中的数据是下标对应的
  40. # TODO: 往选取情况的盘子上装钉子 每个盘子分配和情况对应个数的钉子 钉子种类在设置的总种类数范围内随机
  41. # 这里 +1 是为了对应生成总数量 不加对应condition的下标
  42. # 约定一下 盘子情况的顺序是钉子数从小到大的
  43. # 给每个盘子分配了随机种类的钉子
  44. screw_types_list = [
  45. red_helper.generate_screw_types_for_plate(conditions_selected[i] + 1) for i in range(len(conditions_selected))
  46. ]
  47. # print(screw_types_list)
  48. # print(plate_conditions)
  49. # print(conditions_selected)
  50. # print(screw_types_list)
  51. screw_configs = [
  52. red_helper.generate_screw_configs(
  53. plate_conditions[i],
  54. conditions_selected[i],
  55. screw_types_list[i]
  56. ) for i in range(len(plate_conditions))
  57. ]
  58. # print(screw_configs)
  59. plate_configs_of_this_level = red_helper.correct_plate_zorders(plate_configs_of_this_level)
  60. final_level_config = red_helper.generate_final_level_config(plate_configs_of_this_level, screw_configs)
  61. # print(final_level_config)
  62. final_json_file_name = file_utils.generate_level_json_file_full_path("1")
  63. # print(final_json_file_name)
  64. file_utils.write_dict_to_json(final_level_config, final_json_file_name)