Compare commits
2 Commits
c11911f75f
...
e7f19d7686
| Author | SHA1 | Date | |
|---|---|---|---|
| e7f19d7686 | |||
| 4aa60ba6a4 |
@ -12,7 +12,7 @@ use crate::{
|
||||
chat::{Chat, ChatMessage},
|
||||
game::{
|
||||
commands::{register_commands, unregister_commands},
|
||||
opts::{GameOption, GameOptionValue, GameOptions, PrivateGameOptions},
|
||||
opts::{GameOption, GameOptionValue, GameOptions, PrivateGameOptions, TeamOptions},
|
||||
},
|
||||
map::Map,
|
||||
map_resource::MapResource,
|
||||
@ -490,6 +490,20 @@ 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) {
|
||||
if self.selected_map_idx == map_idx && !force {
|
||||
return;
|
||||
@ -497,6 +511,7 @@ impl Game {
|
||||
self.selected_map_idx = map_idx;
|
||||
if let Some(map) = self.maps.get(map_idx as usize) {
|
||||
self.selected_map = Some(map);
|
||||
self.init_team_opts();
|
||||
|
||||
let teams_max = (self.get_teams().len() - 1) as u8;
|
||||
self.run_deferred(move |s| {
|
||||
@ -512,6 +527,16 @@ 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>> {
|
||||
if let Some(map) = &self.selected_map {
|
||||
map.bind().teams.clone()
|
||||
@ -524,6 +549,10 @@ impl Game {
|
||||
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) {
|
||||
if let Some(player) = self.find_player_mut(player_id) {
|
||||
if player.data.team == team {
|
||||
|
||||
@ -10,6 +10,7 @@ pub struct PrivateGameOptions {
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct GameOptions {
|
||||
pub values: HashMap<GameOption, GameOptionValue>,
|
||||
pub teams: Vec<TeamOptions>,
|
||||
}
|
||||
|
||||
impl Default for GameOptions {
|
||||
@ -21,10 +22,26 @@ impl Default for GameOptions {
|
||||
opts.insert(GameOption::GoalsNeededToWin, GameOptionValue::Number(5.));
|
||||
opts.insert(GameOption::RespawnTimer, GameOptionValue::Number(5.));
|
||||
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(
|
||||
GameOption::TelegrenadesAllowed,
|
||||
GameOptionValue::Boolean(true),
|
||||
);
|
||||
opts.insert(GameOption::PickupsAllowed, GameOptionValue::Boolean(true));
|
||||
Self { values: opts }
|
||||
}
|
||||
}
|
||||
@ -71,6 +88,8 @@ pub enum GameOption {
|
||||
RespawnTimer,
|
||||
/// How long in seconds is spawn protected
|
||||
SpawnProtection,
|
||||
/// Whether pickups are allowed
|
||||
PickupsAllowed,
|
||||
}
|
||||
|
||||
impl ToString for GameOption {
|
||||
@ -83,6 +102,7 @@ impl ToString for GameOption {
|
||||
GameOption::TelegrenadesAllowed => "Telegrenades allowed",
|
||||
GameOption::RespawnTimer => "Respawn Time (seconds)",
|
||||
GameOption::SpawnProtection => "Spawn Protection",
|
||||
GameOption::PickupsAllowed => "Pickups Allowed",
|
||||
}
|
||||
.to_owned()
|
||||
}
|
||||
|
||||
@ -323,6 +323,7 @@ pub enum Package {
|
||||
SetTeam(u16, u8),
|
||||
GameOptions(GameOptions),
|
||||
GameOptionChanged(GameOption, GameOptionValue),
|
||||
TeamGameOptionChanged(u8, GameOption, GameOptionValue),
|
||||
ChatMessage(u16, String),
|
||||
|
||||
// Lobby packages
|
||||
|
||||
@ -27,7 +27,6 @@ impl TeamResource {
|
||||
}
|
||||
|
||||
pub fn color(&self) -> Color {
|
||||
godot_print!("Fetching color");
|
||||
if let Some(game) = Game::singleton() {
|
||||
self.color_from(&game.bind().private_opts)
|
||||
} else {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user