Skip to content

Commit a7257f4

Browse files
authored
fix cs import issues (#343)
1 parent e4aff74 commit a7257f4

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

fast64_internal/oot/cutscene/classes.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __post_init__(self):
5959
class CutsceneCmdActorCue(CutsceneCmdBase):
6060
"""This class contains a single Actor Cue command data"""
6161

62-
actionID: Optional[int] = None
62+
actionID: Optional[int | str] = None
6363
rot: list[str] = field(default_factory=list)
6464
startPos: list[int] = field(default_factory=list)
6565
endPos: list[int] = field(default_factory=list)
@@ -69,7 +69,10 @@ def __post_init__(self):
6969
if self.params is not None:
7070
self.startFrame = getInteger(self.params[1])
7171
self.endFrame = getInteger(self.params[2])
72-
self.actionID = getInteger(self.params[0])
72+
try:
73+
self.actionID = getInteger(self.params[0])
74+
except ValueError:
75+
self.actionID = self.params[0]
7376
self.rot = [getRotation(self.params[3]), getRotation(self.params[4]), getRotation(self.params[5])]
7477
self.startPos = [getInteger(self.params[6]), getInteger(self.params[7]), getInteger(self.params[8])]
7578
self.endPos = [getInteger(self.params[9]), getInteger(self.params[10]), getInteger(self.params[11])]
@@ -302,7 +305,7 @@ class CutsceneCmdLightSetting(CutsceneCmdBase):
302305

303306
isLegacy: Optional[bool] = None
304307
lightSetting: Optional[int] = None
305-
paramNumber: int = 11
308+
paramNumber: int = 14
306309

307310
def __post_init__(self):
308311
if self.params is not None:

fast64_internal/oot/cutscene/importer/classes.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import bpy
2+
import re
23

34
from dataclasses import dataclass
45
from typing import TYPE_CHECKING
@@ -53,7 +54,11 @@ def getCmdParams(self, data: str, cmdName: str, paramNumber: int):
5354
"""Returns the list of every parameter of the given command"""
5455

5556
parenthesis = "(" if not cmdName.endswith("(") else ""
56-
params = data.strip().removeprefix(f"{cmdName}{parenthesis}").replace(" ", "").removesuffix(")").split(",")
57+
data = data.strip().removeprefix(f"{cmdName}{parenthesis}").replace(" ", "").removesuffix(")")
58+
if "CS_FLOAT" in data:
59+
data = re.sub(r"CS_FLOAT\([a-fA-F0-9x]*,([0-9e+-.f]*)\)", r"\1", data, re.DOTALL)
60+
data = re.sub(r"CS_FLOAT\([a-fA-F0-9x]*,([0-9e+-.f]*)", r"\1", data, re.DOTALL)
61+
params = data.split(",")
5762
validTimeCmd = cmdName == "CS_TIME" and len(params) == 6 and paramNumber == 5
5863
if len(params) != paramNumber and not validTimeCmd:
5964
raise PluginError(
@@ -86,8 +91,11 @@ def getParsedCutscenes(self):
8691
for oldName in oldNames:
8792
fileData = fileData.replace(f"{oldName}(", f"{ootCSLegacyToNewCmdNames[oldName]}(")
8893

94+
fileLines: list[str] = []
95+
for line in fileData.split("\n"):
96+
fileLines.append(line.strip())
97+
8998
# parse cutscenes
90-
fileLines = fileData.split("\n")
9199
csData = []
92100
cutsceneList: list[list[str]] = []
93101
foundCutscene = False
@@ -98,10 +106,11 @@ def getParsedCutscenes(self):
98106

99107
if foundCutscene:
100108
sLine = line.strip()
101-
if not sLine.endswith("),") and sLine.endswith(","):
102-
line += fileLines[fileLines.index(line) + 1].strip()
109+
csCmd = sLine.split("(")[0]
110+
if "CutsceneData " not in line and "};" not in line and csCmd not in ootCutsceneCommandsC:
111+
csData[-1] += line
103112

104-
if len(csData) == 0 or "CS_" in line:
113+
if len(csData) == 0 or sLine.startswith("CS_") and not sLine.startswith("CS_FLOAT"):
105114
csData.append(line)
106115

107116
if "};" in line:

0 commit comments

Comments
 (0)