subtr_actor/processor/
debug.rs1use super::*;
2
3impl<'a> ReplayProcessor<'a> {
4 pub fn map_attribute_keys(
6 &self,
7 hash_map: &HashMap<boxcars::ObjectId, (boxcars::Attribute, usize)>,
8 ) -> HashMap<String, boxcars::Attribute> {
9 hash_map
10 .iter()
11 .map(|(k, (v, _updated))| {
12 self.object_id_to_name
13 .get(k)
14 .map(|name| (name.clone(), v.clone()))
15 .unwrap()
16 })
17 .collect()
18 }
19
20 pub fn all_mappings_string(&self) -> String {
22 let pairs = [
23 ("player_to_car", &self.player_to_car),
24 ("player_to_team", &self.player_to_team),
25 ("car_to_player", &self.car_to_player),
26 ("car_to_boost", &self.car_to_boost),
27 ("car_to_jump", &self.car_to_jump),
28 ("car_to_double_jump", &self.car_to_double_jump),
29 ("car_to_dodge", &self.car_to_dodge),
30 ];
31 let mut strings: Vec<_> = pairs
32 .iter()
33 .map(|(map_name, map)| format!("{map_name:?}: {map:?}"))
34 .collect();
35 strings.push(format!("name_to_object_id: {:?}", &self.name_to_object_id));
36 strings.join("\n")
37 }
38
39 pub fn actor_state_string(&self, actor_id: &boxcars::ActorId) -> String {
41 if let Ok(actor_state) = self.get_actor_state(actor_id) {
42 format!("{:?}", self.map_attribute_keys(&actor_state.attributes))
43 } else {
44 String::from("error")
45 }
46 }
47
48 pub fn print_actors_by_id<'b>(&self, actor_ids: impl Iterator<Item = &'b boxcars::ActorId>) {
50 actor_ids.for_each(|actor_id| {
51 let state = self.get_actor_state(actor_id).unwrap();
52 println!(
53 "{:?}\n\n\n",
54 self.object_id_to_name.get(&state.object_id).unwrap()
55 );
56 println!("{:?}", self.map_attribute_keys(&state.attributes))
57 })
58 }
59
60 pub fn print_actors_of_type(&self, actor_type: &'static str) {
62 self.iter_actors_by_type(actor_type)
63 .unwrap()
64 .for_each(|(_actor_id, state)| {
65 log::debug!("{:?}", self.map_attribute_keys(&state.attributes));
66 });
67 }
68
69 pub fn print_actor_types(&self) {
71 let types: Vec<_> = self
72 .actor_state
73 .actor_ids_by_type
74 .keys()
75 .filter_map(|id| self.object_id_to_name.get(id))
76 .collect();
77 log::debug!("{types:?}");
78 }
79
80 pub fn print_all_actors(&self) {
82 self.actor_state
83 .actor_states
84 .iter()
85 .for_each(|(actor_id, actor_state)| {
86 log::debug!(
87 "{}: {:?}",
88 self.object_id_to_name
89 .get(&actor_state.object_id)
90 .unwrap_or(&String::from("unknown")),
91 self.actor_state_string(actor_id)
92 )
93 });
94 }
95}