diff --git a/classes/deck/deck.gd b/classes/deck/deck.gd index 8367f59..7426da5 100644 --- a/classes/deck/deck.gd +++ b/classes/deck/deck.gd @@ -291,6 +291,11 @@ func duplicate_nodes(nodes: Array[String]) -> void: paste_nodes_from_dict(d, position) +func send_event(event_name: StringName, event_data: Dictionary = {}) -> void: + for node: DeckNode in nodes.values(): + node._event_received(event_name, event_data) + + ## Returns a [Dictionary] representation of this deck. func to_dict(with_meta: bool = true) -> Dictionary: var inner := { diff --git a/classes/deck/deck_holder.gd b/classes/deck/deck_holder.gd index 14879f9..86de789 100644 --- a/classes/deck/deck_holder.gd +++ b/classes/deck/deck_holder.gd @@ -30,3 +30,8 @@ static func open_deck_from_file(path: String) -> Deck: ## Unloads a deck. static func close_deck(deck: Deck) -> void: DeckHolder.decks.erase(deck) + + +static func send_event(event_name: StringName, event_data: Dictionary = {}) -> void: + for deck in decks: + deck.send_event(event_name, event_data) diff --git a/classes/deck/deck_node.gd b/classes/deck/deck_node.gd index ef954bd..e3176c0 100644 --- a/classes/deck/deck_node.gd +++ b/classes/deck/deck_node.gd @@ -182,6 +182,10 @@ func remove_incoming_connection(to_port: int) -> void: incoming_connection_removed.emit(to_port) +func _event_received(event_name: StringName, event_data: Dictionary = {}) -> void: + pass + + ## Returns a list of all input ports. func get_input_ports() -> Array[Port]: return ports.filter( diff --git a/classes/deck/nodes/process_node.gd b/classes/deck/nodes/process_node.gd new file mode 100644 index 0000000..bea6576 --- /dev/null +++ b/classes/deck/nodes/process_node.gd @@ -0,0 +1,50 @@ +extends DeckNode + +var delta: float + + +func _init() -> void: + name = "Process Loop" + node_type = name.to_snake_case() + description = "" + category = "general" + + add_input_port( + DeckType.Types.BOOL, + "Enabled", + "checkbox" + ) + + add_output_port( + DeckType.Types.BOOL, + "Trigger" + ) + + add_output_port( + DeckType.Types.NUMERIC, + "Delta" + ) + + +func _event_received(event_name: StringName, event_data: Dictionary = {}) -> void: + if event_name != &"process": + return + + var run := false + if request_value(0) != null: + run = request_value(0) + elif ports[0].value_callback.get_object() && ports[0].value_callback.call() != null: + run = ports[0].value_callback.call() + + if !run: + return + + delta = event_data.delta + send(0, true) + + +func _value_request(on_output_port: int) -> Variant: + if on_output_port != 1: + return null + + return delta diff --git a/graph_node_renderer/deck_holder_renderer.gd b/graph_node_renderer/deck_holder_renderer.gd index e13fffb..9ef6d9b 100644 --- a/graph_node_renderer/deck_holder_renderer.gd +++ b/graph_node_renderer/deck_holder_renderer.gd @@ -168,3 +168,6 @@ func _on_obs_websocket_setup_dialog_connect_button_pressed(state: OBSWebsocketSe await no_obsws.connection_ready obs_setup_dialog.set_button_state(OBSWebsocketSetupDialog.ConnectionState.CONNECTED) + +func _process(delta: float) -> void: + DeckHolder.send_event(&"process", {"delta": delta}) diff --git a/graph_node_renderer/deck_node_renderer_graph_node.gd b/graph_node_renderer/deck_node_renderer_graph_node.gd index eb6dbe3..571074d 100644 --- a/graph_node_renderer/deck_node_renderer_graph_node.gd +++ b/graph_node_renderer/deck_node_renderer_graph_node.gd @@ -121,6 +121,16 @@ func update_port(port: Port) -> void: 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 + "checkbox": + var cb := CheckBox.new() + add_child(cb) + if descriptor_split.size() > 1: + cb.button_pressed = true + if port.value is bool: + cb.button_pressed = port.value + cb.text = port.label + port.value_callback = cb.is_pressed + cb.toggled.connect(port.set_value) _: var label := Label.new() add_child(label)