source2_demo/event/list.rs
1use crate::event::*;
2use crate::HashMap;
3use source2_demo_protobufs::CSvcMsgGameEventList;
4use std::rc::Rc;
5
6/// Container for all game event definitions in a replay.
7///
8/// This stores the complete definitions for all game events that can occur
9/// during replay parsing. Each event definition specifies:
10/// - Event ID: Unique identifier
11/// - Event name: Human-readable name
12/// - Key definitions: Names and types of fields in the event
13///
14/// # Examples
15///
16/// ```no_run
17/// use source2_demo::prelude::*;
18///
19/// # fn example(ctx: &Context) {
20/// // Game events are automatically parsed from the event definitions
21/// // You access them through the observer callbacks or game event iteration
22/// # }
23/// ```
24#[derive(Default)]
25pub struct GameEventList {
26 pub(crate) list: HashMap<i32, Rc<GameEventDefinition>>,
27}
28
29impl GameEventList {
30 pub(crate) fn new(list: CSvcMsgGameEventList) -> Self {
31 let list = list
32 .descriptors
33 .into_iter()
34 .map(|descriptor| {
35 let keys = descriptor
36 .keys
37 .clone()
38 .into_iter()
39 .enumerate()
40 .map(|(i, key)| {
41 Rc::new(GameEventKey {
42 id: i as i32,
43 name: key.name().into(),
44 })
45 })
46 .collect::<Vec<_>>();
47 let definition = Rc::new(GameEventDefinition {
48 name: descriptor.name().into(),
49 keys: keys.clone(),
50 name_to_key: keys
51 .into_iter()
52 .map(|key| (key.name.clone(), key))
53 .collect(),
54 });
55 (descriptor.eventid(), definition)
56 })
57 .collect::<HashMap<_, _>>();
58
59 Self { list }
60 }
61}