Skip to content

Commit

Permalink
lots of random clean ups
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilaa3 committed Sep 22, 2024
1 parent 583404a commit 9d1ed80
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
33 changes: 17 additions & 16 deletions fast64_internal/sm64/animation/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 11 additions & 9 deletions fast64_internal/sm64/animation/exporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions fast64_internal/sm64/animation/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 9d1ed80

Please sign in to comment.