Skip to content

Commit

Permalink
fix cs import issues (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanis42 authored May 22, 2024
1 parent e4aff74 commit a7257f4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
9 changes: 6 additions & 3 deletions fast64_internal/oot/cutscene/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __post_init__(self):
class CutsceneCmdActorCue(CutsceneCmdBase):
"""This class contains a single Actor Cue command data"""

actionID: Optional[int] = None
actionID: Optional[int | str] = None
rot: list[str] = field(default_factory=list)
startPos: list[int] = field(default_factory=list)
endPos: list[int] = field(default_factory=list)
Expand All @@ -69,7 +69,10 @@ def __post_init__(self):
if self.params is not None:
self.startFrame = getInteger(self.params[1])
self.endFrame = getInteger(self.params[2])
self.actionID = getInteger(self.params[0])
try:
self.actionID = getInteger(self.params[0])
except ValueError:
self.actionID = self.params[0]
self.rot = [getRotation(self.params[3]), getRotation(self.params[4]), getRotation(self.params[5])]
self.startPos = [getInteger(self.params[6]), getInteger(self.params[7]), getInteger(self.params[8])]
self.endPos = [getInteger(self.params[9]), getInteger(self.params[10]), getInteger(self.params[11])]
Expand Down Expand Up @@ -302,7 +305,7 @@ class CutsceneCmdLightSetting(CutsceneCmdBase):

isLegacy: Optional[bool] = None
lightSetting: Optional[int] = None
paramNumber: int = 11
paramNumber: int = 14

def __post_init__(self):
if self.params is not None:
Expand Down
19 changes: 14 additions & 5 deletions fast64_internal/oot/cutscene/importer/classes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import bpy
import re

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

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

fileLines: list[str] = []
for line in fileData.split("\n"):
fileLines.append(line.strip())

# parse cutscenes
fileLines = fileData.split("\n")
csData = []
cutsceneList: list[list[str]] = []
foundCutscene = False
Expand All @@ -98,10 +106,11 @@ def getParsedCutscenes(self):

if foundCutscene:
sLine = line.strip()
if not sLine.endswith("),") and sLine.endswith(","):
line += fileLines[fileLines.index(line) + 1].strip()
csCmd = sLine.split("(")[0]
if "CutsceneData " not in line and "};" not in line and csCmd not in ootCutsceneCommandsC:
csData[-1] += line

if len(csData) == 0 or "CS_" in line:
if len(csData) == 0 or sLine.startswith("CS_") and not sLine.startswith("CS_FLOAT"):
csData.append(line)

if "};" in line:
Expand Down

0 comments on commit a7257f4

Please sign in to comment.