Browse Source

LOGICWIZ: don't leave junk node trees behind

pull/133/head
Adam Johnson 6 years ago
parent
commit
8dff482789
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 10
      korman/properties/modifiers/avatar.py
  2. 19
      korman/properties/modifiers/base.py
  3. 10
      korman/properties/modifiers/gui.py
  4. 11
      korman/properties/modifiers/region.py

10
korman/properties/modifiers/avatar.py

@ -127,20 +127,16 @@ class PlasmaSittingBehavior(idprops.IDPropObjectMixin, PlasmaModifierProperties,
raise ExportError("'{}': Sitting Behavior's clickable object is invalid".format(self.key_name))
# Generate the logic nodes now
self.logicwiz(bo)
# Now, export the node tree
self.node_tree.export(exporter, bo, so)
with self.generate_logic(bo) as tree:
tree.export(exporter, bo, so)
def harvest_actors(self):
if self.facing_enabled:
return (self.clickable_object.name,)
return ()
def logicwiz(self, bo):
tree = self.node_tree
def logicwiz(self, bo, tree):
nodes = tree.nodes
nodes.clear()
# Sitting Modifier
sittingmod = nodes.new("PlasmaSittingBehaviorNode")

19
korman/properties/modifiers/base.py

@ -16,6 +16,7 @@
import abc
import bpy
from bpy.props import *
from contextlib import contextmanager
class PlasmaModifierProperties(bpy.types.PropertyGroup):
def created(self):
@ -70,16 +71,20 @@ class PlasmaModifierProperties(bpy.types.PropertyGroup):
class PlasmaModifierLogicWiz:
@property
def node_tree(self):
name = self.key_name
@contextmanager
def generate_logic(self, bo, **kwargs):
name = kwargs.pop("name", self.key_name)
assert not "tree" in kwargs
tree = bpy.data.node_groups.new(name, "PlasmaNodeTree")
kwargs["tree"] = tree
try:
return bpy.data.node_groups[name]
except LookupError:
return bpy.data.node_groups.new(name, "PlasmaNodeTree")
self.logicwiz(bo, **kwargs)
yield tree
finally:
bpy.data.node_groups.remove(tree)
@abc.abstractmethod
def logicwiz(self, bo):
def logicwiz(self, bo, tree):
pass

10
korman/properties/modifiers/gui.py

@ -163,19 +163,15 @@ class PlasmaJournalBookModifier(PlasmaModifierProperties, PlasmaModifierLogicWiz
self.temp_rgn = self.clickable_region
# Generate the logic nodes
self.logicwiz(bo, version)
# Export the node tree
self.node_tree.export(exporter, bo, so)
with self.generate_logic(bo, version=version) as tree:
tree.export(exporter, bo, so)
# Get rid of our temporary clickable region
if self.clickable_region is None:
bpy.context.scene.objects.unlink(self.temp_rgn)
def logicwiz(self, bo, version):
tree = self.node_tree
def logicwiz(self, bo, tree, version):
nodes = tree.nodes
nodes.clear()
# Assign journal script based on target version
journal_pfm = journal_pfms[version]

11
korman/properties/modifiers/region.py

@ -140,16 +140,11 @@ class PlasmaFootstepRegion(PlasmaModifierProperties, PlasmaModifierLogicWiz):
default="hull")
def export(self, exporter, bo, so):
# Generate the logic nodes now
self.logicwiz(bo)
# Now, export the node tree
self.node_tree.export(exporter, bo, so)
with self.generate_logic(bo) as tree:
tree.export(exporter, bo, so)
def logicwiz(self, bo):
tree = self.node_tree
def logicwiz(self, bo, tree):
nodes = tree.nodes
nodes.clear()
# Region Sensor
volsens = nodes.new("PlasmaVolumeSensorNode")

Loading…
Cancel
Save