diff --git a/fast64_internal/z64/animation/operators.py b/fast64_internal/z64/animation/operators.py index 9e7e44e8a..d80a9e5b0 100644 --- a/fast64_internal/z64/animation/operators.py +++ b/fast64_internal/z64/animation/operators.py @@ -1,4 +1,5 @@ import mathutils, bpy, os +from pathlib import Path from bpy.types import Scene, Operator, Armature from bpy.props import StringProperty, BoolProperty from bpy.utils import register_class, unregister_class @@ -11,23 +12,30 @@ from ..utility import ( ootGetPath, addIncludeFiles, + addIncludeFilesExtension, checkEmptyName, ootGetObjectPath, getOOTScale, + add_include_to_spec_segment, ) def exportAnimationC(armatureObj: bpy.types.Object, settings: OOTAnimExportSettingsProperty): if settings.isCustom: checkEmptyName(settings.customPath) - else: + elif not settings.isLink: checkEmptyName(settings.folderName) if settings.isCustomFilename: checkEmptyName(settings.filename) path = bpy.path.abspath(settings.customPath) - exportPath = ootGetObjectPath(settings.isCustom, path, settings.folderName, False) + if settings.isCustom: + exportPath = path + elif not settings.isLink: + exportPath = ootGetObjectPath(settings.isCustom, path, settings.folderName, False) + else: + exportPath = None # Won't be used as the export is not custom checkEmptyName(armatureObj.name) name = toAlnum(armatureObj.name) @@ -40,20 +48,21 @@ def exportAnimationC(armatureObj: bpy.types.Object, settings: OOTAnimExportSetti if settings.isLink: ootAnim = ootExportLinkAnimation(armatureObj, convertTransformMatrix, name) ootAnimC, ootAnimHeaderC = ootAnim.toC(settings.isCustom) + path = ootGetPath( exportPath, settings.isCustom, "assets/misc/link_animetion", - settings.folderName if settings.isCustom else "", - False, + "", + True, False, ) headerPath = ootGetPath( exportPath, settings.isCustom, "assets/objects/gameplay_keep", - settings.folderName if settings.isCustom else "", - False, + "", + True, False, ) writeCData( @@ -66,8 +75,22 @@ def exportAnimationC(armatureObj: bpy.types.Object, settings: OOTAnimExportSetti ) if not settings.isCustom: - addIncludeFiles("link_animetion", path, ootAnim.dataName()) - addIncludeFiles("gameplay_keep", headerPath, ootAnim.headerName) + if (Path(bpy.context.scene.ootDecompPath) / "assets/objects/gameplay_keep/gameplay_keep.c").exists(): + # Pre "new" assets system + addIncludeFiles("link_animetion", path, ootAnim.dataName()) + addIncludeFiles("gameplay_keep", headerPath, ootAnim.headerName) + else: + add_include_to_spec_segment( + Path(bpy.context.scene.ootDecompPath) / "spec/spec", + "link_animetion", + f"$(BUILD_DIR)/assets/misc/link_animetion/{ootAnim.dataName()}.o", + ) + add_include_to_spec_segment( + Path(bpy.context.scene.ootDecompPath) / "spec/spec", + "gameplay_keep", + f"$(BUILD_DIR)/assets/objects/gameplay_keep/{ootAnim.headerName}.o", + ) + addIncludeFilesExtension("gameplay_keep", headerPath, ootAnim.headerName, "h") else: ootAnim = ootExportNonLinkAnimation(armatureObj, convertTransformMatrix, name, filename) diff --git a/fast64_internal/z64/animation/properties.py b/fast64_internal/z64/animation/properties.py index ab3a641c9..ef1445c29 100644 --- a/fast64_internal/z64/animation/properties.py +++ b/fast64_internal/z64/animation/properties.py @@ -31,9 +31,10 @@ class OOTAnimExportSettingsProperty(PropertyGroup): def draw_props(self, layout: UILayout): layout.label(text="Exports active animation on selected object.", icon="INFO") - layout.prop(self, "isCustomFilename") - if self.isCustomFilename: - prop_split(layout, self, "filename", "Filename") + if not self.isLink: + layout.prop(self, "isCustomFilename") + if self.isCustomFilename: + prop_split(layout, self, "filename", "Filename") if self.isCustom: prop_split(layout, self, "customPath", "Folder") elif not self.isLink: diff --git a/fast64_internal/z64/exporter/animation/classes.py b/fast64_internal/z64/exporter/animation/classes.py index ef3be8b44..c2124231b 100644 --- a/fast64_internal/z64/exporter/animation/classes.py +++ b/fast64_internal/z64/exporter/animation/classes.py @@ -102,16 +102,16 @@ def toC(self, isCustomExport: bool): animHeaderData.header = f"#ifndef {self.headerName.upper()}_H\n" + f"#define {self.headerName.upper()}_H\n\n" if bpy.context.scene.fast64.oot.is_globalh_present(): - data.header = '#include "ultra64.h"\n' + '#include "global.h"\n\n' - animHeaderData.header = '#include "ultra64.h"\n' + '#include "global.h"\n\n' + data.header += '#include "ultra64.h"\n' + '#include "global.h"\n\n' + animHeaderData.header += '#include "ultra64.h"\n' + '#include "global.h"\n\n' elif bpy.context.scene.fast64.oot.is_z64sceneh_present(): - data.header = '#include "ultra64.h"\n' + '#include "array_count.h"\n' + '#include "z64animation.h"\n\n' - animHeaderData.header = ( + data.header += '#include "ultra64.h"\n' + '#include "array_count.h"\n' + '#include "z64animation.h"\n\n' + animHeaderData.header += ( '#include "ultra64.h"\n' + '#include "array_count.h"\n' + '#include "z64animation.h"\n\n' ) else: - data.header = '#include "ultra64.h"\n' + '#include "array_count.h"\n' + '#include "animation.h"\n\n' - animHeaderData.header = ( + data.header += '#include "ultra64.h"\n' + '#include "array_count.h"\n' + '#include "animation.h"\n\n' + animHeaderData.header += ( '#include "ultra64.h"\n' + '#include "array_count.h"\n' + '#include "animation.h"\n\n' ) diff --git a/fast64_internal/z64/utility.py b/fast64_internal/z64/utility.py index 5e229acb0..da7bd8719 100644 --- a/fast64_internal/z64/utility.py +++ b/fast64_internal/z64/utility.py @@ -1,6 +1,7 @@ import bpy import math import os +from pathlib import Path import re import traceback @@ -1031,3 +1032,28 @@ def is_oot_features(): def is_hackeroot(): return game_data.z64.is_oot() and bpy.context.scene.fast64.oot.feature_set == "hackeroot" + + +def add_include_to_spec_segment(spec_p: Path, segment: str, inc: str): + spec_content = spec_p.read_text() + new_spec_lines = [] + in_segment = False + in_target_segment = False + found_existing_include = False + include_line_to_add = f' include "{inc}"\n' + for l in spec_content.splitlines(keepends=True): + if l.strip() == "beginseg": + in_segment = True + if l.strip() == "endseg": + if in_target_segment and not found_existing_include: + new_spec_lines.append(include_line_to_add) + in_segment = False + in_target_segment = False + if in_segment and l.split() == f'name "{segment}"'.split(): + in_target_segment = True + if in_target_segment and l.split() == include_line_to_add.split(): + found_existing_include = True + new_spec_lines.append(l) + new_spec_content = "".join(new_spec_lines) + if new_spec_content != spec_content: + spec_p.write_text(new_spec_content)