2025-04-03 09:41:20 +00:00
|
|
|
from lnx.logicnode.lnx_nodes import *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LeenkxSendMessageNode(LnxLogicTreeNode):
|
|
|
|
|
"""Leenkx Send Message"""
|
|
|
|
|
bl_idname = 'LNLeenkxSendMessageNode'
|
|
|
|
|
bl_label = 'Leenkx Send Message'
|
|
|
|
|
bl_description = 'Send messages to the Leenkx network'
|
|
|
|
|
lnx_category = 'Leenkx'
|
|
|
|
|
lnx_version = 1
|
|
|
|
|
|
2026-10-06 02:10:08 -07:00
|
|
|
def update_sockets(self, context):
|
|
|
|
|
if not self.inputs:
|
|
|
|
|
return
|
|
|
|
|
links = {}
|
|
|
|
|
send_all = True
|
|
|
|
|
for socket in self.inputs:
|
|
|
|
|
for link in socket.links:
|
|
|
|
|
links.setdefault(socket.name, []).append(
|
|
|
|
|
(link.from_node, link.from_socket))
|
|
|
|
|
if socket.name == 'Send All':
|
|
|
|
|
send_all = socket.default_value_raw
|
|
|
|
|
for socket in self.inputs[3:]:
|
|
|
|
|
self.inputs.remove(socket)
|
|
|
|
|
self._add_data_inputs(send_all)
|
|
|
|
|
tree = self.id_data
|
|
|
|
|
for socket in self.inputs:
|
|
|
|
|
if socket.name in links:
|
|
|
|
|
for from_node, from_socket in links[socket.name]:
|
|
|
|
|
tree.links.new(from_socket, socket)
|
|
|
|
|
|
|
|
|
|
def _add_data_inputs(self, send_all=True):
|
|
|
|
|
data_sockets = {
|
|
|
|
|
'string': ('LnxStringSocket', 'String payload to send'),
|
|
|
|
|
'vector': ('LnxVectorSocket', 'Vector payload to send'),
|
|
|
|
|
'float': ('LnxFloatSocket', 'Float payload to send'),
|
|
|
|
|
'integer': ('LnxIntSocket', 'Integer payload to send'),
|
|
|
|
|
'boolean': ('LnxBoolSocket', 'Boolean payload to send'),
|
|
|
|
|
'transform': ('LnxDynamicSocket', 'Transform (Mat4) payload to send'),
|
|
|
|
|
'rotation': ('LnxRotationSocket', 'Rotation (Quat) payload to send'),
|
|
|
|
|
}
|
|
|
|
|
socket_type, desc = data_sockets.get(self.property1, data_sockets['string'])
|
|
|
|
|
self.add_input(socket_type, 'Data')
|
|
|
|
|
self.add_input('LnxBoolSocket', 'Send All', default_value=send_all)
|
|
|
|
|
if not send_all:
|
|
|
|
|
self._add_id_input()
|
|
|
|
|
|
|
|
|
|
def _add_id_input(self):
|
|
|
|
|
self.add_input('LnxStringSocket', 'ID')
|
|
|
|
|
|
|
|
|
|
def on_socket_val_update(self, context, socket):
|
|
|
|
|
if socket.name == 'Send All':
|
|
|
|
|
if (len(self.inputs) > 5
|
|
|
|
|
and self.inputs[5].name == 'ID'):
|
|
|
|
|
self.inputs.remove(self.inputs[5])
|
|
|
|
|
if not socket.default_value_raw:
|
|
|
|
|
self._add_id_input()
|
|
|
|
|
super().on_socket_val_update(context, socket)
|
|
|
|
|
|
|
|
|
|
property1: HaxeEnumProperty('property1',
|
2025-04-03 09:41:20 +00:00
|
|
|
items = [('string', 'String', 'Send a string over the network to one or all of the clients'),
|
|
|
|
|
('vector', 'Vector', 'Send a vector over the network to one or all of the clients'),
|
|
|
|
|
('float', 'Float', 'Send a float over the network to one or all of the clients'),
|
|
|
|
|
('integer', 'Integer', 'Send an integer over the network to one or all of the clients'),
|
|
|
|
|
('boolean', 'Boolean', 'Send a boolean over the network to one or all of the clients'),
|
|
|
|
|
('transform', 'Transform', 'Send a transform over the network to one or all of the clients'),
|
|
|
|
|
('rotation', 'Rotation', 'Send a rotation over the network to one or all of the clients')],
|
2026-10-06 02:10:08 -07:00
|
|
|
name='', default='string', update=update_sockets)
|
|
|
|
|
|
|
|
|
|
property2: HaxeBoolProperty('property2',
|
|
|
|
|
name='Encrypted',
|
|
|
|
|
description='Use full encryption protocol (signing, bencode, box encryption). Disable for fast raw message mode',
|
|
|
|
|
default=False)
|
2025-04-03 09:41:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
super(LeenkxSendMessageNode, self).__init__(*args, **kwargs)
|
|
|
|
|
array_nodes[str(id(self))] = self
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def lnx_init(self, context):
|
|
|
|
|
self.add_input('LnxNodeSocketAction', 'In')
|
|
|
|
|
self.add_input('LnxDynamicSocket', 'Connection')
|
|
|
|
|
self.add_input('LnxStringSocket', 'API')
|
2026-10-06 02:10:08 -07:00
|
|
|
self._add_data_inputs()
|
|
|
|
|
|
2025-04-03 09:41:20 +00:00
|
|
|
self.add_output('LnxNodeSocketAction', 'Out')
|
2026-10-06 02:10:08 -07:00
|
|
|
|
2025-04-03 09:41:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def draw_buttons(self, context, layout):
|
|
|
|
|
layout.prop(self, 'property1')
|
2026-10-06 02:10:08 -07:00
|
|
|
layout.prop(self, 'property2')
|
2025-04-03 09:41:20 +00:00
|
|
|
|
|
|
|
|
def register():
|
|
|
|
|
add_category('Leenkx', icon='ORIENTATION_CURSOR')
|
2025-01-22 16:18:30 +01:00
|
|
|
LeenkxSendMessageNode.on_register()
|