From 3939f6e64252a3a0ac65c2002f89baecc79ac443 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 22 Feb 2025 19:18:37 -0500 Subject: [PATCH] Convert xSitCam.py to regular engine features. Using standard engine features should make the Ages generated by Korman more robust. Also, any time we can avoid calling into Python, that's a performance win. --- korman/properties/modifiers/avatar.py | 25 ++++++++++++++------- korman/properties/modifiers/base.py | 31 +++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/korman/properties/modifiers/avatar.py b/korman/properties/modifiers/avatar.py index bbd0bc9..99aebcd 100644 --- a/korman/properties/modifiers/avatar.py +++ b/korman/properties/modifiers/avatar.py @@ -128,15 +128,24 @@ class PlasmaSittingBehavior(idprops.IDPropObjectMixin, PlasmaModifierProperties, sittingmod = nodes.new("PlasmaSittingBehaviorNode") sittingmod.approach = self.approach sittingmod.name = "SittingBeh" - # xSitCam.py PythonFileMod - if self.sitting_camera is not None: - sittingpynode = self._create_python_standard_file_node(tree, "xSitCam.py") - sittingmod.link_output(sittingpynode, "satisfies", "sitAct") - # Camera Object - cameraobj = nodes.new("PlasmaAttribObjectNode") - cameraobj.link_output(sittingpynode, "pfm", "sitCam") - cameraobj.target_object = self.sitting_camera + # Sitting Camera handling + if self.sitting_camera is not None: + sitDownRespNode = self._create_responder_nodes( + tree, + ("PlasmaCameraMsgNode", { "camera": self.sitting_camera, "cmd": "push" }), + detect_trigger=True, detect_untrigger=False, + name="SitDown" + ) + standUpRespNode = self._create_responder_nodes( + tree, + ("PlasmaCameraMsgNode", { "camera": self.sitting_camera, "cmd": "pop" }), + detect_trigger=False, detect_untrigger=True, + name="StandUp" + ) + + sittingmod.link_output(sitDownRespNode, "satisfies", "condition") + sittingmod.link_output(standUpRespNode, "satisfies", "condition") # Clickable clickable = nodes.new("PlasmaClickableNode") diff --git a/korman/properties/modifiers/base.py b/korman/properties/modifiers/base.py index 5fee595..e589c21 100644 --- a/korman/properties/modifiers/base.py +++ b/korman/properties/modifiers/base.py @@ -24,6 +24,7 @@ from typing import * if TYPE_CHECKING: from ...nodes.node_python import * + from ...nodes.node_responder import * from ... import helpers from ... import plasma_api @@ -237,6 +238,36 @@ class PlasmaModifierLogicWiz: setattr(node, i, j) return node + def _create_responder_nodes( + self, tree: bpy.types.NodeGroup, + *messages: Tuple[str, Dict[str, Any]], + **responder_settings + ) -> PlasmaResponderNode: + """Creates and links together a Responder node tree. Each message sould be specified by a tuple + of string message type and a dict of attributes to set on the message node. Messages will be + created and linked in the order they are specified, including any callback waits if needed. + Attributes on the responder node can be set by passing them in as keyword arguments. + """ + + nodes = tree.nodes + respNode = nodes.new("PlasmaResponderNode") + for attr, value in responder_settings.items(): + setattr(respNode, attr, value) + respStateNode = nodes.new("PlasmaResponderStateNode") + respNode.link_output(respStateNode, "state_refs", "resp") + + linkMsgTo = respStateNode + for msgNodeType, msgNodeAttrs in messages: + msgNode = nodes.new(msgNodeType) + for attr, value in msgNodeAttrs.items(): + setattr(msgNode, attr, value) + + linkMsgTo.link_output(msgNode, "msgs", "sender") + if msgNode.has_callbacks and msgNode.can_link_callbacks: + linkMsgTo = msgNode + + return respNode + @abc.abstractmethod def logicwiz(self, bo, tree): pass