from lnx.logicnode.lnx_nodes import * class IntegerArrayNode(LnxLogicVariableNodeMixin, LnxLogicTreeNode): """Stores an array of integer elements as a variable.""" bl_idname = 'LNArrayIntegerNode' bl_label = 'Array Integer' lnx_version = 4 lnx_section = 'variable' min_inputs = 0 def __init__(self): super(IntegerArrayNode, self).__init__() 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 = 'LnxIntSocket' 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('LnxIntSocket', 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, 3): raise LookupError() return NodeReplacement.Identity(self)