diff --git a/docs/assets/extraction.md b/docs/assets/extraction.md index f8d060fb34..d8546d3595 100644 --- a/docs/assets/extraction.md +++ b/docs/assets/extraction.md @@ -6,3 +6,9 @@ For details on the xml files contents, see [the assets xml specification file](. The extraction tool can use [rich](https://github.com/Textualize/rich) if installed to make output prettier. If you are looking at output or errors from during extraction, consider installing rich for a better experience: `.venv/bin/python3 -m pip install rich` + +To run the extraction outside of `make setup`, use `./tools/extract_assets.sh VERSION`. +- Pass `-f` to force extraction: otherwise only assets for which xmls were modified will be extracted. +- Pass `-j` to use multiprocessing, making extraction quicker. Note that this makes for less readable errors if any error happens. +- Pass `-s name` to extract assets using baserom file `name`. +- Pass `-r -s 'name.*'` to extract assets using baserom files whose name match regular expression `name.*`. diff --git a/requirements.txt b/requirements.txt index c9c4afed64..bea2fe176c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,7 @@ crunch64>=0.5.1,<1.0.0 ipl3checksum>=1.2.0,<2.0.0 pyyaml>=6.0.1,<7.0.0 +pygfxd>=1.0.3,<2.0.0 # asm-differ argcomplete diff --git a/tools/assets/descriptor/__main__.py b/tools/assets/descriptor/__main__.py index 6162d2b340..2fb89f6eba 100644 --- a/tools/assets/descriptor/__main__.py +++ b/tools/assets/descriptor/__main__.py @@ -1,3 +1,10 @@ +from pprint import pprint as vanilla_pprint + +try: + from rich.pretty import pprint +except ImportError: + pprint = vanilla_pprint + from tools import version_config from . import base @@ -8,16 +15,15 @@ def main(): pools = base.get_resources_desc(vc) - from pprint import pprint - - if 0: - with open( - "/home/dragorn421/Documents/oot/tools/assets/descriptor/resources.txt", - "w", - ) as f: - for i, pool in enumerate(pools): - print(round(i / len(pools) * 100, 2), "%", end="\r") - pprint(pool, f) + try: + for pool in pools: + if any(coll.out_path.name == "gameplay_keep" for coll in pool.collections): + vanilla_pprint(pool) + else: + pprint(pool) + input("Press enter for next pool") + except KeyboardInterrupt: + print() main() diff --git a/tools/assets/descriptor/base.py b/tools/assets/descriptor/base.py index 1b41f2f82b..0295947057 100644 --- a/tools/assets/descriptor/base.py +++ b/tools/assets/descriptor/base.py @@ -191,14 +191,6 @@ def get_resources_desc(vc: version_config.VersionConfig): except Exception as e: raise Exception(f"Error with pool {pool}") from e - if 0: - from rich.pretty import pretty_repr - - with Path( - "/home/dragorn421/Documents/oot/tools/assets/descriptor/pools.txt" - ).open("w") as f: - f.write(pretty_repr(pools)) - return pools diff --git a/tools/assets/extract/__main__.py b/tools/assets/extract/__main__.py index 991e280533..8fecdd4d1e 100644 --- a/tools/assets/extract/__main__.py +++ b/tools/assets/extract/__main__.py @@ -5,6 +5,6 @@ if __name__ == "__main__": if profile: import cProfile - cProfile.run("extract_xml_z64.main()", "cprof_assets421.txt") + cProfile.run("extract_xml_z64.main()", "cprofile_extract_assets.txt") else: extract_xml_z64.main() diff --git a/tools/assets/extract/extase/__init__.py b/tools/assets/extract/extase/__init__.py index c35ea92f0d..3bb65e304b 100644 --- a/tools/assets/extract/extase/__init__.py +++ b/tools/assets/extract/extase/__init__.py @@ -760,7 +760,9 @@ class Resource(abc.ABC): range_end: Optional[int], name: str, ): - assert 0 <= range_start < file.size + assert ( + 0 <= range_start < file.size + ), f"{range_start=:#08X} out of range [0,{file.size=:#08X})" if range_end is None: assert self.can_size_be_unknown else: diff --git a/tools/assets/extract/extract_xml_z64.py b/tools/assets/extract/extract_xml_z64.py index 0c85684951..bf354dd126 100644 --- a/tools/assets/extract/extract_xml_z64.py +++ b/tools/assets/extract/extract_xml_z64.py @@ -65,6 +65,10 @@ def create_file_resources(rescoll: ResourcesDescCollection, file: File): ) as e: resource = e.resource list_ResourceNeedsPostProcessWithPoolResourcesException.append(e) + except Exception as e: + raise Exception( + "Error while creating resource from description:", resource_desc + ) from e # TODO nice hack right here. # probably instead rework the "c declaration" system into a more opaque object @@ -454,13 +458,14 @@ def main(): import traceback import sys - traceback.print_exc(file=sys.stdout) - try: import rich.pretty + import rich.console except: + traceback.print_exc(file=sys.stdout) print("Install rich for prettier output (`pip install rich`)") else: + rich.console.Console().print_exception() # TODO implement more __rich_repr__ if e.__class__ in (Exception, AssertionError, NotImplementedError): print("rich.pretty.pprint(e.args):") @@ -468,6 +473,8 @@ def main(): else: print("rich.pretty.pprint(e):") rich.pretty.pprint(e, indent_guides=False) + + sys.exit(1) finally: with last_extracts_json_p.open("w") as f: json.dump(last_extracts, f)