From 9d1ed8013ad481596cc5c709afc43e79665b6d12 Mon Sep 17 00:00:00 2001 From: Lila Date: Sun, 22 Sep 2024 18:48:19 +0100 Subject: [PATCH] lots of random clean ups --- fast64_internal/sm64/animation/classes.py | 33 ++++++++++---------- fast64_internal/sm64/animation/exporting.py | 20 ++++++------ fast64_internal/sm64/animation/properties.py | 6 ++-- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/fast64_internal/sm64/animation/classes.py b/fast64_internal/sm64/animation/classes.py index d67f8e269..50b929ad6 100644 --- a/fast64_internal/sm64/animation/classes.py +++ b/fast64_internal/sm64/animation/classes.py @@ -139,6 +139,7 @@ def read_c(self, indice_decl: CArrayDeclaration, value_decl: CArrayDeclaration): class SM64_AnimFlags(IntFlag): + prop: Optional[str] def __new__(cls, value, blender_prop: str | None = None): obj = int.__new__(cls, value) obj._value_, obj.prop = 1 << value, blender_prop @@ -482,7 +483,7 @@ def enum_names(self) -> list[str]: def to_binary_dma(self): assert self.data - headers: list[bytearray] = [] + headers: list[bytes] = [] indice_offset = HEADER_SIZE * len(self.headers) anim_data, values_offset = self.data.to_binary() @@ -498,20 +499,24 @@ def to_binary(self, start_address: int = 0, segment_data: SegmentData | None = N data: bytearray = bytearray() ptrs: list[int] = [] if self.data: - indice_offset = start_address + (HEADER_SIZE * len(self.headers)) anim_data, values_offset = self.data.to_binary() + indice_offset = start_address + (HEADER_SIZE * len(self.headers)) + values_offset = indice_offset + values_offset + else: + anim_data = bytearray() + indice_offset = values_offset = None for header in self.headers: - ptrs.extend([start_address + len(data) + 12, start_address + len(data) + 16]) + if self.data: + ptrs.extend([start_address + len(data) + 12, start_address + len(data) + 16]) header_data = header.to_binary( - indice_offset + values_offset if self.data else None, - indice_offset if self.data else None, + values_offset, + indice_offset, segment_data, ) data.extend(header_data) - if self.data: - data.extend(anim_data) - return data, ptrs - return data, [] + + data.extend(anim_data) + return data, ptrs def headers_to_c(self, dma_structure: bool) -> str: text_data = StringIO() @@ -578,7 +583,7 @@ def to_c(self, designated: bool): @dataclasses.dataclass class SM64_AnimTable: - reference: str | int = None + reference: str | int = "" enum_list_reference: str = "" enum_list_delimiter: str = "" file_name: str = "" @@ -683,11 +688,7 @@ def get_seperate_anims_dma(self) -> list[SM64_Anim]: data = copy(data) data_already_added.append(data) - data.indice_reference, data.values_reference, data.file_name = ( - f"{name}_indices", - f"{name}_values", - file_name, - ) + data.indice_reference, data.values_reference = f"{name}_indices", f"{name}_values)" # Normal names are possible (order goes by line and file) but would break convention for i, included_header in enumerate(included_headers): included_header.file_name = file_name @@ -782,7 +783,7 @@ def read_binary( table_index: Optional[int] = None, bone_count: Optional[int] = None, size: Optional[int] = None, - ) -> SM64_AnimHeader | None: + ): print(f"Reading table at address {reader.start_address}.") self.elements.clear() self.reference = reader.start_address diff --git a/fast64_internal/sm64/animation/exporting.py b/fast64_internal/sm64/animation/exporting.py index 046ab4b0c..394d66b29 100644 --- a/fast64_internal/sm64/animation/exporting.py +++ b/fast64_internal/sm64/animation/exporting.py @@ -194,7 +194,7 @@ def to_xyz(row): def to_header_class( header_props: "SM64_AnimHeaderProperties", bone_count: int, - data: SM64_AnimData, + data: SM64_AnimData | None, action: Action, values_reference: int | str, indice_reference: int | str, @@ -286,11 +286,13 @@ def to_table_element_class( export_type: str, actor_name="mario", gen_enums=False, - prev_enums: dict[str, int] = None, + prev_enums: dict[str, int] | None = None, ): + prev_enums = {} or prev_enums use_addresses, can_reference = export_type.endswith("Binary"), not dma element = SM64_AnimTableElement() + enum = None if gen_enums: enum = element_props.get_enum(can_reference, actor_name, prev_enums) element.enum_name = enum @@ -300,7 +302,7 @@ def to_table_element_class( element.reference = reference if reference == "": raise PluginError("Header is not set.") - if gen_enums and enum == "": + if enum == "": raise PluginError("Enum name is not set.") return element @@ -310,7 +312,7 @@ def to_table_element_class( raise PluginError("Action is not set.") if not header_props: raise PluginError("Header is not set.") - if gen_enums and enum == "": + if enum == "": raise PluginError("Enum name is not set.") action_props = get_action_props(action) @@ -333,9 +335,8 @@ def to_table_element_class( data = data_dict[action] values_reference, indice_reference = data.values_reference, data.indice_reference - element.header = header_dict.get( - header_props, - to_header_class( + if header_props not in header_dict: + header_dict[header_props] = to_header_class( header_props=header_props, bone_count=bone_count, data=data, @@ -348,8 +349,9 @@ def to_table_element_class( actor_name=actor_name, gen_enums=gen_enums, file_name=action_props.get_file_name(action, export_type), - ), - ) + ) + + element.header = header_dict[header_props] element.reference = element.header.reference return element diff --git a/fast64_internal/sm64/animation/properties.py b/fast64_internal/sm64/animation/properties.py index f8ecb8c94..c9ca394cf 100644 --- a/fast64_internal/sm64/animation/properties.py +++ b/fast64_internal/sm64/animation/properties.py @@ -378,12 +378,12 @@ def headers(self) -> list[SM64_AnimHeaderProperties]: def dma_name(self): return get_dma_anim_name([header.table_index for header in self.headers]) - def get_name(self, action: Action, dma=False): + def get_name(self, action: Action, dma=False) -> str: if dma: return self.dma_name return toAlnum(f"anim_{action.name}") - def get_file_name(self, action: Action, export_type: str, dma=False) -> Path: + def get_file_name(self, action: Action, export_type: str, dma=False) -> str: if not export_type in {"C", "Insertable Binary"}: return "" if export_type == "C" and dma: @@ -487,7 +487,7 @@ def draw_props( text = "File Name" if not in_table and not export_seperately: text = "File Name (individual action export)" - draw_custom_or_auto(self, col, "file_name", str(self.get_file_name(action, export_type)), text=text) + draw_custom_or_auto(self, col, "file_name", self.get_file_name(action, export_type), text=text) elif not in_table: # C DMA forced auto name split = col.split(factor=0.5) split.label(text="File Name")