1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-05-09 18:43:45 +00:00

0XHEX -> 0xHEX

This commit is contained in:
Dragorn421 2025-05-06 19:18:37 +02:00
parent 78675719c1
commit 428a75b4ec
No known key found for this signature in database
GPG key ID: 381AEBAF3D429335
4 changed files with 43 additions and 39 deletions

View file

@ -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}"

View file

@ -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

View file

@ -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)

View file

@ -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)