# 工具-将关关卡redraem文件转化为json --- ## 组件 ### RedHelper #### 功能 从 python 容器中获取组成 json 需要的各种内容 #### 结构 ```python import random class RedHelper: """ @brief: 初始化 设置默认成员变量 """ def __init__(self): pass """ @brief: 从red文件的dict中获取关卡使用的模板文件ID """ def get_template_IDs(self, levelData: dict) -> list: pass """ @brief: 获取盘子配置 """ def get_plate_configs(self, template: dict) -> list: pass """ @brief: 获取盘子能容纳的最大钉子个数 """ def get_max_screws_of_plate(self, plate_condition: dict) -> int: pass """ @brief: 随机选取盘子情况 返回对应的ID """ def generate_condition_id(self, max_screws_of_plate: int) -> int: pass """ @brief: 根据盘子情况和随机挑选的情况生成盘子上摆放的钉子类型 """ def generate_screw_types_for_plate(self, condition_selected: int) -> list: pass """ @brief: 为每种盘子生成钉子数据 """ def generate_screw_configs(self, plate_condition: dict, condition_selected: int, screw_types: list) -> list: pass """ @brief: 将盘子和钉子的配置合成为最终的关卡配置 """ def generate_final_level_config(self, plate_configs_of_this_level: list) -> list: pass """ @brief: 将plate的zorder从都是1修正为正确的数字 """ def correct_plate_zorders(self, plate_config_of_this_level: list) -> list: pass """ @components: __nScrewTypes: 关卡的钉子总种类数 """ ``` ### FileUtils #### 功能 负责从磁盘读取和写入数据 #### 结构 ```python import xml.etree.ElementTree as ET class FileUtils: """ @brief 初始化 从同文件夹的 configs.json 获取使用到的文件路径 """ def __init__(self) -> None: pass """ @brief 为用户显示configs.json中读取到的路径 提供修改选项 可以修改这些设置 """ def greet(self) -> None: pass """ @brief 将red(xml)文件 转化为 python 数据结构 """ def xml_to_oy_object(self, root: ET.Element) -> str | dict | list | None: pass """ @brief 将字典写为json文件 """ def write_dict_to_json(self, dic: dict, path: str) -> None: pass """ @brief 退出时如果修改了默认参数 写入到文件中 """ def update_config_file(self) -> None: pass """ @brief 将目录路径与关卡号组合在一起得到完整路径 """ def get_template_file_full_path(self, template_id_list: list) -> list: pass """ @brief 将盘子ID和盘子上位置情况目录组合在一起得到完整路径 """ def get_plate_file_full_path(self, level_id: str) -> str: pass """ @brief 根据关卡号生成json文件的完整路径 """ def generate_level_json_file_full_path(self, level_id: str) -> str: pass """ @brief 根据关卡red文件目录组合出文件的完整地址 """ def get_all_level_red_file_full_path(self) -> list: pass """ @components: __redLevelConfigDir: 关卡red文件目录 __redLevelTemplateDir: 关卡模板red文件目录 __plateConfigDir: 盘子位置情况red文件目录 __jsonLevelConfigDir: 关卡json文件目录 """ ``` --- ## 注意事项 - 盘子上位置情况.red 必须按照钉子个数排序 - 一个钉子 两个钉子 三个钉子 ... - 否则会造成最终钉子个数和需要的不一致