mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 10:14:06 +02:00
building fixes
This commit is contained in:
parent
a8893c4751
commit
cf58a0609a
1 changed files with 9 additions and 29 deletions
|
|
@ -14,6 +14,7 @@ use crate::demo::sendprop::{SendProp, SendPropIdentifier, SendPropValue};
|
|||
use crate::demo::vector::{Vector, VectorXY};
|
||||
use crate::{MessageType, ParserState, ReadResult, Stream};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::BTreeMap;
|
||||
use std::convert::TryFrom;
|
||||
use std::str::FromStr;
|
||||
|
||||
|
|
@ -256,7 +257,7 @@ impl Kill {
|
|||
#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct GameState {
|
||||
pub players: Vec<Player>,
|
||||
pub buildings: Vec<Building>,
|
||||
pub buildings: BTreeMap<EntityId, Building>,
|
||||
pub world: Option<World>,
|
||||
pub kills: Vec<Kill>,
|
||||
pub tick: u32,
|
||||
|
|
@ -289,37 +290,13 @@ impl GameState {
|
|||
entity_id: EntityId,
|
||||
class: BuildingClass,
|
||||
) -> &mut Building {
|
||||
let index = match self
|
||||
.buildings
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(_index, building)| building.entity_id() == entity_id)
|
||||
.map(|(index, _)| index)
|
||||
{
|
||||
Some(index) => index,
|
||||
None => {
|
||||
let index = self.buildings.len();
|
||||
self.buildings.push(Building::new(entity_id, class));
|
||||
index
|
||||
}
|
||||
};
|
||||
|
||||
&mut self.buildings[index]
|
||||
self.buildings
|
||||
.entry(entity_id)
|
||||
.or_insert_with(|| Building::new(entity_id, class))
|
||||
}
|
||||
|
||||
pub fn remove_building(&mut self, entity_id: EntityId) {
|
||||
match self
|
||||
.buildings
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(_index, building)| building.entity_id() == entity_id)
|
||||
.map(|(index, _)| index)
|
||||
{
|
||||
Some(index) => {
|
||||
self.buildings.remove(index);
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
self.buildings.remove(&entity_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -354,6 +331,9 @@ impl MessageHandler for GameStateAnalyser {
|
|||
GameEvent::RoundStart(_) => {
|
||||
self.state.buildings.clear();
|
||||
}
|
||||
GameEvent::TeamPlayRoundStart(_) => {
|
||||
self.state.buildings.clear();
|
||||
}
|
||||
GameEvent::ObjectDestroyed(ObjectDestroyedEvent { index, .. }) => {
|
||||
self.state.remove_building((*index as u32).into());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue