ed_journals/modules/civilization/models/
thargoid_war.rs

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
use std::fmt::{Display, Formatter};

use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct ThargoidWar {
    pub current_state: ThargoidWarState,
    pub next_state_success: ThargoidWarState,
    pub next_state_failure: ThargoidWarState,
    pub success_state_reached: bool,
    pub war_progress: f32,
    pub remaining_ports: u8,

    // TODO parse this to a special struct
    // TODO check when this is [None]
    pub estimated_remaining_time: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub enum ThargoidWarState {
    #[serde(rename = "Thargoid_Stronghold")]
    Stronghold,

    #[serde(rename = "Thargoid_Probing")]
    Probing,

    #[serde(rename = "Thargoid_Controlled")]
    Controlled,

    #[serde(rename = "Thargoid_Recovery")]
    Recovery,

    #[serde(rename = "Thargoid_Harvest")]
    Harvest,

    #[serde(rename = "Unknown")]
    UnknownState,

    #[serde(rename = "")]
    Unspecified,

    #[cfg(feature = "allow-unknown")]
    #[cfg_attr(docsrs, doc(cfg(feature = "allow-unknown")))]
    #[serde(untagged)]
    Unknown(String),
}

impl Display for ThargoidWarState {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "{}",
            match self {
                ThargoidWarState::Stronghold => "Stronghold",
                ThargoidWarState::Probing => "Probing",
                ThargoidWarState::Controlled => "Controlled",
                ThargoidWarState::Recovery => "Recovery",
                ThargoidWarState::Harvest => "Harvest",
                ThargoidWarState::UnknownState => "Unknown",
                ThargoidWarState::Unspecified => "Unspecified",

                #[cfg(feature = "allow-unknown")]
                ThargoidWarState::Unknown(unknown) =>
                    return write!(f, "Unknown thargoid war state: {}", unknown),
            }
        )
    }
}