From dbdda4614a2c33e9642d740ca537ad5f46cb0b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Tue, 5 Dec 2023 02:02:02 +0300 Subject: [PATCH] add bool constant and if true nodes --- classes/deck/nodes/bool_constant.gd | 20 +++++++++++++++++ classes/deck/nodes/if_true.gd | 33 ++++++++++++++++++++++++++++ graph_node_renderer/add_node_menu.gd | 1 - 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 classes/deck/nodes/bool_constant.gd create mode 100644 classes/deck/nodes/if_true.gd diff --git a/classes/deck/nodes/bool_constant.gd b/classes/deck/nodes/bool_constant.gd new file mode 100644 index 0000000..cc61cbd --- /dev/null +++ b/classes/deck/nodes/bool_constant.gd @@ -0,0 +1,20 @@ +extends DeckNode + + +func _init() -> void: + name = "Bool Constant" + node_type = name.to_snake_case() + category = "general" + + add_output_port( + DeckType.Types.BOOL, + "Value", + "checkbox" + ) + + +func _value_request(_from_port: int) -> Variant: + if ports[0].value_callback.get_object(): + return ports[0].value_callback.call() + else: + return ports[0].value diff --git a/classes/deck/nodes/if_true.gd b/classes/deck/nodes/if_true.gd new file mode 100644 index 0000000..72da98f --- /dev/null +++ b/classes/deck/nodes/if_true.gd @@ -0,0 +1,33 @@ +extends DeckNode + + +func _init() -> void: + name = "Pass If True" + node_type = "if_true" + description = "Pass input if and only if the condition input is true." + category = "general" + + add_input_port( + DeckType.Types.BOOL, + "Condition", + "checkbox" + ) + add_input_port( + DeckType.Types.ANY, + "Input" + ) + + add_output_port( + DeckType.Types.ANY, + "Output" + ) + + +func _receive(to_input_port: int, data: Variant, extra_data: Array = []) -> void: + if to_input_port != 1: + return + + if !request_value(0): + return + + send(0, data, extra_data) diff --git a/graph_node_renderer/add_node_menu.gd b/graph_node_renderer/add_node_menu.gd index c38a5dd..706302c 100644 --- a/graph_node_renderer/add_node_menu.gd +++ b/graph_node_renderer/add_node_menu.gd @@ -178,7 +178,6 @@ func _on_category_collapse_toggled(collapsed: bool, category: String) -> void: class Category extends VBoxContainer: const COLLAPSE_ICON := preload("res://graph_node_renderer/textures/collapse-icon.svg") const COLLAPSE_ICON_COLLAPSED := preload("res://graph_node_renderer/textures/collapse-icon-collapsed.svg") - var collapse_button: Button ## Emitted when a child item has been pressed.