11use num_enum:: TryFromPrimitive ;
2- use serde:: { ser:: SerializeMap , Deserialize , Serialize , Serializer } ;
3- use serde_repr:: { Deserialize_repr , Serialize_repr } ;
2+ use serde:: { Deserialize , Serialize } ;
43use std:: collections:: { BTreeMap , HashMap } ;
54use std:: convert:: TryFrom ;
6- use std:: ops:: { Index , IndexMut } ;
75use std:: str:: FromStr ;
86use tf_demo_parser:: demo:: gameevent_gen:: { GameEvent , PlayerDeathEvent , PlayerSpawnEvent , TeamPlayRoundWinEvent } ;
97use tf_demo_parser:: demo:: message:: packetentities:: { EntityId , PacketEntity } ;
@@ -66,7 +64,7 @@ impl Default for Team {
6664 }
6765}
6866
69- #[ derive( Debug , Clone , Serialize_repr , Deserialize_repr , Copy , PartialEq , Eq , Hash , TryFromPrimitive ) ]
67+ #[ derive( Debug , Clone , Serialize , Deserialize , Copy , PartialEq , Eq , Hash , TryFromPrimitive ) ]
7068#[ repr( u8 ) ]
7169pub enum Class {
7270 Other = 0 ,
@@ -96,55 +94,6 @@ impl Default for Class {
9694 }
9795}
9896
99- #[ derive( Default , Debug , Eq , PartialEq , Deserialize , Clone ) ]
100- #[ serde( from = "HashMap<Class, u8>" ) ]
101- pub struct ClassList ( [ u8 ; 10 ] ) ;
102-
103- impl Index < Class > for ClassList {
104- type Output = u8 ;
105-
106- #[ cfg_attr( feature = "no-panic" , no_panic:: no_panic) ]
107- fn index ( & self , class : Class ) -> & Self :: Output {
108- & self . 0 [ class as u8 as usize ]
109- }
110- }
111-
112- impl IndexMut < Class > for ClassList {
113- #[ cfg_attr( feature = "no-panic" , no_panic:: no_panic) ]
114- fn index_mut ( & mut self , class : Class ) -> & mut Self :: Output {
115- & mut self . 0 [ class as u8 as usize ]
116- }
117- }
118-
119- impl Serialize for ClassList {
120- fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
121- where
122- S : Serializer ,
123- {
124- let count = self . 0 . iter ( ) . filter ( |c| * * c > 0 ) . count ( ) ;
125- let mut classes = serializer. serialize_map ( Some ( count) ) ?;
126- for ( class, count) in self . 0 . iter ( ) . copied ( ) . enumerate ( ) {
127- if count > 0 {
128- classes. serialize_entry ( & class, & count) ?;
129- }
130- }
131-
132- classes. end ( )
133- }
134- }
135-
136- impl From < HashMap < Class , u8 > > for ClassList {
137- fn from ( map : HashMap < Class , u8 > ) -> Self {
138- let mut classes = ClassList :: default ( ) ;
139-
140- for ( class, count) in map. into_iter ( ) {
141- classes[ class] = count;
142- }
143-
144- classes
145- }
146- }
147-
14897#[ derive( Debug , Clone , Serialize , Deserialize , Copy , PartialEq , Eq , Hash , Ord , PartialOrd ) ]
14998pub struct UserId ( u32 ) ;
15099
@@ -182,7 +131,6 @@ impl Spawn {
182131#[ derive( Debug , Clone , Serialize , Deserialize ) ]
183132#[ serde( rename_all = "camelCase" ) ]
184133pub struct UserInfo {
185- pub classes : ClassList ,
186134 pub name : String ,
187135 pub user_id : UserId ,
188136 pub steam_id : String ,
@@ -192,7 +140,7 @@ pub struct UserInfo {
192140
193141impl PartialEq for UserInfo {
194142 fn eq ( & self , other : & UserInfo ) -> bool {
195- self . classes == other . classes && self . name == other. name && self . user_id == other. user_id && self . steam_id == other. steam_id && self . team == other. team
143+ self . name == other. name && self . user_id == other. user_id && self . steam_id == other. steam_id && self . team == other. team
196144 }
197145}
198146
@@ -480,7 +428,6 @@ impl HeatmapAnalyser {
480428 GameEvent :: PlayerSpawn ( event) => {
481429 let spawn = Spawn :: from_event ( event, tick) ;
482430 if let Some ( user_state) = self . state . users . get_mut ( & spawn. user ) {
483- user_state. classes [ spawn. class ] += 1 ;
484431 user_state. team = spawn. team ;
485432 }
486433 }
@@ -515,7 +462,6 @@ impl HeatmapAnalyser {
515462 }
516463 } )
517464 . or_insert_with ( || UserInfo {
518- classes : ClassList :: default ( ) ,
519465 team : Team :: Other ,
520466 steam_id,
521467 user_id,
@@ -551,7 +497,6 @@ impl Default for HeatmapAnalysis {
551497 users : {
552498 let mut users = BTreeMap :: new ( ) ;
553499 let world = UserInfo {
554- classes : ClassList :: default ( ) ,
555500 entity_id : Some ( EntityId :: from ( 0 ) ) ,
556501 name : "world" . into ( ) ,
557502 user_id : UserId :: from ( 0u32 ) ,
0 commit comments