miggor-StreamGraph/rpc_renderer/scopes/scope_deck.gd

67 lines
2.2 KiB
GDScript3
Raw Normal View History

# (c) 2023-present Eroax
# (c) 2023-present Yagich
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
extends RPCScope
func _init() -> void:
name = "deck"
operation_types = {
"add_node": add_node,
}
RPCSignalLayer.signals.deck_node_added.connect(_on_deck_node_added)
RPCSignalLayer.signals.deck_node_removed.connect(_on_deck_node_removed)
RPCSignalLayer.signals.deck_nodes_connected.connect(_on_deck_nodes_connected)
RPCSignalLayer.signals.deck_nodes_disconnected.connect(_on_deck_nodes_disconnected)
func add_node(r: RPCRequest) -> void:
reconnect(
RPCSignalLayer.signals.deck_node_added,
_on_deck_node_added,
func():
var deck := DeckHolder.get_deck(r.operation.condition.deck_id)
var node := deck.add_node_type(r.operation.payload.node_type)
var node_partial := RPCNodePartial.new()
node_partial.deck_id = deck.id
node_partial.id = node._id
var resp := create_response(r, node_partial)
resp.create_event_counterpart(node_partial)
response.emit(resp)
)
func _on_deck_node_added(deck_id: String, node_id: String) -> void:
event.emit(create_event("node_added", {"node_id": node_id}, {"deck_id": deck_id}))
func _on_deck_node_removed(deck_id: String, node_id: String) -> void:
event.emit(create_event("node_removed", {"node_id": node_id}, {"deck_id": deck_id}))
func _on_deck_nodes_connected(deck_id: String, from_node_id: String, to_node_id: String, from_output_port: int, to_input_port: int) -> void:
var connection := RPCNodeConnection.new()
connection.from_node_id = from_node_id
connection.to_node_id = to_node_id
connection.from_output_port = from_output_port
connection.to_input_port = to_input_port
var ev := create_event("nodes_connected", connection, {"deck_id": deck_id})
event.emit(ev)
func _on_deck_nodes_disconnected(deck_id: String, from_node_id: String, to_node_id: String, from_output_port: int, to_input_port: int) -> void:
var connection := RPCNodeConnection.new()
connection.from_node_id = from_node_id
connection.to_node_id = to_node_id
connection.from_output_port = from_output_port
connection.to_input_port = to_input_port
var ev := create_event("nodes_disconnected", connection, {"deck_id": deck_id})
event.emit(ev)