Browse Source

Limit all SceneObjects to valid Python 2 identifiers.

In Path of the Shell, the entire tree from plSceneObject to
plPythonFileMod MUST be a valid identifier, otherwise, a SystemError is
raised.
pull/190/head
Adam Johnson 4 years ago
parent
commit
e576bab339
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 14
      korman/exporter/manager.py
  2. 3
      korman/nodes/node_core.py

14
korman/exporter/manager.py

@ -19,7 +19,7 @@ from PyHSPlasma import *
import weakref import weakref
from . import explosions from . import explosions
from .. import korlib from ..korlib import replace_python2_identifier
from ..plasma_magic import * from ..plasma_magic import *
# These objects have to be in the plSceneNode pool in order to be loaded... # These objects have to be in the plSceneNode pool in order to be loaded...
@ -93,7 +93,7 @@ class ExportManager:
else: else:
name = so.key.name name = so.key.name
assert issubclass(pl, hsKeyedObject) assert issubclass(pl, hsKeyedObject)
pl = pl(name) pl = pl(self._fixup_key_name(pl, name))
self.AddObject(location, pl) self.AddObject(location, pl)
node = self._nodes[location] node = self._nodes[location]
@ -145,7 +145,7 @@ class ExportManager:
self._pack_agesdl_hook(age) self._pack_agesdl_hook(age)
sdl = self.add_object(plSceneObject, name="AgeSDLHook", loc=builtin) sdl = self.add_object(plSceneObject, name="AgeSDLHook", loc=builtin)
pfm = self.add_object(plPythonFileMod, name="VeryVerySpecialPythonFileMod", so=sdl) pfm = self.add_object(plPythonFileMod, name="VeryVerySpecialPythonFileMod", so=sdl)
pfm.filename = korlib.replace_python2_identifier(age) pfm.filename = replace_python2_identifier(age)
# Textures.prp # Textures.prp
# FIXME: unconditional creation will overwrite any existing textures PRP. This should # FIXME: unconditional creation will overwrite any existing textures PRP. This should
@ -212,6 +212,7 @@ class ExportManager:
name = bl.name name = bl.name
else: else:
name = so.key.name name = so.key.name
name = self._fixup_key_name(pClass, name)
key = self._keys.get((location, pClass, name), None) key = self._keys.get((location, pClass, name), None)
if key is not None and so is not None: if key is not None and so is not None:
@ -239,6 +240,11 @@ class ExportManager:
return key.object return key.object
return None return None
def _fixup_key_name(self, pClass, name):
if pClass in {plSceneObject, plPythonFileMod}:
return replace_python2_identifier(name)
return name
def get_location(self, bl): def get_location(self, bl):
"""Returns the Page Location of a given Blender Object""" """Returns the Page Location of a given Blender Object"""
return self._pages[bl.plasma_object.page] return self._pages[bl.plasma_object.page]
@ -271,7 +277,7 @@ class ExportManager:
return result return result
# AgeSDL Hook Python # AgeSDL Hook Python
fixed_agename = korlib.replace_python2_identifier(age) fixed_agename = replace_python2_identifier(age)
py_filename = "{}.py".format(fixed_agename) py_filename = "{}.py".format(fixed_agename)
age_py = get_text(py_filename) age_py = get_text(py_filename)
if output.want_py_text(age_py): if output.want_py_text(age_py):

3
korman/nodes/node_core.py

@ -20,7 +20,6 @@ from PyHSPlasma import *
import time import time
from ..exporter import ExportError from ..exporter import ExportError
from ..korlib import replace_python2_identifier
class PlasmaNodeBase: class PlasmaNodeBase:
def generate_notify_msg(self, exporter, so, socket_id, idname=None): def generate_notify_msg(self, exporter, so, socket_id, idname=None):
@ -53,7 +52,7 @@ class PlasmaNodeBase:
working_name = "{}_{}_{}".format(self.id_data.name, self.name, suffix) working_name = "{}_{}_{}".format(self.id_data.name, self.name, suffix)
else: else:
working_name = "{}_{}".format(self.id_data.name, self.name) working_name = "{}_{}".format(self.id_data.name, self.name)
return replace_python2_identifier(working_name) return working_name
def draw_label(self): def draw_label(self):
if hasattr(self, "pl_label_attr") and self.hide: if hasattr(self, "pl_label_attr") and self.hide:

Loading…
Cancel
Save