diff --git a/fast64_internal/z64/exporter/scene/actors.py b/fast64_internal/z64/exporter/scene/actors.py index ba4f2f6d8..7dd3cd0a7 100644 --- a/fast64_internal/z64/exporter/scene/actors.py +++ b/fast64_internal/z64/exporter/scene/actors.py @@ -41,6 +41,26 @@ def getEntryC(self): ) +def split_c_on_commas(s: str): + parts: list[str] = [] + part = "" + parens_depth = 0 + for c in s: + if c == "(": + parens_depth += 1 + if c == ")": + parens_depth -= 1 + if parens_depth < 0: + parens_depth = 0 + if c == "," and parens_depth == 0: + parts.append(part) + part = "" + else: + part += c + parts.append(part) + return parts + + @dataclass class SceneTransitionActors: name: str @@ -116,14 +136,14 @@ def from_data(raw_data: str, not_zapd_assets: bool): if entry == "": continue - params = entry.replace("{", "").replace("}", "").split(",") + params = split_c_on_commas(entry.replace("{", "").replace("}", "")) # trailing commas for p in params: if p == "": params.remove(p) - assert len(params) == 10 + assert len(params) == 10, entry trans_actor = TransitionActor() trans_actor.name = "(unset)" trans_actor.id = params[4] diff --git a/fast64_internal/z64/importer/actor.py b/fast64_internal/z64/importer/actor.py index 505510b72..af1f09751 100644 --- a/fast64_internal/z64/importer/actor.py +++ b/fast64_internal/z64/importer/actor.py @@ -1,4 +1,5 @@ import re +import traceback import bpy from ...utility import parentObject, hexOrDecInt @@ -19,6 +20,21 @@ ) +def set_actor_params(actorProp, actor_id, actor_params): + if actorProp.actor_id != "Custom": + try: + actorProp.set_param_value(actor_params, "Params") + except: + print("Failed to parse params " + actor_params + " for actor " + actor_id + ":") + traceback.print_exc() + print("Defaulting to custom") + actorProp.actor_id = "Custom" + actorProp.actor_id_custom = actor_id + actorProp.params_custom = actor_params + else: + actorProp.params_custom = actor_params + + def parseTransActorList( roomObjs: list[bpy.types.Object], sceneData: str, @@ -66,10 +82,7 @@ def parseTransActorList( actorProp = transActorProp.actor setCustomProperty(actorProp, "actor_id", actor.id, game_data.z64.actors.ootEnumActorID) - if actorProp.actor_id != "Custom": - actorProp.params = actor.params - else: - actorProp.params_custom = actor.params + set_actor_params(actorProp, actor.id, actor.params) handleActorWithRotAsParam(actorProp, actor.id, rotation) unsetAllHeadersExceptSpecified(actorProp.headerSettings, headerIndex) @@ -147,10 +160,7 @@ def parseSpawnList( spawnProp.customActor = actorID != "ACTOR_PLAYER" actorProp = spawnProp.actor setCustomProperty(actorProp, "actor_id", actorID, game_data.z64.actors.ootEnumActorID) - if actorProp.actor_id != "Custom": - actorProp.params = actorParam - else: - actorProp.params_custom = actorParam + set_actor_params(actorProp, actorID, actorParam) handleActorWithRotAsParam(actorProp, actorID, rotation) unsetAllHeadersExceptSpecified(actorProp.headerSettings, headerIndex) @@ -188,10 +198,7 @@ def parseActorList( actorProp = actorObj.ootActorProperty setCustomProperty(actorProp, "actor_id", actorID, game_data.z64.actors.ootEnumActorID) - if actorProp.actor_id != "Custom": - actorProp.params = actorParam - else: - actorProp.params_custom = actorParam + set_actor_params(actorProp, actorID, actorParam) handleActorWithRotAsParam(actorProp, actorID, rotation) unsetAllHeadersExceptSpecified(actorProp.headerSettings, headerIndex) diff --git a/fast64_internal/z64/utility.py b/fast64_internal/z64/utility.py index da7bd8719..76159807b 100644 --- a/fast64_internal/z64/utility.py +++ b/fast64_internal/z64/utility.py @@ -845,7 +845,9 @@ def _eval(node) -> int: try: return _eval(node.body) except: - print("WARNING: something wrong happened:", traceback.print_exc()) + print("WARNING: something wrong happened:") + print("input:", input) + traceback.print_exc() return None