50 lines
1.8 KiB
Python
Raw Normal View History

2025-01-22 16:18:30 +01:00
from lnx.logicnode.lnx_nodes import *
class ArrayNode(LnxLogicVariableNodeMixin, LnxLogicTreeNode):
"""Stores the given array as a variable."""
bl_idname = 'LNArrayNode'
bl_label = 'Array Dynamic'
lnx_version = 3
lnx_section = 'variable'
min_inputs = 0
def __init__(self):
self.register_id()
def lnx_init(self, context):
self.add_output('LnxNodeSocketArray', 'Array', is_var=True)
self.add_output('LnxIntSocket', 'Length')
def draw_content(self, context, layout):
row = layout.row(align=True)
op = row.operator('lnx.node_add_input', text='New', icon='PLUS', emboss=True)
op.node_index = self.get_id_str()
op.socket_type = 'LnxDynamicSocket'
column = row.column(align=True)
op = column.operator('lnx.node_remove_input', text='', icon='X', emboss=True)
op.node_index = self.get_id_str()
if len(self.inputs) == self.min_inputs:
column.enabled = False
def draw_label(self) -> str:
if len(self.inputs) == self.min_inputs:
return super().draw_label()
return f'{super().draw_label()} [{len(self.inputs)}]'
def synchronize_from_master(self, master_node: LnxLogicVariableNodeMixin):
self.inputs.clear()
for i in range(len(master_node.inputs)):
inp = self.add_input('LnxDynamicSocket', master_node.inputs[i].name)
inp.hide = self.lnx_logic_id != ''
inp.enabled = self.lnx_logic_id == ''
inp.default_value_raw = master_node.inputs[i].get_default_value()
def get_replacement_node(self, node_tree: bpy.types.NodeTree):
if self.lnx_version not in (0, 2):
raise LookupError()
return NodeReplacement.Identity(self)