|
1 |
| -extends Control |
| 1 | +extends GraphEdit |
2 | 2 |
|
3 | 3 | var initial_position = Vector2(40,40)
|
4 | 4 | var node_index = 0
|
5 |
| -@onready var nodeList = $Control/NodeList |
| 5 | +@onready var node_list = get_parent().get_parent().get_node("Node List/NodeList") |
6 | 6 | var built_in_nodes = {
|
7 | 7 | 'DMX Value':"DMX_value",
|
8 | 8 | 'Art-Net Output':"ART_NET_output",
|
| 9 | + 'Merge':"Merge", |
| 10 | + 'Value':"Value", |
| 11 | + 'DMX Table': "DMX_table" |
9 | 12 | }
|
| 13 | + |
10 | 14 | var connected_nodes = {}
|
| 15 | + |
| 16 | +var outbound_queue = {} |
11 | 17 | # Called when the node enters the scene tree for the first time.
|
12 | 18 |
|
13 | 19 | func _ready():
|
14 |
| - pass # Replace with function body. |
| 20 | + for node in built_in_nodes: |
| 21 | + node_list.add_item(node) |
15 | 22 |
|
16 | 23 | # Called every frame. 'delta' is the elapsed time since the previous frame.
|
17 |
| -#func _process(delta): |
18 |
| -# pass |
19 |
| - |
20 |
| - |
| 24 | +func _process(_delta): |
| 25 | + if Input.is_action_just_pressed("process_loop"): |
| 26 | + print(connected_nodes) |
| 27 | + if not outbound_queue.is_empty(): |
| 28 | + for i in outbound_queue: |
| 29 | + if connected_nodes.has(i): |
| 30 | + for slot in connected_nodes[i]: |
| 31 | + get_node(NodePath(slot[1])).receive(outbound_queue[i][slot[0]], slot[2]) |
| 32 | + outbound_queue = {} |
| 33 | + for N in self.get_children(): |
| 34 | + N.node_process() |
| 35 | + |
21 | 36 | func send(node, data, slot):
|
22 |
| - print(data) |
23 |
| - get_node(NodePath(connected_nodes[node][slot])).receive(data, slot) |
| 37 | + if node.name in outbound_queue: |
| 38 | + outbound_queue[node.name][slot] = data |
| 39 | + else: |
| 40 | + outbound_queue[node.name] = {slot:data} |
| 41 | + |
| 42 | +# for node_to_send in connected_nodes: |
| 43 | +# get_node(NodePath(list[i]["to"])).receive(data, list[i]["to_port"]) |
| 44 | + |
| 45 | +# print(self.get_parent().get_node("Node Editor").get_connection_list()) |
| 46 | +# if connected_nodes.has(node): |
| 47 | +# get_node(NodePath(connected_nodes[node][slot])).receive(data, slot) |
24 | 48 |
|
25 | 49 | func _on_GraphEdit_connection_request(from, from_slot, to, to_slot):
|
26 |
| - self.get_parent().get_node("Node Editor").connect_node(from, from_slot, to, to_slot) |
27 |
| - print(from) |
28 |
| - connected_nodes[get_node(str(from))] = {from_slot:to} |
| 50 | + self.connect_node(from, from_slot, to, to_slot) |
| 51 | + if from in connected_nodes: |
| 52 | + connected_nodes[from].append([from_slot, to, to_slot]) |
| 53 | + else: |
| 54 | + connected_nodes[from] = [[from_slot, to, to_slot]] |
| 55 | + print(connected_nodes) |
29 | 56 |
|
30 | 57 | func _on_GraphEdit_disconnection_request(from, from_slot, to, to_slot):
|
31 |
| - self.get_parent().get_node("Node Editor").disconnect_node(from, from_slot, to, to_slot) |
32 |
| - print(from) |
33 |
| - connected_nodes[get_node(str(from))].erase(from_slot) |
34 |
| - |
35 |
| -func _on_RunProgram_pressed(): |
36 |
| - var G = self |
37 |
| - var connection_list = G.get_connection_list() |
38 |
| - print(G.get_connection_list()) |
39 |
| - var result = 0 |
40 |
| - for i in range(0, connection_list.size()): |
41 |
| - var value = G.get_node(NodePath(connection_list[i].from)).get_node('SpinBox').value |
42 |
| - var value_2 = G.get_node(NodePath(connection_list[i].to)).get_node('SpinBox').value |
43 |
| - result += value |
44 |
| - if i+1 == connection_list.size(): |
45 |
| - result += value_2 |
46 |
| - print(result) |
| 58 | + self.disconnect_node(from, from_slot, to, to_slot) |
| 59 | + connected_nodes[from].erase([from_slot, to, to_slot]) |
| 60 | + if len(connected_nodes[from]) == 0: |
| 61 | + connected_nodes.erase(from) |
| 62 | + print(connected_nodes) |
| 63 | + |
| 64 | +func delete(node): |
| 65 | + connected_nodes.erase(node.name) |
| 66 | + print(connected_nodes) |
| 67 | + for i in connected_nodes: |
| 68 | + print(i) |
| 69 | + for x in connected_nodes[i]: |
| 70 | + print(x) |
| 71 | + if node.name in x: |
| 72 | + print("found node to delete") |
| 73 | + print(x) |
| 74 | + connected_nodes[i].erase(x) |
| 75 | + if len(connected_nodes[i]) == 0: |
| 76 | + connected_nodes.erase(i) |
| 77 | + |
| 78 | +#func _on_RunProgram_pressed(): |
| 79 | +# var G = self |
| 80 | +# var connection_list = G.get_connection_list() |
| 81 | +# print(G.get_connection_list()) |
| 82 | +# var result = 0 |
| 83 | +# for i in range(0, connection_list.size()): |
| 84 | +# var value = G.get_node(NodePath(connection_list[i].from)).get_node('SpinBox').value |
| 85 | +# var value_2 = G.get_node(NodePath(connection_list[i].to)).get_node('SpinBox').value |
| 86 | +# result += value |
| 87 | +# if i+1 == connection_list.size(): |
| 88 | +# result += value_2 |
| 89 | +# print(result) |
47 | 90 |
|
48 | 91 |
|
49 | 92 | func _on_item_list_item_clicked(index, _at_position, _mouse_button_index):
|
50 |
| - print("res://Nodes/" + built_in_nodes[nodeList.get_item_text(index)] + ".tscn") |
51 |
| - var node_to_add = load("res://Nodes/" + built_in_nodes[nodeList.get_item_text(index)] + ".tscn").instantiate() |
52 |
| - node_to_add.position_offset += initial_position + (node_index * Vector2(20,20)) |
53 |
| - set_editable_instance(node_to_add, true) |
| 93 | + print("res://Nodes/" + built_in_nodes[node_list.get_item_text(index)] + ".tscn") |
| 94 | + var node_to_add = load("res://Nodes/" + built_in_nodes[node_list.get_item_text(index)] + ".tscn").instantiate() |
| 95 | + node_to_add.position_offset = (get_viewport().get_mouse_position() + self.scroll_offset) / self.zoom |
| 96 | +# set_editable_instance(node_to_add, true) |
54 | 97 | node_to_add.name = node_to_add.name + str(node_index)
|
55 | 98 | self.add_child(node_to_add)
|
56 | 99 | node_index += 1
|
0 commit comments