use crate::builtin::{StringName, VarDictionary};
use crate::classes::Node;
use crate::classes::multiplayer_api::RpcMode;
use crate::classes::multiplayer_peer::TransferMode;
use crate::meta::{AsArg, ToGodot};
use crate::{arg_into_ref, vdict};
#[derive(Copy, Clone, Debug)]
pub struct RpcConfig {
pub rpc_mode: RpcMode,
pub transfer_mode: TransferMode,
pub call_local: bool,
pub channel: u32,
}
impl Default for RpcConfig {
fn default() -> Self {
Self {
rpc_mode: RpcMode::AUTHORITY,
transfer_mode: TransferMode::UNRELIABLE,
call_local: false,
channel: 0,
}
}
}
impl RpcConfig {
pub fn configure_node(self, node: &mut Node, method_name: impl AsArg<StringName>) {
arg_into_ref!(method_name);
node.rpc_config(method_name, &self.to_dictionary().to_variant());
}
pub fn to_dictionary(&self) -> VarDictionary {
vdict! {
"rpc_mode" => self.rpc_mode,
"transfer_mode" => self.transfer_mode,
"call_local" => self.call_local,
"channel" => self.channel,
}
}
}