diff --git a/tools/build/configure.py b/tools/build/configure.py index d3e00233e44..7b0ba727d71 100755 --- a/tools/build/configure.py +++ b/tools/build/configure.py @@ -566,18 +566,21 @@ def build( build( self.build_path() / "include/world_map.h", [Path("src/gen/world_map.xml")], - "world_map",) + "world_map", + ) build( self.build_path() / "include/item_entity_scripts.h", [Path("src/gen/item_entity_scripts.xml")], - "item_entity_scripts",) + "item_entity_scripts", + ) build( self.build_path() / "include/item_hud_scripts.h", [Path("src/gen/item_hud_scripts.xml")], - "item_hud_scripts",) - + "item_hud_scripts", + ) + # Build objects for entry in self.linker_entries: seg = entry.segment diff --git a/tools/build/pm_item_entity_scripts.py b/tools/build/pm_item_entity_scripts.py index bdb08e914d8..59d76d1c384 100644 --- a/tools/build/pm_item_entity_scripts.py +++ b/tools/build/pm_item_entity_scripts.py @@ -5,16 +5,16 @@ from pathlib import Path import xml.etree.ElementTree as ET + def build(in_xml: Path, out_c: Path): xml = ET.parse(in_xml) ScriptList = xml.getroot() with open(out_c, "w") as f: - f.write("#ifndef ITEM_ENTITY_SCRIPTS_H\n") f.write("#define ITEM_ENTITY_SCRIPTS_H\n") f.write("/* This file is auto-generated. Do not edit. */\n\n") - f.write("#include \"item_entity.h\"\n\n") + f.write('#include "item_entity.h"\n\n') for Script in ScriptList.findall("IScript"): name = Script.attrib.get("name", None) @@ -23,10 +23,10 @@ def build(in_xml: Path, out_c: Path): if name is None: raise Exception("IScript is missing attribute: 'name'") - + if template is None: raise Exception("IScript is missing attribute: 'template'") - + if icon is None: icon = "" else: @@ -36,6 +36,7 @@ def build(in_xml: Path, out_c: Path): f.write("\n#endif // ITEM_ENTITY_SCRIPTS_H\n") + if __name__ == "__main__": parser = argparse.ArgumentParser(description="Generates item entity scripts") parser.add_argument("in_xml", type=Path, help="input xml file path") diff --git a/tools/build/pm_item_hud_scripts.py b/tools/build/pm_item_hud_scripts.py index c3dff37c5d2..33fc54f20e5 100644 --- a/tools/build/pm_item_hud_scripts.py +++ b/tools/build/pm_item_hud_scripts.py @@ -5,16 +5,16 @@ from pathlib import Path import xml.etree.ElementTree as ET + def build(in_xml: Path, out_c: Path): xml = ET.parse(in_xml) ScriptList = xml.getroot() with open(out_c, "w") as f: - f.write("#ifndef ITEM_HUD_SCRIPTS_H\n") f.write("#define ITEM_HUD_SCRIPTS_H\n") f.write("/* This file is auto-generated. Do not edit. */\n\n") - f.write("#include \"hud_element.h\"\n\n") + f.write('#include "hud_element.h"\n\n') for Script in ScriptList.findall("HScript"): name = Script.attrib.get("name", None) @@ -24,7 +24,7 @@ def build(in_xml: Path, out_c: Path): if name is None: raise Exception("HScript is missing attribute: 'name'") - + if template is None: raise Exception("HScript is missing attribute: 'name'") @@ -49,6 +49,7 @@ def build(in_xml: Path, out_c: Path): f.write("\n#endif // ITEM_HUD_SCRIPTS_H\n") + if __name__ == "__main__": parser = argparse.ArgumentParser(description="Generates item HUD scripts") parser.add_argument("in_xml", type=Path, help="input xml file path") diff --git a/tools/build/pm_world_map.py b/tools/build/pm_world_map.py index 944779e36b7..72d1f371e4b 100644 --- a/tools/build/pm_world_map.py +++ b/tools/build/pm_world_map.py @@ -5,12 +5,14 @@ from typing import List, Dict import xml.etree.ElementTree as ET + def get_required_attrib(elem: ET.Element, attrib: str) -> str: value = elem.attrib.get(attrib, None) if value == None: raise Exception(f"{elem.tag} is missing attribute: '{attrib}'") return str(value) + class WorldMapEntry: def __init__(self, elem: ET.Element): self.location = get_required_attrib(elem, "id") @@ -31,18 +33,17 @@ def build(in_xml: Path, out_c: Path): ScriptList = xml.getroot() with open(out_c, "w") as f: - f.write("#ifndef WORLD_MAP_H\n") f.write("#define WORLD_MAP_H\n") f.write("/* This file is auto-generated. Do not edit. */\n\n") - f.write("#include \"common.h\"\n\n") + f.write('#include "common.h"\n\n') locations: List[WorldMapEntry] = [] for elem in ScriptList.findall("Location"): locations.append(WorldMapEntry(elem)) - loc_to_idx: Dict[str,int] = {} + loc_to_idx: Dict[str, int] = {} for idx, loc in enumerate(locations): loc_to_idx[loc.location] = idx @@ -65,14 +66,17 @@ def build(in_xml: Path, out_c: Path): if loc.parent not in loc_to_idx: raise Exception(f"{loc.parent} is not defined") - f.write(f" {{ .id = {loc.location}, .parent = {loc_to_idx[loc.parent]}, .afterRequirement = {loc.requires}, " \ - + f".pos = {{ .x = {loc.startX}, .y = {loc.startY} }}, " \ - + f".pathLength = {len(loc.path)}, .path = PauseMapPaths[{idx}] }},\n") + f.write( + f" {{ .id = {loc.location}, .parent = {loc_to_idx[loc.parent]}, .afterRequirement = {loc.requires}, " + + f".pos = {{ .x = {loc.startX}, .y = {loc.startY} }}, " + + f".pathLength = {len(loc.path)}, .path = PauseMapPaths[{idx}] }},\n" + ) f.write("};\n") f.write("\n#endif // WORLD_MAP_H\n") + if __name__ == "__main__": parser = argparse.ArgumentParser(description="Generates world map data") parser.add_argument("in_xml", type=Path, help="input xml file path")