Skip to main content

ed_journals/modules/logs/content/log_event_content/
module_swap_event.rs

1//! Fired when swapping a module from one slot to another.
2
3use serde::{Deserialize, Deserializer, Serialize};
4use std::str::FromStr;
5
6use crate::modules::ship::{ShipSlot, ShipType};
7use crate::ship::ShipModule;
8
9/// Fired when swapping a module from one slot to another.
10#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
11#[serde(rename_all = "PascalCase")]
12pub struct ModuleSwapEvent {
13    /// The market id the player is performing the action at.
14    #[serde(rename = "MarketID")]
15    pub market_id: u64,
16
17    /// The slot that the module was originally in.
18    pub from_slot: ShipSlot,
19
20    /// The slot that the module has been moved to.
21    pub to_slot: ShipSlot,
22
23    /// The module that was in the 'from' slot.
24    pub from_item: ShipModule,
25
26    /// The localized name of the module that was in the 'from' slot.
27    #[serde(rename = "FromItem_Localised")]
28    pub from_item_localized: Option<String>,
29
30    /// The module that was originally in the 'to' slot and that has now been placed in the 'from'
31    /// slot.
32    #[serde(deserialize_with = "deserialize_to_item")]
33    pub to_item: Option<ShipModule>,
34
35    /// The localized name of the module that was in the 'to' slot.
36    #[serde(rename = "ToItem_Localised")]
37    pub to_item_localized: Option<String>,
38
39    /// The id of the current active ship.
40    pub ship: ShipType,
41
42    /// Whether the module is hot.
43    #[serde(rename = "ShipID")]
44    pub ship_id: u64,
45}
46
47fn deserialize_to_item<'de, D>(deserializer: D) -> Result<Option<ShipModule>, D::Error>
48where
49    D: Deserializer<'de>,
50{
51    let string = String::deserialize(deserializer)?;
52
53    if &string == "Null" {
54        Ok(None)
55    } else {
56        ShipModule::from_str(&string)
57            .map(Some)
58            .map_err(serde::de::Error::custom)
59    }
60}