Skip to content

Commit

Permalink
py formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
HailSanta authored and HailSanta committed Jul 30, 2023
1 parent 2394354 commit b661af2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
11 changes: 7 additions & 4 deletions tools/build/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions tools/build/pm_item_entity_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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")
Expand Down
7 changes: 4 additions & 3 deletions tools/build/pm_item_hud_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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'")

Expand All @@ -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")
Expand Down
16 changes: 10 additions & 6 deletions tools/build/pm_world_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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

Expand All @@ -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")
Expand Down

0 comments on commit b661af2

Please sign in to comment.