95 lines
3.4 KiB
Python
95 lines
3.4 KiB
Python
from lnx.logicnode.lnx_nodes import *
|
|
|
|
|
|
class JSEventTargetNode(LnxLogicTreeNode):
|
|
"""JS Event Target"""
|
|
bl_idname = 'LNJSEventTargetNode'
|
|
bl_label = 'JS Event Target'
|
|
bl_description = 'Event Target is an interface implemented by objects that can receive events and may have listeners for them.'
|
|
lnx_category = 'HTML'
|
|
lnx_version = 1
|
|
|
|
@staticmethod
|
|
def get_enum_id_value(obj, prop_name, value):
|
|
return obj.bl_rna.properties[prop_name].enum_items[value].identifier
|
|
|
|
@staticmethod
|
|
def get_count_in(type_name):
|
|
return {
|
|
'addEventListener': 0,
|
|
'removeEventListener': 1,
|
|
'dispatchEvent': 2,
|
|
}.get(type_name, 0)
|
|
|
|
def get_enum(self):
|
|
return self.get('property0', 0)
|
|
|
|
def set_enum(self, value):
|
|
# Checking the selection of each type
|
|
select_current = self.get_enum_id_value(self, 'property0', value)
|
|
select_prev = self.property0
|
|
|
|
#Check if type changed
|
|
if select_prev != select_current:
|
|
|
|
for i in self.inputs:
|
|
self.inputs.remove(i)
|
|
|
|
# Arguements for type Client
|
|
index = self.get_count_in(select_current)
|
|
|
|
match index:
|
|
case 2:
|
|
self.add_input('LnxNodeSocketAction', 'In')
|
|
self.add_input('LnxDynamicSocket', 'JS Object')
|
|
self.add_input('LnxDynamicSocket', 'Event')
|
|
case _:
|
|
self.add_input('LnxNodeSocketAction', 'In')
|
|
self.add_input('LnxDynamicSocket', 'JS Object')
|
|
self.add_input('LnxStringSocket', 'Type')
|
|
self.add_input('LnxDynamicSocket', 'Listener')
|
|
self.add_input('LnxDynamicSocket', 'Options')
|
|
self.add_input('LnxBoolSocket', 'unTrusted')
|
|
|
|
self['property0'] = value
|
|
|
|
property0: HaxeEnumProperty(
|
|
'property0',
|
|
items = [('addEventListener', 'addEventListener', 'Add an event listener to the object'),
|
|
('removeEventListener', 'removeEventListener', 'Remove an event listener to the object'),
|
|
('dispatchEvent', 'dispatchEvent', 'Dispatch an event to the object listener')],
|
|
name='',
|
|
default='addEventListener',
|
|
set=set_enum,
|
|
get=get_enum)
|
|
|
|
property1: HaxeEnumProperty(
|
|
'property1',
|
|
items = [('inline', 'Inline Function', 'Inline function to evaluate on event'),
|
|
('callable', 'Callable Function', 'Callable function to trigger on event'),
|
|
('event', 'Event Listener', 'Bind event to existing event listener'),
|
|
('output', 'Bind output', 'Trigger node output on JS event')],
|
|
name='',
|
|
default='inline')
|
|
|
|
def lnx_init(self, context):
|
|
self.add_input('LnxNodeSocketAction', 'In')
|
|
self.add_input('LnxDynamicSocket', 'JS Object')
|
|
self.add_input('LnxStringSocket', 'Type')
|
|
self.add_input('LnxDynamicSocket', 'Listener')
|
|
self.add_input('LnxDynamicSocket', 'Options')
|
|
self.add_input('LnxBoolSocket', 'WantsUnTrusted')
|
|
|
|
self.add_output('LnxNodeSocketAction', 'Out')
|
|
|
|
|
|
def draw_buttons(self, context, layout):
|
|
layout.prop(self, 'property0')
|
|
if str(self.property0) == 'addEventListener':
|
|
layout.prop(self, 'property1')
|
|
|
|
|
|
def register():
|
|
add_category('HTML', icon='SEQ_STRIP_META')
|
|
JSEventTargetNode.on_register()
|