1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//! Fired when loading into the game.
use serde::{Deserialize, Serialize};
use crate::modules::ship::ShipType;
/// Fired when loading into the game.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct LoadGameEvent {
/// The name of the player.
pub commander: String,
/// The Frontier ID of the player.
#[serde(rename = "FID")]
pub fid: String,
/// Whether horizons content has been enabled.
pub horizons: bool,
/// Whether odyssey content has been enabled.
#[serde(default)]
pub odyssey: bool,
/// Information about the current active ship of the player.
#[serde(flatten)]
pub ship_info: Option<LoadGameEventShipInfo>,
/// The gamemode the player loaded into.
pub game_mode: Option<LoadGameEventGameMode>,
/// The number of credits the player has in the bank.
pub credits: u64,
/// The number of credits the player has open in loans.
pub loan: u64,
}
/// Information about the current active ship of the player.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct LoadGameEventShipInfo {
/// The kind of ship currently active.
pub ship: ShipType,
/// The id of the active ship.
#[serde(rename = "ShipID")]
pub ship_id: u32,
/// The name of the ship.
pub ship_name: String,
/// The id nameplate of the ship.
pub ship_ident: String,
/// The current fuel level of the active ship.
pub fuel_level: f32,
/// The max fuel capacity of the active ship.
pub fuel_capacity: f32,
}
/// The gamemode the player loaded into.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub enum LoadGameEventGameMode {
Open,
Solo,
Group,
}
#[cfg(test)]
mod tests {
use crate::logs::content::log_event_content::load_game_event::{
LoadGameEvent, LoadGameEventGameMode, LoadGameEventShipInfo,
};
use crate::modules::ship::ShipType;
#[test]
fn load_game_event_is_parsed_correctly() {
let parsed: LoadGameEvent = serde_json::from_str(
r#"
{
"Commander": "HRC-2",
"FID": "F44396",
"Horizons": true,
"Ship": "FerDeLance",
"ShipID": 19,
"ShipName": "jewel of parhoon",
"ShipIdent": "hr-17f",
"FuelLevel": 3.964024,
"FuelCapacity": 8,
"GameMode": "Open",
"Credits": 2890718739,
"Loan": 0
}
"#,
)
.unwrap();
let expected = LoadGameEvent {
commander: "HRC-2".to_string(),
fid: "F44396".to_string(),
horizons: true,
odyssey: false,
ship_info: Some(LoadGameEventShipInfo {
ship: ShipType::FerDeLance,
ship_id: 19,
ship_name: "jewel of parhoon".to_string(),
ship_ident: "hr-17f".to_string(),
fuel_level: 3.964024,
fuel_capacity: 8.0,
}),
game_mode: Some(LoadGameEventGameMode::Open),
credits: 2890718739,
loan: 0,
};
assert_eq!(parsed, expected);
}
}