Browse Source

Merge pull request #121 from Hoikas/mod-versions

Modifier Upgrading
pull/122/head
Adam Johnson 6 years ago committed by GitHub
parent
commit
a672db70a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      korman/nodes/node_deprecated.py
  2. 4
      korman/nodes/node_responder.py
  3. 6
      korman/properties/modifiers/__init__.py
  4. 55
      korman/properties/modifiers/base.py
  5. 2
      korman/properties/modifiers/render.py

13
korman/nodes/node_deprecated.py

@ -13,6 +13,7 @@
# You should have received a copy of the GNU General Public License
# along with Korman. If not, see <http://www.gnu.org/licenses/>.
import abc
import bpy
from bpy.props import *
from collections import OrderedDict
@ -20,16 +21,26 @@ from collections import OrderedDict
from .node_core import *
class PlasmaDeprecatedNode(PlasmaNodeBase):
@abc.abstractmethod
def upgrade(self):
raise NotImplementedError()
class PlasmaVersionedNode(PlasmaNodeBase):
def init(self, context):
self.version = self.latest_version
@property
@abc.abstractmethod
def latest_version(self):
raise NotImplementedError()
@classmethod
def register(cls):
cls.version = IntProperty(name="Node Version", default=1, options=set())
def upgrade(self, from_version):
@abc.abstractmethod
def upgrade(self):
raise NotImplementedError()

4
korman/nodes/node_responder.py

@ -135,6 +135,10 @@ class PlasmaResponderNode(PlasmaVersionedNode, bpy.types.Node):
stateMgr.register_state(stateNode)
stateMgr.convert_states(exporter, so)
@property
def latest_version(self):
return 2
def upgrade(self):
# In version 1 responder nodes, responder states could be linked to the responder
# or to subsequent responder state nodes and be exported. The problem with this

6
korman/properties/modifiers/__init__.py

@ -88,8 +88,6 @@ def modifier_mapping():
label = label[:-len(category)-1]
tup = (pl_id, label, description, icon, i)
if category not in d:
d[category] = [tup]
else:
d[category].append(tup)
d_cat = d.setdefault(category, [])
d_cat.append(tup)
return d

55
korman/properties/modifiers/base.py

@ -62,7 +62,10 @@ class PlasmaModifierProperties(bpy.types.PropertyGroup):
"options": {"HIDDEN"}}),
"show_expanded": (BoolProperty, {"name": "INTERNAL: Actually draw the modifier",
"default": True,
"options": {"HIDDEN"}})
"options": {"HIDDEN"}}),
"current_version": (IntProperty, {"name": "INTERNAL: Modifier version",
"default": 1,
"options": {"HIDDEN"}}),
}
@ -78,3 +81,53 @@ class PlasmaModifierLogicWiz:
@abc.abstractmethod
def logicwiz(self, bo):
pass
class PlasmaModifierUpgradable:
@property
@abc.abstractmethod
def latest_version(self):
raise NotImplementedError()
@property
def requires_upgrade(self):
current_version, latest_version = self.current_version, self.latest_version
assert current_version < latest_version
return current_version < latest_version
@abc.abstractmethod
def upgrade(self):
raise NotImplementedError()
@bpy.app.handlers.persistent
def _restore_properties(dummy):
# When Blender opens, it loads the default blend. The post load handler
# below is executed and deprecated properties are unregistered. When the
# user goes to load a new blend file, the handler below tries to execute
# again and BOOM--there are no deprecated properties available. Therefore,
# we reregister them here.
for mod_cls in PlasmaModifierUpgradable.__subclasses__():
for prop_name in mod_cls.deprecated_properties:
# Unregistered propertes are a sequence of (property function,
# property keyword arguments). Interesting design decision :)
prop_cb, prop_kwargs = getattr(mod_cls, prop_name)
del prop_kwargs["attr"] # Prevents proper registration
setattr(mod_cls, prop_name, prop_cb(**prop_kwargs))
bpy.app.handlers.load_pre.append(_restore_properties)
@bpy.app.handlers.persistent
def _upgrade_modifiers(dummy):
# First, run all the upgrades
for i in bpy.data.objects:
for mod_cls in PlasmaModifierUpgradable.__subclasses__():
mod = getattr(i.plasma_modifiers, mod_cls.pl_id)
if mod.requires_upgrade:
mod.upgrade()
# Now that everything is upgraded, forcibly remove all properties
# from the modifiers to prevent sneaky zombie-data type export bugs
for mod_cls in PlasmaModifierUpgradable.__subclasses__():
for prop in mod_cls.deprecated_properties:
RemoveProperty(mod_cls, attr=prop)
bpy.app.handlers.load_post.append(_upgrade_modifiers)

2
korman/properties/modifiers/render.py

@ -18,7 +18,7 @@ import bpy
from bpy.props import *
from PyHSPlasma import *
from .base import PlasmaModifierProperties
from .base import PlasmaModifierProperties, PlasmaModifierUpgradable
from ...exporter.etlight import _NUM_RENDER_LAYERS
from ...exporter import utils
from ...exporter.explosions import ExportError

Loading…
Cancel
Save