diff --git a/korman/properties/modifiers/base.py b/korman/properties/modifiers/base.py index 35bf255..388e4e8 100644 --- a/korman/properties/modifiers/base.py +++ b/korman/properties/modifiers/base.py @@ -17,7 +17,7 @@ import bpy from bpy.props import * import abc -from typing import Generator +from typing import Any, Dict, Generator class PlasmaModifierProperties(bpy.types.PropertyGroup): @property @@ -128,6 +128,18 @@ class PlasmaModifierLogicWiz: else: return tree + def _create_python_file_node(self, tree, filename: str, attributes: Dict[str, Any]) -> bpy.types.Node: + pfm_node = tree.nodes.new("PlasmaPythonFileNode") + with pfm_node.NoUpdate(): + pfm_node.filename = filename + for attr in attributes: + new_attr = pfm_node.attributes.add() + new_attr.attribute_id = attr["id"] + new_attr.attribute_type = attr["type"] + new_attr.attribute_name = attr["name"] + pfm_node.update() + return pfm_node + @abc.abstractmethod def logicwiz(self, bo, tree): pass diff --git a/korman/properties/modifiers/gui.py b/korman/properties/modifiers/gui.py index 9c6f93f..164405e 100644 --- a/korman/properties/modifiers/gui.py +++ b/korman/properties/modifiers/gui.py @@ -230,27 +230,13 @@ class PlasmaJournalBookModifier(PlasmaModifierProperties, PlasmaModifierLogicWiz yield self.convert_logic(bo, age_name=exporter.age_name, rgn_obj=rgn_obj, version=version) def logicwiz(self, bo, tree, age_name, rgn_obj, version): - nodes = tree.nodes - # Assign journal script based on target version journal_pfm = journal_pfms[version] - journalnode = nodes.new("PlasmaPythonFileNode") - with journalnode.NoUpdate(): - journalnode.filename = journal_pfm["filename"] - - # Manually add required attributes to the PFM - journal_attribs = journal_pfm["attribs"] - for attr in journal_attribs: - new_attr = journalnode.attributes.add() - new_attr.attribute_id = attr["id"] - new_attr.attribute_type = attr["type"] - new_attr.attribute_name = attr["name"] - journalnode.update() - + journalnode = self._create_python_file_node(tree, journal_pfm["filename"], journal_pfm["attribs"]) if version <= pvPots: - self._create_pots_nodes(bo, nodes, journalnode, age_name, rgn_obj) + self._create_pots_nodes(bo, tree.nodes, journalnode, age_name, rgn_obj) else: - self._create_moul_nodes(bo, nodes, journalnode, age_name, rgn_obj) + self._create_moul_nodes(bo, tree.nodes, journalnode, age_name, rgn_obj) def _create_pots_nodes(self, clickable_object, nodes, journalnode, age_name, rgn_obj): clickable_region = nodes.new("PlasmaClickableRegionNode") @@ -484,27 +470,13 @@ class PlasmaLinkingBookModifier(PlasmaModifierProperties, PlasmaModifierLogicWiz yield self.seek_point.name def logicwiz(self, bo, tree, age_name, version, region): - nodes = tree.nodes - # Assign linking book script based on target version linking_pfm = linking_pfms[version] - linkingnode = nodes.new("PlasmaPythonFileNode") - with linkingnode.NoUpdate(): - linkingnode.filename = linking_pfm["filename"] - - # Manually add required attributes to the PFM - linking_attribs = linking_pfm["attribs"] - for attr in linking_attribs: - new_attr = linkingnode.attributes.add() - new_attr.attribute_id = attr["id"] - new_attr.attribute_type = attr["type"] - new_attr.attribute_name = attr["name"] - linkingnode.update() - + linkingnode = self._create_python_file_node(tree, linking_pfm["filename"], linking_pfm["attribs"]) if version <= pvPots: - self._create_pots_nodes(bo, nodes, linkingnode, age_name, region) + self._create_pots_nodes(bo, tree.nodes, linkingnode, age_name, region) else: - self._create_moul_nodes(bo, nodes, linkingnode, age_name, region) + self._create_moul_nodes(bo, tree.nodes, linkingnode, age_name, region) def _create_pots_nodes(self, clickable_object, nodes, linkingnode, age_name, clk_region): # Clickable