48 lines
2.0 KiB
Python
48 lines
2.0 KiB
Python
|
from lnx.logicnode.lnx_nodes import *
|
||
|
|
||
|
class CallHaxeStaticNode(LnxLogicTreeNode):
|
||
|
"""Calls the given static Haxe function and optionally passes arguments to it.
|
||
|
|
||
|
**Compatibility info**: prior versions of this node didn't accept arguments and instead implicitly passed the current logic tree object as the first argument. In newer versions you need to pass that argument explicitly if the called function expects it.
|
||
|
|
||
|
@input Function: the full module path to the function.
|
||
|
@output Result: the result of the function."""
|
||
|
bl_idname = 'LNCallHaxeStaticNode'
|
||
|
bl_label = 'Call Haxe Static'
|
||
|
lnx_section = 'haxe'
|
||
|
lnx_version = 3
|
||
|
min_inputs = 2
|
||
|
|
||
|
def __init__(self):
|
||
|
array_nodes[str(id(self))] = self
|
||
|
|
||
|
def lnx_init(self, context):
|
||
|
self.add_input('LnxNodeSocketAction', 'In')
|
||
|
self.add_input('LnxStringSocket', 'Function')
|
||
|
|
||
|
self.add_output('LnxNodeSocketAction', 'Out')
|
||
|
self.add_output('LnxDynamicSocket', 'Result')
|
||
|
|
||
|
def draw_buttons(self, context, layout):
|
||
|
row = layout.row(align=True)
|
||
|
op = row.operator('lnx.node_add_input', text='Add Arg', icon='PLUS', emboss=True)
|
||
|
op.node_index = str(id(self))
|
||
|
op.socket_type = 'LnxDynamicSocket'
|
||
|
op.name_format = "Arg {0}"
|
||
|
op.index_name_offset = -2
|
||
|
column = row.column(align=True)
|
||
|
op = column.operator('lnx.node_remove_input', text='', icon='X', emboss=True)
|
||
|
op.node_index = str(id(self))
|
||
|
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, 2):
|
||
|
raise LookupError()
|
||
|
|
||
|
if self.lnx_version == 1 or self.lnx_version == 2:
|
||
|
return NodeReplacement(
|
||
|
'LNCallHaxeStaticNode', self.lnx_version, 'LNCallHaxeStaticNode', 2,
|
||
|
in_socket_mapping={0:0, 1:1}, out_socket_mapping={0:0, 1:1}
|
||
|
)
|