diff --git a/rust/src/game_manager.rs b/rust/src/game_manager.rs index f31c457..216a144 100644 --- a/rust/src/game_manager.rs +++ b/rust/src/game_manager.rs @@ -37,8 +37,6 @@ pub const GAME_MANAGER_GLOBAL: &str = "GameManagerGlobal"; #[derive(GodotClass)] #[class(base=Node, init)] pub struct GameManager { - #[export] - pub respawn_timer: f64, #[export] pub lobby_screen: Option>, #[export] @@ -96,7 +94,6 @@ impl GameManager { let mut game = Game::new_alloc(); game.bind_mut().is_host = is_host; game.bind_mut().maps = self.maps.clone(); - game.bind_mut().respawn_timer = self.respawn_timer; self.run_deferred(|s| { if let Some(game) = &s.game { @@ -166,7 +163,8 @@ impl Default for GameOptions { opts.insert(GameOption::AllowAnyMap, GameOptionValue::Boolean(false)); opts.insert(GameOption::AllowAnyTeam, GameOptionValue::Boolean(false)); opts.insert(GameOption::FriendlyFire, GameOptionValue::Boolean(true)); - opts.insert(GameOption::GoalsNeededToWin, GameOptionValue::Number(10.)); + opts.insert(GameOption::GoalsNeededToWin, GameOptionValue::Number(5.)); + opts.insert(GameOption::RespawnTimer, GameOptionValue::Number(5.)); opts.insert( GameOption::TelegrenadesAllowed, GameOptionValue::Boolean(true), @@ -187,6 +185,18 @@ impl GameOptions { _ => false, } } + + pub fn get_float(&self, opt: GameOption) -> f64 { + let opt = self + .values + .get(&opt) + .copied() + .unwrap_or(GameOptionValue::Number(0.)); + match opt { + GameOptionValue::Number(value) => value, + _ => 0., + } + } } #[derive(Debug, PartialEq, Eq, PartialOrd, Hash, Copy, Clone, Serialize, Deserialize)] @@ -201,6 +211,8 @@ pub enum GameOption { GoalsNeededToWin, /// Whether telegrenades are allowed or not. TelegrenadesAllowed, + /// How long in seconds does it take for a player to respawn + RespawnTimer, } impl ToString for GameOption { @@ -211,6 +223,7 @@ impl ToString for GameOption { GameOption::FriendlyFire => "Friendly fire", GameOption::GoalsNeededToWin => "Goals needed to win", GameOption::TelegrenadesAllowed => "Telegrenades allowed", + GameOption::RespawnTimer => "Respawn Time (seconds)", } .to_owned() } @@ -238,9 +251,6 @@ impl Command for RespawnBallCommand { #[derive(GodotClass)] #[class(base=Node, init)] pub struct Game { - #[export] - pub respawn_timer: f64, - pub selected_map_idx: u8, pub selected_map: Option>, pub maps: Array>, @@ -338,7 +348,9 @@ impl INode for Game { for player in self.players.clone() { let player_id = player.id(); if let Some(character) = player.character { - if character.dyn_bind().dead_for() > self.respawn_timer { + if character.dyn_bind().dead_for() + > self.opts.get_float(GameOption::RespawnTimer) + { let character = self.spawn_player_server(player_id); if let Some(character) = character { diff --git a/rust/src/player/local_player.rs b/rust/src/player/local_player.rs index ef0b6b2..88a3295 100644 --- a/rust/src/player/local_player.rs +++ b/rust/src/player/local_player.rs @@ -423,7 +423,7 @@ impl ICharacterBody3D for LocalPlayer { if let Some(label) = &mut self.respawn_label { let respawn_timer = if let Some(game) = Game::singleton() { - game.bind().respawn_timer + game.bind().opts.get_float(GameOption::RespawnTimer) } else { 0. };