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)) raise ExportError("'{}': Sitting Behavior's clickable object is invalid".format(self.key_name))
# Generate the logic nodes now # Generate the logic nodes now
self.logicwiz(bo) with self.generate_logic(bo) as tree:
tree.export(exporter, bo, so)
# Now, export the node tree
self.node_tree.export(exporter, bo, so)
def harvest_actors(self): def harvest_actors(self):
if self.facing_enabled: if self.facing_enabled:
return (self.clickable_object.name,) return (self.clickable_object.name,)
return () return ()
def logicwiz(self, bo): def logicwiz(self, bo, tree):
tree = self.node_tree
nodes = tree.nodes nodes = tree.nodes
nodes.clear()
# Sitting Modifier # Sitting Modifier
sittingmod = nodes.new("PlasmaSittingBehaviorNode") sittingmod = nodes.new("PlasmaSittingBehaviorNode")

19
korman/properties/modifiers/base.py

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

10
korman/properties/modifiers/gui.py

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

11
korman/properties/modifiers/region.py

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

Loading…
Cancel
Save