From 3a428239c9582218ab45f7f1c960581019ef892a Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Sat, 8 Feb 2025 18:10:57 +0100 Subject: [PATCH] slightly improve standard output --- tools/assets/extract/extase/__init__.py | 4 +- tools/assets/extract/extase/memorymap.py | 52 ++++++++----------- .../extract/extase_oot64/dlist_resources.py | 37 +++++++------ tools/assets/extract/extract_xml_z64.py | 2 +- 4 files changed, 46 insertions(+), 49 deletions(-) diff --git a/tools/assets/extract/extase/__init__.py b/tools/assets/extract/extase/__init__.py index 7442594f02..538ac78e5f 100644 --- a/tools/assets/extract/extase/__init__.py +++ b/tools/assets/extract/extase/__init__.py @@ -16,7 +16,7 @@ if TYPE_CHECKING: # 0: nothing, 1: in progress & waiting, 2: all VERBOSE_FILE_TRY_PARSE_DATA = 0 -VERBOSE_REPORT_RESBUF = True +VERBOSE_REPORT_RESBUF = False # # file @@ -263,7 +263,7 @@ class File: else: print("??? no last_parse_waiting_e ???") print("then why has", resource.name, "not been parsed?") - BEST_EFFORT = True # TODO move + BEST_EFFORT = False # TODO move if BEST_EFFORT: print("BEST_EFFORT: removing non-parsed resources") for resource in resources_data_not_parsed: diff --git a/tools/assets/extract/extase/memorymap.py b/tools/assets/extract/extase/memorymap.py index 6d514f71a8..e29a98c3cb 100644 --- a/tools/assets/extract/extase/memorymap.py +++ b/tools/assets/extract/extase/memorymap.py @@ -3,6 +3,11 @@ from dataclasses import dataclass from typing import Callable, TypeVar, Generic +try: + from rich.pretty import pprint as rich_pprint +except ModuleNotFoundError: + rich_pprint = print + from . import Resource, File, GetResourceAtResult @@ -321,18 +326,15 @@ class MemoryContext: fake_resource.reporters.add(reporter) fake_file.add_resource(fake_resource) if VERBOSE_BEST_EFFORT: - print( - "BEST_EFFORT: ignored error e=", - repr(e), - "on resource report by reporter=", - reporter, - "at address=", - hex(address), - "and created fake_file=", - fake_file, - "and fake_resource=", - fake_resource, - ) + print("BEST_EFFORT: ignored error e=") + rich_pprint(e) + print(" on resource report by reporter=") + rich_pprint(reporter) + print(f" at {address=:#08X}") + print(" and created fake_file=") + rich_pprint(fake_file), + print(" and fake_resource=") + rich_pprint(fake_resource) fake_file.FAKE_FOR_BEST_EFFORT = True fake_resource.FAKE_FOR_BEST_EFFORT = True return fake_resource @@ -370,18 +372,11 @@ class MemoryContext: except UnmappedAddressError as e: if BEST_EFFORT: if VERBOSE_BEST_EFFORT: - print( - "BEST_EFFORT: ignored error e=", - repr(e), - "and skipping marking resource buffer for reporter=", - reporter, - "resource_type=", - resource_type, - "address_start=", - hex(address_start), - "address_end=", - hex(address_end), - ) + print("BEST_EFFORT: ignored error e=") + rich_pprint(e) + print(" and skipping marking resource buffer for reporter=") + rich_pprint(reporter) + print(f" {resource_type=} {address_start=:#08X} {address_end=:#08X}") return raise file_start = resolve_result.file_offset @@ -401,12 +396,9 @@ class MemoryContext: except UnmappedAddressError as e: if BEST_EFFORT: if VERBOSE_BEST_EFFORT: - print( - "BEST_EFFORT: ignored error e=", - repr(e), - "and returning raw address =", - f"0x{address:08X}", - ) + print("BEST_EFFORT: ignored error e="), + rich_pprint(e) + print(f" and returning raw address=0x{address:08X}") return f"0x{address:08X}" raise diff --git a/tools/assets/extract/extase_oot64/dlist_resources.py b/tools/assets/extract/extase_oot64/dlist_resources.py index 980e5989cc..ae1a28973d 100644 --- a/tools/assets/extract/extase_oot64/dlist_resources.py +++ b/tools/assets/extract/extase_oot64/dlist_resources.py @@ -1,12 +1,18 @@ -from __future__ import annotations -from pathlib import Path import enum +import io +from pathlib import Path import reprlib -import io - from typing import TYPE_CHECKING, Union, Optional, Callable +try: + from rich.pretty import pprint as rich_pprint +except ModuleNotFoundError: + rich_pprint = print + +# pip install pygfxd@git+https://github.com/Dragorn421/pygfxd.git@065541d92ad0d84d214fad4f30e4592f7102c013 +import pygfxd + if TYPE_CHECKING: from ..extase.memorymap import MemoryContext @@ -31,13 +37,6 @@ VERBOSE_ColorIndexedTexturesManager = False VERBOSE_BEST_EFFORT_TLUT_NO_REAL_USER = True -import pygfxd -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from ......pygfxd import pygfxd - - class MtxResource(CDataResource): def write_mtx(resource, memory_context, v, f: io.TextIOBase, line_prefix): assert isinstance(v, dict) @@ -301,9 +300,13 @@ class TextureResource(Resource): cur_count = self.width * self.height assert cur_count >= new_min_count, ( - cur_count, - new_min_count, + "TLUT resource", self, + "is defined as having", + cur_count, + "colors, but there is an image using it as having at least", + new_min_count, + "colors:", resource_ci, ) @@ -392,9 +395,11 @@ class TextureResource(Resource): if VERBOSE_BEST_EFFORT_TLUT_NO_REAL_USER: print( "BEST_EFFORT", - "no real (non-fake for best effort) ci resource uses this tlut\n ", - self, - "\n extracting the tlut as its own png", + "no real (non-fake for best effort) ci resource uses this tlut", + ) + rich_pprint(self) + print( + " extracting the tlut as its own png", self.extract_to_path.resolve().as_uri(), "instead of relying on it being generated", "\n (note while the result may build and match the tlut probably is", diff --git a/tools/assets/extract/extract_xml_z64.py b/tools/assets/extract/extract_xml_z64.py index f16e1f4fcd..afa7bf5a71 100644 --- a/tools/assets/extract/extract_xml_z64.py +++ b/tools/assets/extract/extract_xml_z64.py @@ -22,7 +22,7 @@ from . import z64_resource_handlers # VERBOSE1 = False -VERBOSE2 = True +VERBOSE2 = False # "options" RM_SOURCE = True