From 3f5a4419725fbbf388aa6827ef5081992a47f68c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Fri, 15 Mar 2024 07:47:45 +0000 Subject: [PATCH] add a map of operation types to event names to RPCScope (#108) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #104 Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/108 Co-authored-by: Lera ElvoƩ Co-committed-by: Lera ElvoƩ --- rpc_renderer/rpc_scope.gd | 2 +- rpc_renderer/scopes/scope_deck.gd | 36 +++++++++++----------- rpc_renderer/scopes/scope_deck_holder.gd | 6 ++-- rpc_renderer/types/rpc_request_response.gd | 5 +-- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/rpc_renderer/rpc_scope.gd b/rpc_renderer/rpc_scope.gd index 16d5717..0b80e2c 100644 --- a/rpc_renderer/rpc_scope.gd +++ b/rpc_renderer/rpc_scope.gd @@ -27,7 +27,7 @@ func can_handle_request(request: RPCRequest) -> bool: ## Wrapper function to handle a request. See [param operation_types]. func handle_request(request: RPCRequest) -> void: - var c: Callable = operation_types[request.operation.type] + var c: Callable = operation_types[request.operation.type].callable c.call(request) diff --git a/rpc_renderer/scopes/scope_deck.gd b/rpc_renderer/scopes/scope_deck.gd index 95e57b2..cdaace5 100644 --- a/rpc_renderer/scopes/scope_deck.gd +++ b/rpc_renderer/scopes/scope_deck.gd @@ -8,22 +8,22 @@ func _init() -> void: name = "deck" operation_types = { - "add_node": add_node, - "remove_node": remove_node, - "get_node": get_node, + "add_node": {"callable": add_node, "event_name": "node_added"}, + "remove_node": {"callable": remove_node, "event_name": "node_removed"}, + "get_node": {"callable": get_node, "event_name": ""}, - "is_valid_connection": is_valid_connection, - "connect_nodes": connect_nodes, - "disconnect_nodes": disconnect_nodes, + "is_valid_connection": {"callable": is_valid_connection, "event_name": ""}, + "connect_nodes": {"callable": connect_nodes, "event_name": "nodes_connected"}, + "disconnect_nodes": {"callable": disconnect_nodes, "event_name": "nodes_disconnected"}, - "group_nodes": group_nodes, + "group_nodes": {"callable": group_nodes, "event_name": "nodes_grouped"}, - "set_variable": set_variable, - "get_variable": get_variable, - "get_variable_list": get_variable_list, + "set_variable": {"callable": set_variable, "event_name": ""}, + "get_variable": {"callable": get_variable, "event_name": ""}, + "get_variable_list": {"callable": get_variable_list, "event_name": ""}, - "send_event": send_event, - "get_referenced_groups": get_referenced_groups, + "send_event": {"callable": send_event, "event_name": ""}, + "get_referenced_groups": {"callable": get_referenced_groups, "event_name": ""}, } RPCSignalLayer.signals.deck_node_added.connect(_on_deck_node_added) @@ -47,7 +47,7 @@ func add_node(r: RPCRequest) -> void: node_partial.id = node._id var resp := create_response(r, node_partial) - resp.create_event_counterpart(node_partial) + resp.create_event_counterpart(node_partial, operation_types) response.emit(resp) ) @@ -67,7 +67,7 @@ func remove_node(r: RPCRequest) -> void: node_partial.id = node_id var resp := create_generic_success(r) - resp.create_event_counterpart(node_partial) + resp.create_event_counterpart(node_partial, operation_types) response.emit(resp) ) @@ -113,7 +113,7 @@ func connect_nodes(r: RPCRequest) -> void: connection.from_output_port = from_output_port connection.to_input_port = to_input_port var resp := create_generic_success(r) - resp.create_event_counterpart(connection) + resp.create_event_counterpart(connection, operation_types) response.emit(resp) else: var err := create_generic_failure(r) @@ -141,7 +141,7 @@ func disconnect_nodes(r: RPCRequest) -> void: connection.to_input_port = to_input_port var resp := create_generic_success(r) - resp.create_event_counterpart(connection) + resp.create_event_counterpart(connection, operation_types) response.emit(resp) ) @@ -164,7 +164,7 @@ func group_nodes(r: RPCRequest) -> void: else: var dp := RPCDeckPartial.new(group) var resp := create_response(r, dp) - resp.create_event_counterpart(node_ids) + resp.create_event_counterpart(node_ids, operation_types) response.emit(resp) ) @@ -180,7 +180,7 @@ func set_variable(r: RPCRequest) -> void: deck.set_variable(var_name, var_value) var resp := create_generic_success(r) - resp.create_event_counterpart({}) + resp.create_event_counterpart({}, operation_types) response.emit(resp) ) diff --git a/rpc_renderer/scopes/scope_deck_holder.gd b/rpc_renderer/scopes/scope_deck_holder.gd index caf4de9..64e4ed6 100644 --- a/rpc_renderer/scopes/scope_deck_holder.gd +++ b/rpc_renderer/scopes/scope_deck_holder.gd @@ -9,8 +9,8 @@ func _init() -> void: operation_types = { #"new_deck": new_deck, # TODO: evaluate later - "get_deck": get_deck, - "send_event": send_event, + "get_deck": {"callable": get_deck, "event_name": ""}, + "send_event": {"callable": send_event, "event_name": ""}, } RPCSignalLayer.signals.deck_added.connect(_on_deck_holder_deck_added) @@ -25,7 +25,7 @@ func new_deck(r: RPCRequest) -> void: var deck_partial := RPCDeckPartial.new() deck_partial.id = DeckHolder.add_empty_deck().id var resp := create_response(r, deck_partial) - resp.create_event_counterpart(deck_partial) + resp.create_event_counterpart(deck_partial, operation_types) response.emit(resp) ) diff --git a/rpc_renderer/types/rpc_request_response.gd b/rpc_renderer/types/rpc_request_response.gd index f2e7442..c1e27aa 100644 --- a/rpc_renderer/types/rpc_request_response.gd +++ b/rpc_renderer/types/rpc_request_response.gd @@ -39,5 +39,6 @@ func _init(p_request: RPCRequest) -> void: ] -func create_event_counterpart(data: Variant) -> void: - event_counterpart = RPCEvent.new(request.operation.type, scope, data, request.operation.condition) +func create_event_counterpart(data: Variant, operation_types: Dictionary) -> void: + var event_name: String = (operation_types[request.operation.type] as Dictionary).get("event_name", request.operation.type) + event_counterpart = RPCEvent.new(event_name, scope, data, request.operation.condition)