From 8835f326b1b8ae0727727fec93ddb1e871571f32 Mon Sep 17 00:00:00 2001 From: Ryan <73148864+Ryan-000@users.noreply.github.com> Date: Sat, 24 Aug 2024 01:58:54 -0400 Subject: [PATCH] Expose get_rpc_config and get_node_rpc_config add documentation Update doc/classes/Node.xml change name of get_node_rpc_config to get_rpc_config Co-Authored-By: moondog <159832633+dog-on-moon@users.noreply.github.com> Co-Authored-By: Micky <66727710+Mickeon@users.noreply.github.com> --- core/object/script_language.cpp | 2 ++ core/object/script_language.h | 2 +- core/object/script_language_extension.h | 2 +- doc/classes/Node.xml | 6 ++++++ doc/classes/Script.xml | 6 ++++++ modules/gdscript/gdscript.cpp | 2 +- modules/gdscript/gdscript.h | 2 +- modules/mono/csharp_script.cpp | 2 +- modules/mono/csharp_script.h | 2 +- modules/multiplayer/scene_rpc_interface.cpp | 2 +- scene/main/node.cpp | 3 ++- scene/main/node.h | 4 ++-- 12 files changed, 25 insertions(+), 10 deletions(-) diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp index cdc56e5ec51..652e3164c64 100644 --- a/core/object/script_language.cpp +++ b/core/object/script_language.cpp @@ -173,6 +173,8 @@ void Script::_bind_methods() { ClassDB::bind_method(D_METHOD("is_tool"), &Script::is_tool); ClassDB::bind_method(D_METHOD("is_abstract"), &Script::is_abstract); + ClassDB::bind_method(D_METHOD("get_rpc_config"), &Script::get_rpc_config); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "source_code", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_source_code", "get_source_code"); } diff --git a/core/object/script_language.h b/core/object/script_language.h index 59a43a7b297..2238a29649f 100644 --- a/core/object/script_language.h +++ b/core/object/script_language.h @@ -180,7 +180,7 @@ public: virtual bool is_placeholder_fallback_enabled() const { return false; } - virtual const Variant get_rpc_config() const = 0; + virtual Variant get_rpc_config() const = 0; Script() {} }; diff --git a/core/object/script_language_extension.h b/core/object/script_language_extension.h index c9344f5799b..bc773c5ad34 100644 --- a/core/object/script_language_extension.h +++ b/core/object/script_language_extension.h @@ -205,7 +205,7 @@ public: GDVIRTUAL0RC(Variant, _get_rpc_config) - virtual const Variant get_rpc_config() const override { + virtual Variant get_rpc_config() const override { Variant ret; GDVIRTUAL_REQUIRED_CALL(_get_rpc_config, ret); return ret; diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml index c54219c0566..2d309f62165 100644 --- a/doc/classes/Node.xml +++ b/doc/classes/Node.xml @@ -498,6 +498,12 @@ Returns the time elapsed (in seconds) since the last process callback. This value is identical to [method _process]'s [code]delta[/code] parameter, and may vary from frame to frame. See also [constant NOTIFICATION_PROCESS]. + + + + Returns a [Dictionary] mapping method names to their RPC configuration defined for this node using [method rpc_config]. + + diff --git a/doc/classes/Script.xml b/doc/classes/Script.xml index 45f0bbb8aac..80aad9d30d1 100644 --- a/doc/classes/Script.xml +++ b/doc/classes/Script.xml @@ -58,6 +58,12 @@ Returns the default value of the specified property. + + + + Returns a [Dictionary] mapping method names to their RPC configuration defined by this script. + + diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 7bf5e946fbb..663838932be 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -904,7 +904,7 @@ void GDScript::get_members(HashSet *p_members) { } } -const Variant GDScript::get_rpc_config() const { +Variant GDScript::get_rpc_config() const { return rpc_config; } diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h index 6527a0ea4dc..4ff57d1c2e3 100644 --- a/modules/gdscript/gdscript.h +++ b/modules/gdscript/gdscript.h @@ -334,7 +334,7 @@ public: virtual void get_constants(HashMap *p_constants) override; virtual void get_members(HashSet *p_members) override; - virtual const Variant get_rpc_config() const override; + virtual Variant get_rpc_config() const override; void unload_static() const; diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 6d561c15663..cb9d9dc8fbd 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -2716,7 +2716,7 @@ int CSharpScript::get_member_line(const StringName &p_member) const { return -1; } -const Variant CSharpScript::get_rpc_config() const { +Variant CSharpScript::get_rpc_config() const { return rpc_config; } diff --git a/modules/mono/csharp_script.h b/modules/mono/csharp_script.h index c48e1a95c98..ec7328be4a4 100644 --- a/modules/mono/csharp_script.h +++ b/modules/mono/csharp_script.h @@ -284,7 +284,7 @@ public: int get_member_line(const StringName &p_member) const override; - const Variant get_rpc_config() const override; + Variant get_rpc_config() const override; #ifdef TOOLS_ENABLED bool is_placeholder_fallback_enabled() const override { diff --git a/modules/multiplayer/scene_rpc_interface.cpp b/modules/multiplayer/scene_rpc_interface.cpp index 1463598ddc6..5e1067a8a4f 100644 --- a/modules/multiplayer/scene_rpc_interface.cpp +++ b/modules/multiplayer/scene_rpc_interface.cpp @@ -108,7 +108,7 @@ const SceneRPCInterface::RPCConfigCache &SceneRPCInterface::_get_node_config(con return rpc_cache[oid]; } RPCConfigCache cache; - _parse_rpc_config(p_node->get_node_rpc_config(), true, cache); + _parse_rpc_config(p_node->get_rpc_config(), true, cache); if (p_node->get_script_instance()) { _parse_rpc_config(p_node->get_script_instance()->get_rpc_config(), false, cache); } diff --git a/scene/main/node.cpp b/scene/main/node.cpp index de6d49761b5..488acd2ed18 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -757,7 +757,7 @@ void Node::rpc_config(const StringName &p_method, const Variant &p_config) { } } -const Variant Node::get_node_rpc_config() const { +Variant Node::get_rpc_config() const { return data.rpc_config; } @@ -3640,6 +3640,7 @@ void Node::_bind_methods() { ClassDB::bind_method(D_METHOD("get_multiplayer"), &Node::get_multiplayer); ClassDB::bind_method(D_METHOD("rpc_config", "method", "config"), &Node::rpc_config); + ClassDB::bind_method(D_METHOD("get_rpc_config"), &Node::get_rpc_config); ClassDB::bind_method(D_METHOD("set_editor_description", "editor_description"), &Node::set_editor_description); ClassDB::bind_method(D_METHOD("get_editor_description"), &Node::get_editor_description); diff --git a/scene/main/node.h b/scene/main/node.h index 2f6372dad58..7d42af71416 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -199,7 +199,7 @@ private: void *process_group = nullptr; // to avoid cyclic dependency int multiplayer_authority = 1; // Server by default. - Variant rpc_config; + Variant rpc_config = Dictionary(); // Variables used to properly sort the node when processing, ignored otherwise. int process_priority = 0; @@ -717,7 +717,7 @@ public: bool is_multiplayer_authority() const; void rpc_config(const StringName &p_method, const Variant &p_config); // config a local method for RPC - const Variant get_node_rpc_config() const; + Variant get_rpc_config() const; template Error rpc(const StringName &p_method, VarArgs... p_args);