Skip to content

Commit

Permalink
yay
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilaa3 committed Jan 14, 2024
1 parent 7aca431 commit 857347b
Show file tree
Hide file tree
Showing 7 changed files with 672 additions and 1,437 deletions.
55 changes: 31 additions & 24 deletions fast64_internal/sm64/animation/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class SM64_AnimHeader:
header_variant: int = 0
flags: str | int = None
yDivisor: int = 0
startFrame: int = 0
loopStart: int = 0
start_frame: int = 0
loop_start: int = 0
loop_end: int = 1
boneCount: int = None
values: str = ""
Expand All @@ -34,8 +34,8 @@ def toC(self, designated: bool, asArray: bool) -> str:
headerData: list[tuple[str, object]] = [
("flags", self.flags),
("animYTransDivisor", self.yDivisor),
("startFrame", self.startFrame),
("loopStart", self.loopStart),
("startFrame", self.start_frame),
("loopStart", self.loop_start),
("loop_end", self.loop_end),
("unusedBoneCount", f"ANIMINDEX_NUMPARTS({self.data.indicesReference})"), # Unused but potentially useful
("values", self.data.valuesReference),
Expand All @@ -54,8 +54,8 @@ def toBinary(self, indicesReference, valuesReference):
data = bytearray()
data.extend(self.flags.to_bytes(2, byteorder="big", signed=False)) # 0x00
data.extend(self.yDivisor.to_bytes(2, byteorder="big", signed=True)) # 0x02
data.extend(self.startFrame.to_bytes(2, byteorder="big", signed=True)) # 0x04
data.extend(self.loopStart.to_bytes(2, byteorder="big", signed=True)) # 0x06
data.extend(self.start_frame.to_bytes(2, byteorder="big", signed=True)) # 0x04
data.extend(self.loop_start.to_bytes(2, byteorder="big", signed=True)) # 0x06
data.extend(self.loop_end.to_bytes(2, byteorder="big", signed=True)) # 0x08
data.extend(self.boneCount.to_bytes(2, byteorder="big", signed=True)) # 0x0A
data.extend(valuesReference.to_bytes(4, byteorder="big", signed=False)) # 0x0C
Expand All @@ -66,11 +66,14 @@ def toBinary(self, indicesReference, valuesReference):

# Importing
def toHeaderProps(self, action, header):
intFlagsToProps = {
"ANIM_FLAG_NOLOOP": "noLoop",
"ANIM_FLAG_BACKWARD": "backward",
"ANIM_FLAG_NO_ACCEL": "noAcceleration",
flagsToProps = {
"ANIM_FLAG_NOLOOP": "no_loop",
"ANIM_FLAG_BACKWARD": "backwards",
"ANIM_FLAG_NO_ACCEL": "no_acceleration",
"ANIM_FLAG_DISABLED": "disabled",
"ANIM_FLAG_HOR_TRANS": "only_horizontal_trans",
"ANIM_FLAG_VERT_TRANS": "only_vertical_trans",
"ANIM_FLAG_NO_TRANS": "no_trans",
}
intFlagsToString = {
0: "ANIM_FLAG_NOLOOP",
Expand All @@ -89,10 +92,10 @@ def toHeaderProps(self, action, header):
header.overrideName = True
header.customName = self.name

correctFrameRange = self.startFrame, self.loopStart, self.loop_end
header.startFrame, header.loopStart, header.loop_end = correctFrameRange
if correctFrameRange != header.getFrameRange(action): # If auto frame range is wrong
header.manualFrameRange = True
correctFrameRange = self.start_frame, self.loop_start, self.loop_end
header.start_frame, header.loop_start, header.loop_end = correctFrameRange
if correctFrameRange != header.get_frame_range(action): # If auto frame range is wrong
header.manual_frame_range = True

header.yDivisor = self.yDivisor

Expand All @@ -101,8 +104,8 @@ def toHeaderProps(self, action, header):
cFlags = [flag for bit, flag in intFlagsToString.items() if is_bit_active(self.flags, bit)]
header.customFlags = " | ".join(cFlags)
for cFlag in cFlags:
if cFlag in intFlagsToProps:
setattr(header, intFlagsToProps[cFlag], True)
if cFlag in flagsToProps:
setattr(header, flagsToProps[cFlag], True)
else:
header.setCustomFlags = True
else:
Expand All @@ -115,8 +118,8 @@ def read_binary(self, romfile: BinaryIO, address: int, segmentData, isDMA: bool
self.address = address
self.flags = headerReader.read_value(2, signed=False) # /*0x00*/ s16 flags;
self.yDivisor = headerReader.read_value(2) # /*0x02*/ s16 animYTransDivisor;
self.startFrame = headerReader.read_value(2) # /*0x04*/ s16 startFrame;
self.loopStart = headerReader.read_value(2) # /*0x06*/ s16 loopStart;
self.start_frame = headerReader.read_value(2) # /*0x04*/ s16 startFrame;
self.loop_start = headerReader.read_value(2) # /*0x06*/ s16 loopStart;
self.loop_end = headerReader.read_value(2) # /*0x08*/ s16 loopEnd;
# Unused in engine but makes it easy to read animation data
self.boneCount = headerReader.read_value(2) # /*0x0A*/ s16 unusedBoneCount;
Expand All @@ -132,7 +135,7 @@ def read_binary(self, romfile: BinaryIO, address: int, segmentData, isDMA: bool
self.indices = decodeSegmentedAddr(indicesOffset.to_bytes(4, byteorder="big"), segmentData)

def readC(self, value: Initialization):
self.name = toAlnum(value.name)
self.name = value.name

structDict = value.array_to_struct_dict(
[
Expand All @@ -150,8 +153,8 @@ def readC(self, value: Initialization):

self.flags = structDict["flags"]
self.yDivisor = structDict["animYTransDivisor"]
self.startFrame = structDict["startFrame"]
self.loopStart = structDict["loopStart"]
self.start_frame = structDict["startFrame"]
self.loop_start = structDict["loopStart"]
self.loop_end = structDict["loopEnd"]

self.values = structDict["values"]
Expand Down Expand Up @@ -345,21 +348,25 @@ def toC(self, mergeValues: bool, useHexValues: bool) -> str:
return cData.getvalue()

# Importing
def to_action(self, action):
def to_action(self, action, remove_name_footer: bool = True):
action_props = action.fast64.sm64

if self.actionName:
action.name = self.actionName
else:
if self.headers[0].name:
action.name = toAlnum(self.headers[0].name)
if remove_name_footer and self.headers[0].name.startswith("anim_"):
action.name = self.headers[0].name.replace("anim_", "", 1)
else:
action.name = self.headers[0].name
else:
action.name = hex(self.headers[0].address)
self.actionName = action.name

if self.fileName:
action_props.customFileName = self.fileName
action_props.overrideFileName = True
if action_props.get_anim_file_name(action) != self.fileName:
action_props.overrideFileName = True

action_props.indicesTable, action_props.indicesAddress = self.indicesReference, self.indicesReference
action_props.valuesTable, action_props.valueAddress = self.valuesReference, self.valuesReference
Expand Down
Loading

0 comments on commit 857347b

Please sign in to comment.