diff --git a/tools/assets/extract/extase/cdata_resources.py b/tools/assets/extract/extase/cdata_resources.py index 3576229b08..3c5ce74c23 100644 --- a/tools/assets/extract/extase/cdata_resources.py +++ b/tools/assets/extract/extase/cdata_resources.py @@ -455,3 +455,39 @@ cdata_ext_Vec3f = CDataExt_Struct( ("z", CDataExt_Value.f32), ) ) + + +def fmt_hex_s(v: int, nibbles: int = 0): + """Format v to 0x-prefixed uppercase hexadecimal, using (at least) the specified amount of nibbles. + + Meant for signed values (_s suffix), + adds a space in place of where the - sign would be for positive values. + + Note compared to this, + - f"{v:#X}" would produce an uppercase 0X (1 -> 0X1) + - f"0x{v:X}" doesn't work with negative values (-1 -> 0x-1) + """ + v_str = f"{v:0{nibbles}X}" + if v < 0: + v_str = v_str.removeprefix("-") + return f"-0x{v_str}" + else: + return f" 0x{v_str}" + + +def fmt_hex_u(v: int, nibbles: int = 0): + """Format v to 0x-prefixed uppercase hexadecimal, using (at least) the specified amount of nibbles. + + Meant for unsigned values (_u suffix), + but won't fail for negative values. + + See: fmt_hex_s + """ + v_str = f"{v:0{nibbles}X}" + if v < 0: + # Also handle v being negative just in case, + # it will only mean the output isn't aligned as expected + v_str = v_str.removeprefix("-") + return f"-0x{v_str}" + else: + return f"0x{v_str}" diff --git a/tools/assets/extract/extase_oot64/dlist_resources.py b/tools/assets/extract/extase_oot64/dlist_resources.py index c7ead26cbe..32ca8d5328 100644 --- a/tools/assets/extract/extase_oot64/dlist_resources.py +++ b/tools/assets/extract/extase_oot64/dlist_resources.py @@ -32,6 +32,8 @@ from ..extase.cdata_resources import ( CDataExt_Value, CDataExtWriteContext, INDENT, + fmt_hex_s, + fmt_hex_u, ) @@ -110,8 +112,8 @@ class VtxArrayResource(CDataResource): wctx.f.write(wctx.line_prefix) wctx.f.write( f"VTX({v['x']:6}, {v['y']:6}, {v['z']:6}, " - f"{v['s']:#7X}, {v['t']:#7X}, " - f"{v['crnx']:#04X}, {v['cgny']:#04X}, {v['cbnz']:#04X}, {v['a']:#04X})" + f"{fmt_hex_s(v['s']):>7}, {fmt_hex_s(v['t']):>7}, " + f"{fmt_hex_u(v['crnx'], 2)}, {fmt_hex_u(v['cgny'], 2)}, {fmt_hex_u(v['cbnz'], 2)}, {fmt_hex_u(v['a'], 2)})" ) return True diff --git a/tools/assets/extract/extase_oot64/playeranim_resources.py b/tools/assets/extract/extase_oot64/playeranim_resources.py index ddebc662ed..b159d8a67a 100644 --- a/tools/assets/extract/extase_oot64/playeranim_resources.py +++ b/tools/assets/extract/extase_oot64/playeranim_resources.py @@ -12,11 +12,12 @@ from ..extase.cdata_resources import ( CDataExt_Struct, CDataExt_Value, CDataExtWriteContext, + fmt_hex_s, ) class PlayerAnimationDataResource(CDataArrayResource): - elem_cdata_ext = CDataExt_Value("h").set_write_str_v(lambda v: f"{v:#X}") + elem_cdata_ext = CDataExt_Value("h").set_write_str_v(lambda v: fmt_hex_s(v)) def __init__(self, file, range_start, name): super().__init__(file, range_start, name) diff --git a/tools/assets/extract/extase_oot64/scene_rooms_resources.py b/tools/assets/extract/extase_oot64/scene_rooms_resources.py index 94fb29530b..d361c6cf97 100644 --- a/tools/assets/extract/extase_oot64/scene_rooms_resources.py +++ b/tools/assets/extract/extase_oot64/scene_rooms_resources.py @@ -20,6 +20,7 @@ from ..extase.cdata_resources import ( cdata_ext_Vec3s, INDENT, Vec3sArrayResource, + fmt_hex_s, ) from .. import oot64_data @@ -28,42 +29,6 @@ from .. import oot64_data VERBOSE_SPAWN_LIST_LENGTH_GUESSING = False -def fmt_hex_s(v: int, nibbles: int = 0): - """Format v to 0x-prefixed uppercase hexadecimal, using (at least) the specified amount of nibbles. - - Meant for signed values (_s suffix), - adds a space in place of where the - sign would be for positive values. - - Note compared to this, - - f"{v:#X}" would produce an uppercase 0X (1 -> 0X1) - - f"0x{v:X}" doesn't work with negative values (-1 -> 0x-1) - """ - v_str = f"{v:0{nibbles}X}" - if v < 0: - v_str = v_str.removeprefix("-") - return f"-0x{v_str}" - else: - return f" 0x{v_str}" - - -def fmt_hex_u(v: int, nibbles: int = 0): - """Format v to 0x-prefixed uppercase hexadecimal, using (at least) the specified amount of nibbles. - - Meant for unsigned values (_u suffix), - but won't fail for negative values. - - See: fmt_hex_s - """ - v_str = f"{v:0{nibbles}X}" - if v < 0: - # Also handle v being negative just in case, - # it will only mean the output isn't aligned as expected - v_str = v_str.removeprefix("-") - return f"-0x{v_str}" - else: - return f"0x{v_str}" - - class ActorEntryListResource(CDataArrayNamedLengthResource): def write_elem(resource, memory_context, v, wctx: CDataExtWriteContext): assert isinstance(v, dict)