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
//! `StructurePowerBank` data description.
use crate::data::RoomName;

with_structure_fields_and_update_struct! {
    /// A power bank object, which can be attacked by creeps, and when killed will yield a harvest of power.
    #[derive(Clone, Debug, PartialEq)]
    #[serde(rename_all = "camelCase")]
    pub struct StructurePowerBank {
        /// The game time at which this power bank will cease to exist, if it has not been killed by then.
        pub decay_time: u32,
        /// The amount of power held in this power bank - this amount will be dropped when the power bank's
        /// hits drops to 0.
        pub power: i32,
    }

    /// The update structure for a `StructurePowerBank`.
    #[derive(Clone, Debug)]
    #[serde(rename_all = "camelCase")]
    pub struct StructurePowerBankUpdate { ... }
}

#[cfg(test)]
mod test {
    use serde::Deserialize;

    use crate::data::RoomName;

    use super::StructurePowerBank;

    #[test]
    fn parse_power_bank() {
        let json = json!({
            "_id": "59695d5c09c7343d8a4192fd",
            "decayTime": 20238724,
            "hits": 2000000,
            "hitsMax": 2000000,
            "power": 3186,
            "room": "W66N20",
            "type": "powerBank",
            "x": 24,
            "y": 40
        });

        let obj = StructurePowerBank::deserialize(json).unwrap();

        assert_eq!(
            obj,
            StructurePowerBank {
                room: RoomName::new("W66N20").unwrap(),
                x: 24,
                y: 40,
                id: "59695d5c09c7343d8a4192fd".to_owned(),
                decay_time: 20238724,
                hits: 2000000,
                hits_max: 2000000,
                power: 3186,
            }
        );
    }
}