equal
deleted
inserted
replaced
24 } |
24 } |
25 |
25 |
26 pub struct GameInfo { |
26 pub struct GameInfo { |
27 pub original_teams: Vec<(ClientId, TeamInfo)>, |
27 pub original_teams: Vec<(ClientId, TeamInfo)>, |
28 pub left_teams: Vec<String>, |
28 pub left_teams: Vec<String>, |
|
29 pub ingame_teams_count: u8, |
29 pub msg_log: Vec<String>, |
30 pub msg_log: Vec<String>, |
30 pub sync_msg: Option<String>, |
31 pub sync_msg: Option<String>, |
31 pub is_paused: bool, |
32 pub is_paused: bool, |
32 original_config: RoomConfig, |
33 original_config: RoomConfig, |
33 } |
34 } |
37 GameInfo { |
38 GameInfo { |
38 left_teams: Vec::new(), |
39 left_teams: Vec::new(), |
39 msg_log: Vec::new(), |
40 msg_log: Vec::new(), |
40 sync_msg: None, |
41 sync_msg: None, |
41 is_paused: false, |
42 is_paused: false, |
|
43 ingame_teams_count: teams.len() as u8, |
42 original_teams: teams, |
44 original_teams: teams, |
43 original_config: config, |
45 original_config: config, |
44 } |
46 } |
45 } |
47 } |
46 |
48 |
143 pub fn remove_team(&mut self, team_name: &str) { |
145 pub fn remove_team(&mut self, team_name: &str) { |
144 if let Some(index) = self.teams.iter().position(|(_, t)| t.name == team_name) { |
146 if let Some(index) = self.teams.iter().position(|(_, t)| t.name == team_name) { |
145 self.teams.remove(index); |
147 self.teams.remove(index); |
146 |
148 |
147 if let Some(info) = &mut self.game_info { |
149 if let Some(info) = &mut self.game_info { |
|
150 info.ingame_teams_count -= 1; |
148 info.left_teams.push(team_name.to_string()); |
151 info.left_teams.push(team_name.to_string()); |
149 |
152 |
150 if let Some(m) = &info.sync_msg { |
153 if let Some(m) = &info.sync_msg { |
151 info.msg_log.push(m.clone()); |
154 info.msg_log.push(m.clone()); |
152 info.sync_msg = None |
155 info.sync_msg = None |
171 } |
174 } |
172 names |
175 names |
173 } |
176 } |
174 |
177 |
175 pub fn teams_in_game(&self) -> Option<u8> { |
178 pub fn teams_in_game(&self) -> Option<u8> { |
176 self.game_info |
179 self.game_info.as_ref().map(|info| info.ingame_teams_count) |
177 .as_ref() |
|
178 .map(|info| (info.original_teams.len() - info.left_teams.len()) as u8) |
|
179 } |
180 } |
180 |
181 |
181 pub fn find_team_and_owner_mut<F>(&mut self, f: F) -> Option<(ClientId, &mut TeamInfo)> |
182 pub fn find_team_and_owner_mut<F>(&mut self, f: F) -> Option<(ClientId, &mut TeamInfo)> |
182 where |
183 where |
183 F: Fn(&TeamInfo) -> bool, |
184 F: Fn(&TeamInfo) -> bool, |