Skip to content

Commit

Permalink
Move RpcConfig from godot::meta -> godot::register
Browse files Browse the repository at this point in the history
  • Loading branch information
Bromeon committed Nov 10, 2024
1 parent e2f1097 commit ee5410d
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 8 deletions.
3 changes: 3 additions & 0 deletions godot-codegen/src/special_cases/special_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ pub fn maybe_rename_virtual_method(rust_method_name: &str) -> &str {
}
}

// TODO method-level extra docs, for:
// - Node::rpc_config() -> link to RpcConfig.

pub fn get_class_extra_docs(class_name: &TyName) -> Option<&'static str> {
match class_name.godot_ty.as_str() {
"FileAccess" => {
Expand Down
5 changes: 0 additions & 5 deletions godot-core/src/meta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ mod class_name;
mod godot_convert;
mod method_info;
mod property_info;
// RpcConfig uses MultiplayerPeer::TransferMode and MultiplayerApi::RpcMode, which are only enabled in `codegen-full` feature.
#[cfg(feature = "codegen-full")]
mod rpc_config;
mod sealed;
mod signature;
mod traits;
Expand All @@ -61,8 +58,6 @@ pub mod error;
pub use args::*;
pub use class_name::ClassName;
pub use godot_convert::{FromGodot, GodotConvert, ToGodot};
#[cfg(feature = "codegen-full")]
pub use rpc_config::RpcConfig;
pub use traits::{ArrayElement, GodotType, PackedArrayElement};

pub(crate) use array_type_info::ArrayTypeInfo;
Expand Down
8 changes: 7 additions & 1 deletion godot-core/src/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

// Note: final re-exports from godot-core are in lib.rs, mod private_register.
// Note: final re-exports from godot-core are in lib.rs, mod register::private.
// These are public here for simplicity, but many are not imported by the main crate.

pub mod callbacks;
Expand All @@ -15,5 +15,11 @@ pub mod method;
pub mod plugin;
pub mod property;

// RpcConfig uses MultiplayerPeer::TransferMode and MultiplayerApi::RpcMode, which are only enabled in `codegen-full` feature.
#[cfg(feature = "codegen-full")]
mod rpc_config;
#[cfg(feature = "codegen-full")]
pub use rpc_config::RpcConfig;

#[doc(hidden)]
pub mod godot_register_wrappers;
File renamed without changes.
3 changes: 2 additions & 1 deletion godot-macros/src/class/data_models/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub enum RpcAttr {
call_local: Option<bool>,
channel: Option<u32>,
},

// `args` key in the `rpc` attribute.
// Example:
// const RPC_CFG: RpcConfig = RpcConfig { mode: RpcMode::Authority, ..RpcConfig::default() };
Expand Down Expand Up @@ -76,7 +77,7 @@ pub fn make_rpc_registrations_fn(class_name: &Ident, funcs: &[FuncDefinition]) -
#[allow(clippy::needless_update)] // clippy complains about using `..RpcConfig::default()` if all fields are overridden
fn __register_rpcs(object: &mut dyn ::std::any::Any) {
use ::std::any::Any;
use ::godot::meta::RpcConfig;
use ::godot::register::RpcConfig;
use ::godot::classes::multiplayer_api::RpcMode;
use ::godot::classes::multiplayer_peer::TransferMode;
use ::godot::classes::Node;
Expand Down
8 changes: 8 additions & 0 deletions godot-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ pub fn derive_godot_class(input: TokenStream) -> TokenStream {
/// - [User-defined functions](#user-defined-functions)
/// - [Associated functions and methods](#associated-functions-and-methods)
/// - [Virtual methods](#virtual-methods)
/// - [RPC attributes](#rpc-attributes)
/// - [Constants and signals](#signals)
///
/// # Constructors
Expand Down Expand Up @@ -676,6 +677,13 @@ pub fn derive_godot_class(input: TokenStream) -> TokenStream {
///
/// Make sure you understand the limitations in the [tutorial](https://godot-rust.github.io/book/register/virtual-functions.html).
///
/// ## RPC attributes
///
/// You can use the `#[rpc]` attribute to let your functions act as remote procedure calls (RPCs) in Godot. This is the Rust equivalent of
/// GDScript's [`@rpc` annotation](https://docs.godotengine.org/en/stable/tutorials/networking/high_level_multiplayer.html#remote-procedure-calls).
///
///
///
/// # Constants and signals
///
/// Please refer to [the book](https://godot-rust.github.io/book/register/constants.html).
Expand Down
4 changes: 4 additions & 0 deletions godot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,15 @@ pub mod register {
pub use godot_core::registry::property;
pub use godot_macros::{godot_api, Export, GodotClass, GodotConvert, Var};

#[cfg(feature = "__codegen-full")]
pub use godot_core::registry::RpcConfig;

/// Re-exports used by proc-macro API.
#[doc(hidden)]
pub mod private {
#[cfg(feature = "__codegen-full")]
pub use godot_core::registry::class::auto_register_rpcs;

pub use godot_core::registry::godot_register_wrappers::*;
pub use godot_core::registry::{constant, method};
}
Expand Down
3 changes: 2 additions & 1 deletion itest/rust/src/register_tests/rpc_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

use godot::classes::multiplayer_api::RpcMode;
use godot::classes::multiplayer_peer::TransferMode;
use godot::classes::{Engine, MultiplayerApi};
use godot::meta::RpcConfig;
use godot::prelude::*;
use godot::register::RpcConfig;
use godot::test::itest;

#[derive(GodotClass)]
Expand Down

0 comments on commit ee5410d

Please sign in to comment.