Skip to content

Commit

Permalink
Last thing?
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilaa3 committed Sep 30, 2024
1 parent f3570e5 commit cd7a274
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 24 deletions.
9 changes: 6 additions & 3 deletions fast64_internal/sm64/animation/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,9 +746,12 @@ def to_combined_binary(self, table_address=0, data_address=-1, segment_data: Seg
table_data.extend(encodeSegmentedAddr(header_offset, segment_data))
else:
table_data.extend(header_offset.to_bytes(4, byteorder="big"))
else:
assert isinstance(element.reference, int), f"Reference at element {i} is not an int."
table_data.extend(element.reference.to_bytes(4, byteorder="big"))
continue
if element.reference is None:
table_data.extend(0x0.to_bytes(4, byteorder="big"))
continue
assert isinstance(element.reference, int), f"Reference at element {i} is not an int."
table_data.extend(element.reference.to_bytes(4, byteorder="big"))

for anim_header in headers_set: # Add the headers
if not anim_header.data:
Expand Down
16 changes: 5 additions & 11 deletions fast64_internal/sm64/animation/exporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def to_table_class(
anim_props.get_table_name(actor_name),
anim_props.get_enum_name(actor_name),
anim_props.get_enum_end(actor_name),
"table.inc.c",
anim_props.get_table_file_name(actor_name, export_type),
values_reference=toAlnum(f"anim_{actor_name}_values"),
)

Expand Down Expand Up @@ -719,11 +719,9 @@ def export_animation_table_binary(
)


def export_animation_table_insertable(
anim_props: "SM64_ArmatureAnimProperties", table: SM64_AnimTable, is_dma: bool, directory: Path
):
def export_animation_table_insertable(table: SM64_AnimTable, is_dma: bool, directory: Path):
directory_path_checks(directory, "Empty directory path.")
path = directory / anim_props.insertable_file_name
path = directory / table.file_name
if is_dma:
data = table.to_binary_dma()
InsertableBinaryData("Animation DMA Table", data).write(path)
Expand Down Expand Up @@ -955,9 +953,7 @@ def export_animation(context: Context, obj: Object):
animation, anim_props, combined_props, sm64_props.abs_decomp_path, actor_name, sm64_props.designated
)
elif sm64_props.export_type == "Insertable Binary":
export_animation_insertable(
animation, anim_props.is_dma, Path(abspath(combined_props.insertable_directory_path))
)
export_animation_insertable(animation, anim_props.is_dma, Path(abspath(combined_props.insertable_directory)))
elif sm64_props.export_type == "Binary":
with BinaryExporter(
Path(abspath(sm64_props.export_rom)), Path(abspath(sm64_props.output_rom))
Expand Down Expand Up @@ -1012,9 +1008,7 @@ def export_animation_table(context: Context, obj: Object):
anim_props, combined_props, table, sm64_props.abs_decomp_path, actor_name, sm64_props.designated
)
elif sm64_props.export_type == "Insertable Binary":
export_animation_table_insertable(
anim_props, table, anim_props.is_dma, Path(abspath(combined_props.insertable_directory_path))
)
export_animation_table_insertable(table, anim_props.is_dma, Path(abspath(combined_props.insertable_directory)))
elif sm64_props.export_type == "Binary":
with BinaryExporter(
Path(abspath(sm64_props.export_rom)), Path(abspath(sm64_props.output_rom))
Expand Down
19 changes: 17 additions & 2 deletions fast64_internal/sm64/animation/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,7 @@ def upgrade_old_props(self, scene: Scene):
if end_address is not None:
action_props.end_address = intToHex(int(end_address, 16))

insertable_path = scene.pop("animInsertableBinaryPath", "")
is_dma = scene.pop("loopAnimation", None)
update_table = scene.pop("animExportStart", None)
update_behavior = scene.pop("animExportEnd", None)
Expand All @@ -917,6 +918,9 @@ def upgrade_old_props(self, scene: Scene):
anim_props.update_behavior = update_behavior
if beginning_animation is not None:
anim_props.beginning_animation = beginning_animation
if insertable_path is not None: # Ignores directory
anim_props.use_custom_file_name = True
anim_props.custom_file_name = os.path.split(insertable_path)[0]

# Deprecated:
# - addr 0x27 was a pointer to a load anim cmd that would be used to update table pointers
Expand Down Expand Up @@ -974,7 +978,8 @@ class SM64_ArmatureAnimProperties(PropertyGroup):
dma_address: StringProperty(name="DMA Table Address", default=intToHex(0x4EC000))
dma_end_address: StringProperty(name="DMA Table End", default=intToHex(0x4EC000 + 0x8DC20))

insertable_file_name: StringProperty(name="Insertable File Name", default="toad.insertable")
use_custom_file_name: BoolProperty(name="File Name")
custom_file_name: StringProperty(name="File Name", default="toad.insertable")

@property
def behavior_address(self) -> int:
Expand Down Expand Up @@ -1011,6 +1016,16 @@ def get_enum_end(self, actor_name: str):
table_name = self.get_table_name(actor_name)
return f"{table_name.upper()}_END"

def get_table_file_name(self, actor_name: str, export_type: str) -> str:
if not export_type in {"C", "Insertable Binary"}:
return ""
elif export_type == "Insertable Binary":
if self.use_custom_file_name:
return self.custom_file_name
return clean_name(actor_name + ("_dma_table" if self.is_dma else "_table")) + ".insertable"
else:
return "table.inc.c"

def draw_element(
self,
layout: UILayout,
Expand Down Expand Up @@ -1094,7 +1109,7 @@ def draw_table(self, layout: UILayout, export_type: str, actor_name: str, bhv_ex
string_int_prop(col, self, "data_end_address", "Data End")
col.prop(self, "null_delimiter")
if export_type == "Insertable Binary":
prop_split(col, self, "insertable_file_name", "File Name")
draw_custom_or_auto(self, col, "file_name", self.get_table_file_name(actor_name, export_type))

col.separator()

Expand Down
7 changes: 3 additions & 4 deletions fast64_internal/sm64/settings/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,9 @@ def upgrade_changed_props():
for new, old in old_export_props_to_new.items():
upgrade_old_prop(combined_props, new, scene, old)

insertable_directory_path = get_first_set_prop(scene, "animInsertableBinaryPath")
if insertable_directory_path:
# Ignores file name
combined_props.insertable_directory_path = os.path.split(insertable_directory_path)[0]
insertable_directory = get_first_set_prop(scene, "animInsertableBinaryPath")
if insertable_directory is not None: # Ignores file name
combined_props.insertable_directory = os.path.split(insertable_directory)[1]

sm64_props.version = SM64_Properties.cur_version

Expand Down
6 changes: 2 additions & 4 deletions fast64_internal/sm64/sm64_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -2008,9 +2008,7 @@ def update_or_inherit(new_cmd, index, arg_val, bhv_arg):
description="Animation export will only export the armature's current action like in older versions of fast64",
)
binary_level: bpy.props.EnumProperty(items=level_enums, name="Level", default="IC")
insertable_directory_path: bpy.props.StringProperty(
name="Directory Path", subtype="FILE_PATH"
) # TODO should this be here
insertable_directory: bpy.props.StringProperty(name="Directory Path", subtype="FILE_PATH")

# export options
export_bhv: bpy.props.BoolProperty(
Expand Down Expand Up @@ -2220,7 +2218,7 @@ def draw_anim_props(self, layout: UILayout, export_type="C", is_dma=False):
if not is_dma:
prop_split(col, self, "binary_level", "Level")
elif export_type == "Insertable Binary":
prop_split(col, self, "insertable_directory_path", "Directory")
prop_split(col, self, "insertable_directory", "Directory")

def draw_export_options(self, layout):
split = layout.row(align=True)
Expand Down

0 comments on commit cd7a274

Please sign in to comment.