From 7e2cd66ffdc7c2174e54cfcbb15618a6e5ad4403 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Thu, 24 Oct 2019 20:05:17 -0400 Subject: [PATCH] More actor harvesting fixes. Apparently, I forgot about the `requires_actor` property. Oops! That has been corrected along with an oversight in the PythonFileMod nodes. --- korman/nodes/node_avatar.py | 4 ++++ korman/nodes/node_conditions.py | 14 +++++++------- korman/nodes/node_core.py | 10 +++++++--- korman/nodes/node_logic.py | 4 ++-- korman/nodes/node_messages.py | 12 ++++++------ korman/nodes/node_python.py | 19 +++++++++++-------- korman/properties/modifiers/logic.py | 6 +++++- korman/properties/modifiers/region.py | 5 ++++- 8 files changed, 46 insertions(+), 28 deletions(-) diff --git a/korman/nodes/node_avatar.py b/korman/nodes/node_avatar.py index 22deeb4..d9a6ec0 100644 --- a/korman/nodes/node_avatar.py +++ b/korman/nodes/node_avatar.py @@ -67,3 +67,7 @@ class PlasmaSittingBehaviorNode(PlasmaNodeBase, bpy.types.Node): sitmod.addNotifyKey(i.get_key(exporter, so)) else: exporter.report.warn("'{}' Node '{}' doesn't expose a key. It won't be triggered by '{}'!".format(i.bl_idname, i.name, self.name), indent=3) + + @property + def requires_actor(self): + return True diff --git a/korman/nodes/node_conditions.py b/korman/nodes/node_conditions.py index 90f741f..9a9de9d 100644 --- a/korman/nodes/node_conditions.py +++ b/korman/nodes/node_conditions.py @@ -144,13 +144,13 @@ class PlasmaClickableNode(idprops.IDPropObjectMixin, PlasmaNodeBase, bpy.types.N else: return (None, parent_so) - def harvest_actors(self, bo): - actors = set() - if self.clickable_object is not None: - actors.add(self.clickable_object.name) - else: - actors.add(bo.name) - return actors + def harvest_actors(self): + if self.clickable_object: + yield self.clickable_object.name + + @property + def requires_actor(self): + return self.clickable_object is None @classmethod def _idprop_mapping(cls): diff --git a/korman/nodes/node_core.py b/korman/nodes/node_core.py index 073ad65..2f42055 100644 --- a/korman/nodes/node_core.py +++ b/korman/nodes/node_core.py @@ -220,7 +220,7 @@ class PlasmaNodeBase: """Generates valid sockets on this node type that can be linked to a specific node's socket.""" return [] - def harvest_actors(self, bo): + def harvest_actors(self): return set() def link_input(self, node, out_key, in_key): @@ -466,12 +466,12 @@ class PlasmaNodeTree(bpy.types.NodeTree): return node return None - def harvest_actors(self, bo): + def harvest_actors(self): actors = set() for node in self.nodes: harvest_method = getattr(node, "harvest_actors", None) if harvest_method is not None: - actors.update(harvest_method(bo)) + actors.update(harvest_method()) elif not isinstance(node, PlasmaNodeBase): raise ExportError("Plasma Node Tree '{}' Node '{}': is not a valid node for this tree".format(self.id_data.name, node.name)) return actors @@ -480,6 +480,10 @@ class PlasmaNodeTree(bpy.types.NodeTree): def poll(cls, context): return (context.scene.render.engine == "PLASMA_GAME") + @property + def requires_actor(self): + return any((node.requires_actor for node in self.nodes)) + # Welcome to HAXland! # Blender 2.79 is great in that it allows us to have ID Datablock pointer properties everywhere. diff --git a/korman/nodes/node_logic.py b/korman/nodes/node_logic.py index 27804a2..fb4de56 100644 --- a/korman/nodes/node_logic.py +++ b/korman/nodes/node_logic.py @@ -84,8 +84,8 @@ class PlasmaExcludeRegionNode(idprops.IDPropObjectMixin, PlasmaNodeBase, bpy.typ self.raise_error("Region must be set") return self._find_create_key(plExcludeRegionModifier, exporter, bl=self.region_object) - def harvest_actors(self, bo): - return [i.safepoint.name for i in self.find_input_sockets("safe_points") if i.safepoint is not None] + def harvest_actors(self): + return (i.safepoint.name for i in self.find_input_sockets("safe_points") if i.safepoint is not None) def export(self, exporter, bo, parent_so): excludergn = self.get_key(exporter, parent_so).object diff --git a/korman/nodes/node_messages.py b/korman/nodes/node_messages.py index 3e6ad30..a6862ce 100644 --- a/korman/nodes/node_messages.py +++ b/korman/nodes/node_messages.py @@ -561,18 +561,18 @@ class PlasmaOneShotMsgNode(idprops.IDPropObjectMixin, PlasmaMessageWithCallbacks else: return self._find_create_key(plOneShotMod, exporter, so=so) - def harvest_actors(self, bo): - actors = set() + def harvest_actors(self): if self.pos_object: - actors.add(self.pos_object.name) - else: - actors.add(bo.name) - return actors + yield self.pos_object.name @property def has_callbacks(self): return bool(self.marker) + @property + def requires_actor(self): + return self.pos_object is None + @classmethod def _idprop_mapping(cls): return {"pos_object": "pos"} diff --git a/korman/nodes/node_python.py b/korman/nodes/node_python.py index cc58c5c..88521f5 100644 --- a/korman/nodes/node_python.py +++ b/korman/nodes/node_python.py @@ -394,14 +394,13 @@ class PlasmaPythonFileNode(PlasmaVersionedNode, bpy.types.Node): "socket_name": attrib["name"], "socket_text": attrib["name"] } - def harvest_actors(self, bo): - actors = set() - actors.add(bo.name) - - so_nodes = (i.links[0].from_node for i in self.inputs - if i.is_linked and i.attribute_type in {"ptAttribSceneobject", "ptAttribSceneobjectList"}) - actors.update((i.target_object for i in so_nodes if i.target_object is not None)) - return actors + def harvest_actors(self): + for i in self.inputs: + if not i.is_linked or i.attribute_type not in {"ptAttribSceneobject", "ptAttribSceneobjectList"}: + continue + node = i.links[0].from_node + if node.target_object is not None: + yield node.target_object.name @property def key_name(self): @@ -422,6 +421,10 @@ class PlasmaPythonFileNode(PlasmaVersionedNode, bpy.types.Node): if not is_init and new_pos != old_pos: self.inputs.move(old_pos, new_pos) + @property + def requires_actor(self): + return True + @contextmanager def NoUpdate(self): self.no_update = True diff --git a/korman/properties/modifiers/logic.py b/korman/properties/modifiers/logic.py index a37faf1..f31ed1a 100644 --- a/korman/properties/modifiers/logic.py +++ b/korman/properties/modifiers/logic.py @@ -66,9 +66,13 @@ class PlasmaAdvancedLogic(PlasmaModifierProperties): actors = set() for i in self.logic_groups: if i.node_tree is not None: - actors.update(i.node_tree.harvest_actors(self.id_data)) + actors.update(i.node_tree.harvest_actors()) return actors + @property + def requires_actor(self): + return any((i.node_tree.requires_actor for i in self.logic_groups if i.node_tree)) + class PlasmaSpawnPoint(PlasmaModifierProperties): pl_id = "spawnpoint" diff --git a/korman/properties/modifiers/region.py b/korman/properties/modifiers/region.py index e45a59e..aa84f45 100644 --- a/korman/properties/modifiers/region.py +++ b/korman/properties/modifiers/region.py @@ -120,10 +120,13 @@ class PlasmaCameraRegion(PlasmaModifierProperties): raise ExportError("Camera Modifier '{}' does not specify a valid camera object".format(self.id_data.name)) actors.update(self.camera_object.data.plasma_camera.settings.harvest_actors()) else: - actors.add(self.id_data.name) actors.update(self.auto_camera.harvest_actors()) return actors + @property + def requires_actor(self): + return self.camera_type == "auto_follow" + class PlasmaFootstepRegion(PlasmaModifierProperties, PlasmaModifierLogicWiz): pl_id = "footstep"