Skip to content

Commit

Permalink
LETS GO!!!!!!!!!!!!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilaa3 committed Jan 20, 2024
1 parent 483c327 commit 1ab571d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 35 deletions.
2 changes: 2 additions & 0 deletions anim_header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extern enum MarioAnims;
extern const struct Animation *const mario_anims[];
16 changes: 11 additions & 5 deletions fast64_internal/sm64/animation/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,22 +294,28 @@ def headers_to_c(self, is_dma_structure: bool) -> str:
data.write("\n")
return data.getvalue()

def data_to_c(self):
def data_to_c(self, is_dma_structure: bool):
if self.reference:
return

values_table, indices_table = self.create_tables()

data = StringIO()
data.write(values_table.to_c())
data.write("\n\n")
data.write(indices_table.to_c())

if is_dma_structure:
data.write(indices_table.to_c())
data.write("\n\n")
data.write(values_table.to_c())
else:
data.write(values_table.to_c())
data.write("\n\n")
data.write(indices_table.to_c())

return data.getvalue()

def to_c(self, is_dma_structure: bool):
data = StringIO()
c_data = self.data_to_c()
c_data = self.data_to_c(is_dma_structure)
c_headers = self.headers_to_c(is_dma_structure)
if is_dma_structure:
data.write(c_headers)
Expand Down
14 changes: 8 additions & 6 deletions fast64_internal/sm64/animation/exporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ def updateIncludes(level_name, groupName, dir_name, dir_path, header_type: str):
writeIfNotFound(groupPathH, '\n#include "levels/' + level_name + "/" + dir_name + '/anim_header.h"', "\n#endif")


def write_anim_header(geo_dir_path: str, anims_name: str):
headerPath = os.path.join(geo_dir_path, "anim_header.h")
headerFile = open(headerPath, "w", newline="\n")
headerFile.write("extern const struct Animation *const " + anims_name + "[];\n")
headerFile.close()
def write_anim_header(anim_header_path: str, table_name: str, generate_enums: bool, enum_list_name: str):
with open(anim_header_path, "w", newline="\n") as file:
if generate_enums:
file.write(f"extern enum {enum_list_name};\n")
file.write(f"extern const struct Animation *const {table_name}[];\n")


def update_table_file(table_path: str, header_names: str, table_name: str, generate_enums: bool, enum_list_name: str):
Expand All @@ -142,6 +142,7 @@ def update_table_file(table_path: str, header_names: str, table_name: str, gener
with open(table_path, "r") as file:
text = file.read()

# Enum
if generate_enums:
enum_list_index = text.find(enum_list_name)
if enum_list_index == -1: # If there is no enum list, add one and find again
Expand All @@ -154,6 +155,7 @@ def update_table_file(table_path: str, header_names: str, table_name: str, gener
enum_list_end = text.find("}", enum_list_index)
text = text[:enum_list_end] + f"\t{enum_name},\n" + text[enum_list_end:]

# Table
table_index = text.find(table_name)
if table_index == -1: # If there is no table, add one and find again
text += f"const struct Animation *const {table_name}[] = {{\n\tNULL,\n}};\n"
Expand All @@ -176,7 +178,7 @@ def update_table_file(table_path: str, header_names: str, table_name: str, gener
else:
text = text[:table_end] + f"\t{header_reference},\n" + text[table_end:]

with open(table_path, "w") as file:
with open(table_path, "w", newline="\n") as file:
file.write(text)


Expand Down
45 changes: 23 additions & 22 deletions fast64_internal/sm64/animation/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,9 @@ def execute_operator(self, context):
)

if sm64_props.export_type == "C":
anim_dir_path, dir_path, geo_dir_path, level_name = anim_export_props.get_animation_paths()

if not os.path.exists(dir_path):
os.mkdir(dir_path)
if not os.path.exists(geo_dir_path):
os.mkdir(geo_dir_path)
if not os.path.exists(anim_dir_path):
os.mkdir(anim_dir_path)

anim_dir_path, dir_path, geo_dir_path, level_name = anim_export_props.get_animation_paths(
create_directories=True
)
anim_file_name = action_props.get_anim_file_name(action)
anim_path = os.path.join(anim_dir_path, anim_file_name)
if anim_export_props.header_type != "Custom":
Expand All @@ -309,19 +303,26 @@ def execute_operator(self, context):
with open(anim_path, "w", newline="\n") as file:
file.write(animation.to_c(anim_export_props.is_dma_structure(sm64_props)))

table_name = table_props.get_anim_table_name(anim_export_props.actor_name)
write_anim_header(geo_dir_path, table_name)

table_path = os.path.join(anim_dir_path, table_props.get_anim_table_file_name())
data_file_path = os.path.join(anim_dir_path, "data.inc.c")
update_table_file(
table_path,
[header.get_anim_name(anim_export_props.actor_name, action) for header in action_props.get_headers()],
table_name,
table_props.generate_enums,
table_props.get_enum_list_name(anim_export_props.actor_name),
)
updateDataFile(data_file_path, anim_file_name)
if anim_export_props.header_type != "DMA":
table_name = table_props.get_anim_table_name(anim_export_props.actor_name)
enum_list_name = table_props.get_enum_list_name(anim_export_props.actor_name)

anim_header_path = os.path.join(geo_dir_path, "anim_header.h")
write_anim_header(anim_header_path, table_name, table_props.generate_enums, enum_list_name)

table_path = os.path.join(anim_dir_path, table_props.get_anim_table_file_name())
data_file_path = os.path.join(anim_dir_path, "data.inc.c")
update_table_file(
table_path,
[
header.get_anim_name(anim_export_props.actor_name, action)
for header in action_props.get_headers()
],
table_name,
table_props.generate_enums,
enum_list_name,
)
updateDataFile(data_file_path, anim_file_name)

if not anim_export_props.header_type in {"Custom", "DMA"}:
updateIncludes(
Expand Down
12 changes: 10 additions & 2 deletions fast64_internal/sm64/animation/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ def is_dma_structure(self, sm64_props):
return self.use_dma_structure
return False

def get_animation_paths(self):
def get_animation_paths(self, create_directories: bool = False):
custom_export = self.header_type == "Custom"

exportPath, level_name = getPathAndLevel(
Expand All @@ -719,13 +719,21 @@ def get_animation_paths(self):
dirName = toAlnum(self.actor_name)

if self.header_type == "DMA":
anim_dir_path = os.path.join(exportPath, self.DMAFolder)
anim_dir_path = os.path.join(exportPath, self.dma_folder)
dir_path = ""
geo_dir_path = ""
else:
dir_path = getExportDir(custom_export, exportPath, self.header_type, level_name, "", dirName)[0]
geo_dir_path = os.path.join(dir_path, dirName)
anim_dir_path = os.path.join(geo_dir_path, "anims")
if create_directories:
if not os.path.exists(dir_path):
os.mkdir(dir_path)
if not os.path.exists(geo_dir_path):
os.mkdir(geo_dir_path)

if create_directories and not os.path.exists(anim_dir_path):
os.mkdir(anim_dir_path)

return (
abspath(anim_dir_path),
Expand Down

0 comments on commit 1ab571d

Please sign in to comment.