From 0716c2f4da7ecc0f5fe08fe107d5c06b13647fe7 Mon Sep 17 00:00:00 2001 From: Eroax Date: Mon, 27 Nov 2023 09:21:43 +0000 Subject: [PATCH 1/3] Adds Expression Node (#9) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds both the Codeblock Descriptor along with the needed update to Port.set_value to allow Callbacks. + Adds the Expression node which utilizes the Codeblock descriptor. Co-authored-by: Eroax Co-authored-by: Lera ElvoƩ Reviewed-on: https://codeberg.org/Eroax/Re-DotDeck/pulls/9 --- classes/deck/nodes/expression_node.gd | 36 ++++ classes/deck/port.gd | 3 + .../deck_node_renderer_graph_node.gd | 178 +++++++----------- .../deck_node_renderer_graph_node.tscn | 6 +- 4 files changed, 108 insertions(+), 115 deletions(-) create mode 100644 classes/deck/nodes/expression_node.gd diff --git a/classes/deck/nodes/expression_node.gd b/classes/deck/nodes/expression_node.gd new file mode 100644 index 0000000..ce2bdac --- /dev/null +++ b/classes/deck/nodes/expression_node.gd @@ -0,0 +1,36 @@ +extends DeckNode + +var expr = Expression.new() + +func _init(): + name = "Expression" + node_type = name.to_snake_case() + description = "A Node holding a block of executable GDScript code." + category = "general" + + props_to_serialize = [] + + add_output_port(DeckType.Types.ANY, "Expression Text", "codeblock") + + + +func _value_request(from_port : int) -> Variant: + + var text = get_output_ports()[0].value_callback.call() + + var err = expr.parse(text) + if err != OK: + + printerr(err) + return null + + + var res = expr.execute() + if expr.has_execute_failed(): + + printerr("Expression Execution Failed: ", text) + return null + + + return res + diff --git a/classes/deck/port.gd b/classes/deck/port.gd index 9cea9de..77df898 100644 --- a/classes/deck/port.gd +++ b/classes/deck/port.gd @@ -48,4 +48,7 @@ func _init( func set_value(v: Variant) -> void: + if v is Callable: + value = v.call() + return value = v diff --git a/graph_node_renderer/deck_node_renderer_graph_node.gd b/graph_node_renderer/deck_node_renderer_graph_node.gd index 350d29b..57d31a4 100644 --- a/graph_node_renderer/deck_node_renderer_graph_node.gd +++ b/graph_node_renderer/deck_node_renderer_graph_node.gd @@ -16,44 +16,7 @@ func _ready() -> void: #node.port_removed.connect(_on_node_port_removed) node.ports_updated.connect(_on_node_ports_updated) for port in node.get_all_ports(): - var descriptor_split := port.descriptor.split(":") - match descriptor_split[0]: - "button": - var button := Button.new() - add_child(button) - button.text = port.label - if port.port_type == DeckNode.PortType.OUTPUT: - button.pressed.connect( - func(): - node.send(port.index_of_type, true) - ) - elif port.port_type == DeckNode.PortType.INPUT: - button.pressed.connect( - func(): - node._receive(port.index_of_type, true) - ) - "field": - var line_edit := LineEdit.new() - add_child(line_edit) - if port.value: - line_edit.text = str(port.value) - line_edit.placeholder_text = port.label - port.value_callback = line_edit.get_text - line_edit.text_changed.connect(port.set_value) - _: - var label := Label.new() - add_child(label) - label.text = port.label - - set_slot( - port.index, - port.port_type == DeckNode.PortType.INPUT, - port.type, - Color.WHITE, - port.port_type == DeckNode.PortType.OUTPUT, - port.type, - Color.WHITE, - ) + update_port(port) ## Connected to [signal GraphElement.position_offset_updated] and updates the ## [member node]s properties @@ -72,45 +35,8 @@ func _on_node_position_updated(new_position: Dictionary) -> void: ## using [method GraphNode.set_slot] func _on_node_port_added(port_idx: int) -> void: var port := node.get_all_ports()[port_idx] + update_port(port) - var descriptor_split := port.descriptor.split(":") - match descriptor_split[0]: - "button": - var button := Button.new() - add_child(button) - button.text = port.label - if port.port_type == DeckNode.PortType.OUTPUT: - button.pressed.connect( - func(): - node.send(port.index_of_type, true) - ) - elif port.port_type == DeckNode.PortType.INPUT: - button.pressed.connect( - func(): - node._receive(port.index_of_type, true) - ) - "field": - var line_edit := LineEdit.new() - add_child(line_edit) - if port.value: - line_edit.text = str(port.value) - line_edit.placeholder_text = port.label - port.value_callback = line_edit.get_text - line_edit.text_changed.connect(port.set_value) - _: - var label := Label.new() - add_child(label) - label.text = port.label - - set_slot( - port.index, - port.port_type == DeckNode.PortType.INPUT, - port.type, - Color.WHITE, - port.port_type == DeckNode.PortType.OUTPUT, - port.type, - Color.WHITE, - ) ## Connected to [member node]s [signal port_removed], queue_frees the [Node] ## used for the descriptor, as well as using [method GraphNode.set_slot] to remove the slot. @@ -135,41 +61,67 @@ func _on_node_ports_updated() -> void: c.queue_free() for port in node.get_all_ports(): - var descriptor_split := port.descriptor.split(":") - match descriptor_split[0]: - "button": - var button := Button.new() - add_child(button) - button.text = port.label - if port.port_type == DeckNode.PortType.OUTPUT: - button.pressed.connect( - func(): - node.send(port.index_of_type, true) - ) - elif port.port_type == DeckNode.PortType.INPUT: - button.pressed.connect( - func(): - node._receive(port.index_of_type, true) - ) - "field": - var line_edit := LineEdit.new() - add_child(line_edit) - if port.value: - line_edit.text = str(port.value) - line_edit.placeholder_text = port.label - port.value_callback = line_edit.get_text - line_edit.text_changed.connect(port.set_value) - _: - var label := Label.new() - add_child(label) - label.text = port.label + update_port(port) - set_slot( - port.index, - port.port_type == DeckNode.PortType.INPUT, - port.type, - Color.WHITE, - port.port_type == DeckNode.PortType.OUTPUT, - port.type, - Color.WHITE, - ) + +func update_port(port: Port) -> void: + var descriptor_split := port.descriptor.split(":") + match descriptor_split[0]: + "button": + var button := Button.new() + add_child(button) + button.text = port.label + if port.port_type == DeckNode.PortType.OUTPUT: + button.pressed.connect( + func(): + node.send(port.index_of_type, true) + ) + #elif port.port_type == DeckNode.PortType.INPUT: + else: + button.pressed.connect( + func(): + node._receive(port.index_of_type, true) + ) + "field": + var line_edit := LineEdit.new() + add_child(line_edit) + if port.value: + line_edit.text = str(port.value) + line_edit.placeholder_text = port.label + port.value_callback = line_edit.get_text + line_edit.text_changed.connect(port.set_value) + "singlechoice": + var box := OptionButton.new() + for item in descriptor_split.slice(1): + box.add_item(item) + add_child(box) + port.value_callback = func(): return box.get_item_text(box.get_selected_id()) + if port.type == DeckType.Types.STRING: + box.item_selected.connect( + func(id: int): + port.set_value.call(box.get_item_text(box.get_selected_id())) + ) + "codeblock": + var code_edit = CodeEdit.new() + add_child(code_edit) + if port.value: + code_edit.text = str(port.value) + code_edit.placeholder_text = port.label + port.value_callback = code_edit.get_text + code_edit.text_changed.connect(port.set_value.bind(code_edit.get_text)) + code_edit.custom_minimum_size = Vector2(200, 100) + code_edit.size_flags_vertical = SIZE_EXPAND_FILL + _: + var label := Label.new() + add_child(label) + label.text = port.label + + set_slot( + port.index, + port.port_type == DeckNode.PortType.INPUT, + port.type, + Color.WHITE, + port.port_type == DeckNode.PortType.OUTPUT, + port.type, + Color.WHITE, + ) diff --git a/graph_node_renderer/deck_node_renderer_graph_node.tscn b/graph_node_renderer/deck_node_renderer_graph_node.tscn index 2d66ba3..ab50a1f 100644 --- a/graph_node_renderer/deck_node_renderer_graph_node.tscn +++ b/graph_node_renderer/deck_node_renderer_graph_node.tscn @@ -3,8 +3,10 @@ [ext_resource type="Script" path="res://graph_node_renderer/deck_node_renderer_graph_node.gd" id="1_pos0w"] [node name="DeckNodeRendererGraphNode" type="GraphNode"] -offset_right = 280.0 -offset_bottom = 217.0 +custom_minimum_size = Vector2(200, 0) +offset_right = 200.0 +offset_bottom = 55.0 +resizable = true title = "Deck Node" script = ExtResource("1_pos0w") From 3010ead296826f27f2281a82558c36e57cd069ef Mon Sep 17 00:00:00 2001 From: Eroax Date: Mon, 27 Nov 2023 09:28:36 +0000 Subject: [PATCH 2/3] Adds in Delay Node (#10) So a bit behind, but this adds in the Delay Node. Co-authored-by: Eroax Reviewed-on: https://codeberg.org/Eroax/Re-DotDeck/pulls/10 --- classes/deck/nodes/delay.gd | 42 +++++++++++++++++++ .../deck_renderer_graph_edit.tscn | 1 + 2 files changed, 43 insertions(+) create mode 100644 classes/deck/nodes/delay.gd diff --git a/classes/deck/nodes/delay.gd b/classes/deck/nodes/delay.gd new file mode 100644 index 0000000..44dd2d4 --- /dev/null +++ b/classes/deck/nodes/delay.gd @@ -0,0 +1,42 @@ +extends DeckNode + +var thread : Thread + +func _init(): + name = "Delay" + node_type = name.to_snake_case() + description = "A Node that passes through the input after the set time." + + add_output_port(Deck.Types.STRING, "Value", "") + + add_input_port(Deck.Types.NUMERIC, "Delay Time", "field") + add_input_port(Deck.Types.NUMERIC, "Value", "field") + + + +func _receive(to_input_port, data: DeckType, extra_data: Array = []): + + thread = Thread.new() + thread.start(handle_delay.bind(data)) + + +func handle_delay(data): + + var goal_time = Time.get_ticks_msec() + (int(get_input_ports()[0].value_callback.call()) * 1000) + + while Time.get_ticks_msec() < goal_time: + + pass + + + print("Delay over") + send(0, data) + + +func _notification(what): + + if what == NOTIFICATION_PREDELETE and thread != null: + + thread.wait_to_finish() + + diff --git a/graph_node_renderer/deck_renderer_graph_edit.tscn b/graph_node_renderer/deck_renderer_graph_edit.tscn index e2e70c7..1d4e361 100644 --- a/graph_node_renderer/deck_renderer_graph_edit.tscn +++ b/graph_node_renderer/deck_renderer_graph_edit.tscn @@ -9,6 +9,7 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 right_disconnects = true +show_arrange_button = false script = ExtResource("1_pojfs") [connection signal="popup_request" from="." to="." method="_on_popup_request"] From dc7d53e3d2b67dd688ad766ca957199819916fdc Mon Sep 17 00:00:00 2001 From: Eroax Date: Mon, 27 Nov 2023 02:33:14 -0700 Subject: [PATCH 3/3] Patched Delay Node. Delay was REALLY out of date, so I patched it up. --- classes/deck/nodes/delay.gd | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/classes/deck/nodes/delay.gd b/classes/deck/nodes/delay.gd index 44dd2d4..1bea237 100644 --- a/classes/deck/nodes/delay.gd +++ b/classes/deck/nodes/delay.gd @@ -6,15 +6,16 @@ func _init(): name = "Delay" node_type = name.to_snake_case() description = "A Node that passes through the input after the set time." + category = "general" - add_output_port(Deck.Types.STRING, "Value", "") + add_output_port(DeckType.Types.STRING, "Value", "") - add_input_port(Deck.Types.NUMERIC, "Delay Time", "field") - add_input_port(Deck.Types.NUMERIC, "Value", "field") + add_input_port(DeckType.Types.NUMERIC, "Delay Time", "field") + add_input_port(DeckType.Types.NUMERIC, "Value", "field") -func _receive(to_input_port, data: DeckType, extra_data: Array = []): +func _receive(to_input_port : int, data: Variant, extra_data: Array = []) -> void: thread = Thread.new() thread.start(handle_delay.bind(data))