52 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| from lnx.logicnode.lnx_nodes import *
 | |
| 
 | |
| 
 | |
| class VectorArrayNode(LnxLogicVariableNodeMixin, LnxLogicTreeNode):
 | |
|     """Stores an array of vector elements as a variable."""
 | |
|     bl_idname = 'LNArrayVectorNode'
 | |
|     bl_label = 'Array Vector'
 | |
|     lnx_version = 3
 | |
|     lnx_section = 'variable'
 | |
|     min_inputs = 0
 | |
| 
 | |
|     def __init__(self, *args, **kwargs):
 | |
|         super(VectorArrayNode, self).__init__(*args, **kwargs)
 | |
| 
 | |
|         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 = 'LnxVectorSocket'
 | |
|         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('LnxVectorSocket', 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)
 |