source2_demo/event/
definition.rs1use crate::HashMap;
2use std::rc::Rc;
3
4pub struct GameEventDefinition {
6 pub(crate) name: String,
7 pub(crate) keys: Vec<Rc<GameEventKey>>,
8 pub(crate) name_to_key: HashMap<String, Rc<GameEventKey>>,
9}
10
11impl GameEventDefinition {
12 pub fn name(&self) -> &str {
14 &self.name
15 }
16
17 pub fn keys(&self) -> impl Iterator<Item = &GameEventKey> {
19 self.keys.iter().map(|key| key.as_ref())
20 }
21}
22
23#[derive(Debug)]
24pub struct GameEventKey {
26 pub(crate) id: i32,
27 pub(crate) name: String,
28 pub(crate) type_id: i32,
29}
30
31impl GameEventKey {
32 pub fn id(&self) -> i32 {
34 self.id
35 }
36
37 pub fn name(&self) -> &str {
39 &self.name
40 }
41
42 pub fn type_id(&self) -> i32 {
44 self.type_id
45 }
46
47 pub fn type_name(&self) -> &'static str {
49 match self.type_id {
50 1 => "string",
51 2 => "float",
52 3 => "long",
53 4 => "short",
54 5 => "byte",
55 6 => "bool",
56 7 => "uint64",
57 8 => "long",
58 9 => "short",
59 _ => "unknown",
60 }
61 }
62}