From 11e8d230271a57f23765f6499943db0b2406875a Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Wed, 5 Feb 2025 19:04:30 +0100 Subject: [PATCH] Write source with static for overlays using `HACK_IS_STATIC_ON` hack --- tools/assets/extract/extase/__init__.py | 14 +++++++------- tools/assets/extract/extase/cdata_resources.py | 2 ++ tools/assets/extract/extract_xml_z64.py | 11 ++++++++--- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/tools/assets/extract/extase/__init__.py b/tools/assets/extract/extase/__init__.py index 6fea440bc3..e860b6f1e0 100644 --- a/tools/assets/extract/extase/__init__.py +++ b/tools/assets/extract/extase/__init__.py @@ -631,6 +631,8 @@ class File: self, "source_c_path" ), "set_source_path must be called before write_source" assert hasattr(self, "source_h_path") + self.source_c_path.parent.mkdir(parents=True, exist_ok=True) + self.source_h_path.parent.mkdir(parents=True, exist_ok=True) with self.source_c_path.open("w") as c: with self.source_h_path.open("w") as h: @@ -890,17 +892,17 @@ class Resource(abc.ABC): Binary: extracted_path_suffix = ".bin" with get_filename_stem() = "blob" extract_to_path: `extracted/VERSION/assets/.../blob.bin` - inc_c_path: `build/VERSION/assets/.../blob.inc.c` + inc_c_path: `assets/.../blob.inc.c` C: extracted_path_suffix = ".inc.c" with get_filename_stem() = "data" extract_to_path: `extracted/VERSION/assets/.../data.inc.c` - inc_c_path: `extracted/VERSION/assets/.../data.inc.c` + inc_c_path: `assets/.../data.inc.c` rgba16 image: extracted_path_suffix = ".png" with get_filename_stem() = "img.rgba16" extract_to_path: `extracted/VERSION/assets/.../img.rgba16.png` - inc_c_path: `build/VERSION/assets/.../img.rgba16.inc.c` + inc_c_path: `assets/.../img.rgba16.inc.c` """ filename_stem = self.get_filename_stem() @@ -909,11 +911,9 @@ class Resource(abc.ABC): extracted_path / out_path / (filename_stem + self.extracted_path_suffix) ) - if self.needs_build: - inc_c_path = build_path / out_path / (filename_stem + ".inc.c") - else: + if not self.needs_build: assert self.extracted_path_suffix == ".inc.c" - inc_c_path = extract_to_path + inc_c_path = out_path / (filename_stem + ".inc.c") self.extract_to_path = extract_to_path self.inc_c_path = inc_c_path diff --git a/tools/assets/extract/extase/cdata_resources.py b/tools/assets/extract/extase/cdata_resources.py index 9bf2177692..49391a35fa 100644 --- a/tools/assets/extract/extase/cdata_resources.py +++ b/tools/assets/extract/extase/cdata_resources.py @@ -376,6 +376,8 @@ class S16ArrayResource(CDataResource): super().__init__(file, range_start, name) def get_c_declaration_base(self): + if hasattr(self, "HACK_IS_STATIC_ON"): + return f"s16 {self.symbol_name}[{self.cdata_ext.size // self.elem_cdata_ext.size}]" return f"s16 {self.symbol_name}[]" def get_c_reference(self, resource_offset: int): diff --git a/tools/assets/extract/extract_xml_z64.py b/tools/assets/extract/extract_xml_z64.py index bf0462f4ae..8fe920e8ae 100644 --- a/tools/assets/extract/extract_xml_z64.py +++ b/tools/assets/extract/extract_xml_z64.py @@ -66,6 +66,13 @@ def create_file_resources(rescoll: ResourcesDescCollection, file: File): resource = e.resource list_ResourceNeedsPostProcessWithPoolResourcesException.append(e) + # TODO nice hack right here. + # probably instead rework the "c declaration" system into a more opaque object + # not that this is really a required long term feature as it's only relevant + # for writing the source files (main .c/.h), not extracting + if file.name.startswith("ovl_") and file.name != "ovl_file_choose": + resource.HACK_IS_STATIC_ON = ... + file.add_resource(resource) file_resources_by_desc[resource_desc] = resource @@ -224,14 +231,12 @@ def process_pool( # TODO this looks jank for rescoll, file in file_by_rescoll.items(): file.set_source_path(Path("assets") / rescoll.out_path) - (Path("assets") / rescoll.out_path).mkdir(parents=True, exist_ok=True) file.set_resources_paths( EXTRACTED_PATH, BUILD_PATH, Path("assets") / rescoll.out_path, ) - (EXTRACTED_PATH / rescoll.out_path).mkdir(parents=True, exist_ok=True) for file, file_memctx in memctx_by_file.items(): # write to EXTRACTED_PATH @@ -253,7 +258,7 @@ def process_pool_wrapped(version_memctx_base, pd): import sys # Some exceptions can't be pickled for passing back to the main process - # so print them now as well + # so print them now as well as reraising traceback.print_exc(file=sys.stdout) raise Exception( "ERROR with pool_desc collections:",