| 
									
										
										
										
											2025-01-22 16:18:30 +01:00
										 |  |  | from lnx.logicnode.lnx_nodes import * | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class CaseIndexNode(LnxLogicTreeNode): | 
					
						
							|  |  |  |     """Compare the given `Compare` value with the other inputs for equality
 | 
					
						
							|  |  |  |     and return the index of the first match. This is particularly helpful | 
					
						
							|  |  |  |     in combination with the `Select` node. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @seeNode Select | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @input Compare: the value to be compared | 
					
						
							|  |  |  |     @input Value: values for the dynamic comparison | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @output Index: the index of the first equal value, or `null` if no | 
					
						
							|  |  |  |         equal value was found. | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     bl_idname = 'LNCaseIndexNode' | 
					
						
							|  |  |  |     bl_label = 'Case Index' | 
					
						
							|  |  |  |     lnx_version = 1 | 
					
						
							|  |  |  |     min_inputs = 2 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     num_choices: IntProperty(default=0, min=0) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-03 10:01:30 +00:00
										 |  |  |     def __init__(self, *args, **kwargs): | 
					
						
							|  |  |  |         super(CaseIndexNode, self).__init__(*args, **kwargs) | 
					
						
							| 
									
										
										
										
											2025-01-22 16:18:30 +01:00
										 |  |  |         array_nodes[str(id(self))] = self | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def lnx_init(self, context): | 
					
						
							|  |  |  |         self.add_input('LnxDynamicSocket', 'Compare') | 
					
						
							|  |  |  |         self.add_input_func() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self.add_output('LnxIntSocket', 'Index') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def draw_buttons(self, context, layout): | 
					
						
							|  |  |  |         row = layout.row(align=True) | 
					
						
							|  |  |  |         op = row.operator('lnx.node_call_func', text='New', icon='PLUS', emboss=True) | 
					
						
							|  |  |  |         op.node_index = str(id(self)) | 
					
						
							|  |  |  |         op.callback_name = 'add_input_func' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         column = row.column(align=True) | 
					
						
							|  |  |  |         op = column.operator('lnx.node_call_func', text='', icon='X', emboss=True) | 
					
						
							|  |  |  |         op.node_index = str(id(self)) | 
					
						
							|  |  |  |         op.callback_name = 'remove_input_func' | 
					
						
							|  |  |  |         if len(self.inputs) == self.min_inputs: | 
					
						
							|  |  |  |             column.enabled = False | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def add_input_func(self): | 
					
						
							|  |  |  |         self.add_input('LnxDynamicSocket', f'Value {self.num_choices}') | 
					
						
							|  |  |  |         self.num_choices += 1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def remove_input_func(self): | 
					
						
							|  |  |  |         if len(self.inputs) > self.min_inputs: | 
					
						
							|  |  |  |             self.inputs.remove(self.inputs[-1]) | 
					
						
							|  |  |  |             self.num_choices -= 1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def draw_label(self) -> str: | 
					
						
							|  |  |  |         if self.num_choices == 0: | 
					
						
							|  |  |  |             return self.bl_label | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return f'{self.bl_label}: [{self.num_choices}]' |