add event system, add process node

This commit is contained in:
Lera Elvoé 2023-12-01 12:30:35 +03:00
parent 542758c660
commit b05b5561db
No known key found for this signature in database
6 changed files with 77 additions and 0 deletions

View file

@ -291,6 +291,11 @@ func duplicate_nodes(nodes: Array[String]) -> void:
paste_nodes_from_dict(d, position) 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. ## Returns a [Dictionary] representation of this deck.
func to_dict(with_meta: bool = true) -> Dictionary: func to_dict(with_meta: bool = true) -> Dictionary:
var inner := { var inner := {

View file

@ -30,3 +30,8 @@ static func open_deck_from_file(path: String) -> Deck:
## Unloads a deck. ## Unloads a deck.
static func close_deck(deck: Deck) -> void: static func close_deck(deck: Deck) -> void:
DeckHolder.decks.erase(deck) 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)

View file

@ -182,6 +182,10 @@ func remove_incoming_connection(to_port: int) -> void:
incoming_connection_removed.emit(to_port) incoming_connection_removed.emit(to_port)
func _event_received(event_name: StringName, event_data: Dictionary = {}) -> void:
pass
## Returns a list of all input ports. ## Returns a list of all input ports.
func get_input_ports() -> Array[Port]: func get_input_ports() -> Array[Port]:
return ports.filter( return ports.filter(

View file

@ -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

View file

@ -168,3 +168,6 @@ func _on_obs_websocket_setup_dialog_connect_button_pressed(state: OBSWebsocketSe
await no_obsws.connection_ready await no_obsws.connection_ready
obs_setup_dialog.set_button_state(OBSWebsocketSetupDialog.ConnectionState.CONNECTED) obs_setup_dialog.set_button_state(OBSWebsocketSetupDialog.ConnectionState.CONNECTED)
func _process(delta: float) -> void:
DeckHolder.send_event(&"process", {"delta": delta})

View file

@ -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.text_changed.connect(port.set_value.bind(code_edit.get_text))
code_edit.custom_minimum_size = Vector2(200, 100) code_edit.custom_minimum_size = Vector2(200, 100)
code_edit.size_flags_vertical = SIZE_EXPAND_FILL 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() var label := Label.new()
add_child(label) add_child(label)