Compare commits

..

No commits in common. "e7f19d7686ae6938ab2fb8fe8811c426f0793bb8" and "c11911f75ff3535dfab1d1ae656cd6fdf71f554e" have entirely different histories.

4 changed files with 2 additions and 51 deletions

View File

@ -12,7 +12,7 @@ use crate::{
chat::{Chat, ChatMessage}, chat::{Chat, ChatMessage},
game::{ game::{
commands::{register_commands, unregister_commands}, commands::{register_commands, unregister_commands},
opts::{GameOption, GameOptionValue, GameOptions, PrivateGameOptions, TeamOptions}, opts::{GameOption, GameOptionValue, GameOptions, PrivateGameOptions},
}, },
map::Map, map::Map,
map_resource::MapResource, map_resource::MapResource,
@ -490,20 +490,6 @@ impl Game {
}); });
} }
pub fn change_team_option(&mut self, team: u8, opt: GameOption, value: GameOptionValue) {
if let Some(team) = self.opts.teams.get_mut(team as usize) {
team.values.insert(opt, value);
}
self.run_deferred(move |s| {
s.signals().options_changed().emit();
if let Some(peer) = &mut NetworkManager::singleton().bind_mut().peer {
if let PeerKind::Server(peer, _) = peer {
peer.broadcast_reliable(Package::TeamGameOptionChanged(team, opt, value));
}
}
});
}
pub fn change_map_selection(&mut self, map_idx: u8, force: bool) { pub fn change_map_selection(&mut self, map_idx: u8, force: bool) {
if self.selected_map_idx == map_idx && !force { if self.selected_map_idx == map_idx && !force {
return; return;
@ -511,7 +497,6 @@ impl Game {
self.selected_map_idx = map_idx; self.selected_map_idx = map_idx;
if let Some(map) = self.maps.get(map_idx as usize) { if let Some(map) = self.maps.get(map_idx as usize) {
self.selected_map = Some(map); self.selected_map = Some(map);
self.init_team_opts();
let teams_max = (self.get_teams().len() - 1) as u8; let teams_max = (self.get_teams().len() - 1) as u8;
self.run_deferred(move |s| { self.run_deferred(move |s| {
@ -527,16 +512,6 @@ impl Game {
} }
} }
fn init_team_opts(&mut self) {
let prev_settings = self.opts.teams.clone();
let mut new_settings = Vec::with_capacity(self.get_teams().len());
for (id, _) in self.get_teams().iter_shared().enumerate() {
let prev = prev_settings.get(id).cloned().unwrap_or_default();
new_settings.push(prev);
}
self.opts.teams = new_settings;
}
pub fn get_teams(&self) -> Array<Gd<TeamResource>> { pub fn get_teams(&self) -> Array<Gd<TeamResource>> {
if let Some(map) = &self.selected_map { if let Some(map) = &self.selected_map {
map.bind().teams.clone() map.bind().teams.clone()
@ -549,10 +524,6 @@ impl Game {
self.get_teams().get(team as usize) self.get_teams().get(team as usize)
} }
pub fn get_team_opts(&self, team: u8) -> Option<&TeamOptions> {
self.opts.teams.get(team as usize)
}
pub fn try_set_player_team(&mut self, player_id: u16, team: u8) { pub fn try_set_player_team(&mut self, player_id: u16, team: u8) {
if let Some(player) = self.find_player_mut(player_id) { if let Some(player) = self.find_player_mut(player_id) {
if player.data.team == team { if player.data.team == team {

View File

@ -10,7 +10,6 @@ pub struct PrivateGameOptions {
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GameOptions { pub struct GameOptions {
pub values: HashMap<GameOption, GameOptionValue>, pub values: HashMap<GameOption, GameOptionValue>,
pub teams: Vec<TeamOptions>,
} }
impl Default for GameOptions { impl Default for GameOptions {
@ -22,26 +21,10 @@ impl Default for GameOptions {
opts.insert(GameOption::GoalsNeededToWin, GameOptionValue::Number(5.)); opts.insert(GameOption::GoalsNeededToWin, GameOptionValue::Number(5.));
opts.insert(GameOption::RespawnTimer, GameOptionValue::Number(5.)); opts.insert(GameOption::RespawnTimer, GameOptionValue::Number(5.));
opts.insert(GameOption::SpawnProtection, GameOptionValue::Number(3.)); opts.insert(GameOption::SpawnProtection, GameOptionValue::Number(3.));
Self {
values: opts,
teams: Vec::new(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TeamOptions {
pub values: HashMap<GameOption, GameOptionValue>,
}
impl Default for TeamOptions {
fn default() -> Self {
let mut opts = HashMap::new();
opts.insert( opts.insert(
GameOption::TelegrenadesAllowed, GameOption::TelegrenadesAllowed,
GameOptionValue::Boolean(true), GameOptionValue::Boolean(true),
); );
opts.insert(GameOption::PickupsAllowed, GameOptionValue::Boolean(true));
Self { values: opts } Self { values: opts }
} }
} }
@ -88,8 +71,6 @@ pub enum GameOption {
RespawnTimer, RespawnTimer,
/// How long in seconds is spawn protected /// How long in seconds is spawn protected
SpawnProtection, SpawnProtection,
/// Whether pickups are allowed
PickupsAllowed,
} }
impl ToString for GameOption { impl ToString for GameOption {
@ -102,7 +83,6 @@ impl ToString for GameOption {
GameOption::TelegrenadesAllowed => "Telegrenades allowed", GameOption::TelegrenadesAllowed => "Telegrenades allowed",
GameOption::RespawnTimer => "Respawn Time (seconds)", GameOption::RespawnTimer => "Respawn Time (seconds)",
GameOption::SpawnProtection => "Spawn Protection", GameOption::SpawnProtection => "Spawn Protection",
GameOption::PickupsAllowed => "Pickups Allowed",
} }
.to_owned() .to_owned()
} }

View File

@ -323,7 +323,6 @@ pub enum Package {
SetTeam(u16, u8), SetTeam(u16, u8),
GameOptions(GameOptions), GameOptions(GameOptions),
GameOptionChanged(GameOption, GameOptionValue), GameOptionChanged(GameOption, GameOptionValue),
TeamGameOptionChanged(u8, GameOption, GameOptionValue),
ChatMessage(u16, String), ChatMessage(u16, String),
// Lobby packages // Lobby packages

View File

@ -27,6 +27,7 @@ impl TeamResource {
} }
pub fn color(&self) -> Color { pub fn color(&self) -> Color {
godot_print!("Fetching color");
if let Some(game) = Game::singleton() { if let Some(game) = Game::singleton() {
self.color_from(&game.bind().private_opts) self.color_from(&game.bind().private_opts)
} else { } else {