| 
									
										
										
										
											2025-01-22 16:18:30 +01:00
										 |  |  | from lnx.logicnode.lnx_nodes import * | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SwitchNode(LnxLogicTreeNode): | 
					
						
							|  |  |  |     """Activates the outputs depending of the value. If the "value" is equal to "case 1", the output "case 1" will be activated.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @output Default: Activated if the input value does not match any case. | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     bl_idname = 'LNSwitchNode' | 
					
						
							|  |  |  |     bl_label = 'Switch Output' | 
					
						
							|  |  |  |     lnx_version = 4 | 
					
						
							|  |  |  |     min_inputs = 2 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-06 10:12:43 +00:00
										 |  |  |     def __init__(self, *args, **kwargs): | 
					
						
							|  |  |  |         super(SwitchNode, self).__init__(*args, **kwargs) | 
					
						
							| 
									
										
										
										
											2025-01-22 16:18:30 +01:00
										 |  |  |         array_nodes[self.get_id_str()] = self | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def lnx_init(self, context): | 
					
						
							|  |  |  |         self.add_input('LnxNodeSocketAction', 'In') | 
					
						
							|  |  |  |         self.add_input('LnxDynamicSocket', 'Value') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self.add_output('LnxNodeSocketAction', 'Default') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def draw_buttons(self, context, layout): | 
					
						
							|  |  |  |         row = layout.row(align=True) | 
					
						
							|  |  |  |         op = row.operator('lnx.node_add_input_output', text='New', icon='PLUS', emboss=True) | 
					
						
							|  |  |  |         op.node_index = self.get_id_str() | 
					
						
							|  |  |  |         op.in_socket_type = 'LnxDynamicSocket' | 
					
						
							|  |  |  |         op.out_socket_type = 'LnxNodeSocketAction' | 
					
						
							|  |  |  |         op.in_name_format = 'Case {0}' | 
					
						
							|  |  |  |         op.out_name_format = 'Case {0}' | 
					
						
							|  |  |  |         op.in_index_name_offset = -1 | 
					
						
							|  |  |  |         op.out_index_name_offset = -1 | 
					
						
							|  |  |  |         column = row.column(align=True) | 
					
						
							|  |  |  |         op = column.operator('lnx.node_remove_input_output', text='', icon='X', emboss=True) | 
					
						
							|  |  |  |         op.node_index = self.get_id_str() | 
					
						
							|  |  |  |         if len(self.inputs) == self.min_inputs: | 
					
						
							|  |  |  |             column.enabled = False | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def get_replacement_node(self, node_tree: bpy.types.NodeTree): | 
					
						
							|  |  |  |         if self.lnx_version not in (0, 3): | 
					
						
							|  |  |  |             raise LookupError() | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  |         return NodeReplacement.Identity(self) |