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
use crate::data::RoomName;
with_structure_fields_and_update_struct! {
#[derive(Clone, Debug, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct StructurePowerSpawn {
pub user: String,
#[serde(default, rename = "off")]
pub disabled: bool,
pub energy: i32,
pub energy_capacity: i32,
pub power: i32,
pub power_capacity: i32,
pub notify_when_attacked: bool,
}
#[derive(Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct StructurePowerSpawnUpdate {
- user: String,
#[serde(rename = "off")]
- disabled: bool,
- energy: i32,
- energy_capacity: i32,
- power: i32,
- power_capacity: i32,
- notify_when_attacked: bool,
}
}
#[cfg(test)]
mod test {
use serde::Deserialize;
use crate::data::RoomName;
use super::StructurePowerSpawn;
#[test]
fn parse_power_spawn() {
let json = json!({
"_id": "5825874e440f3fbd2caf30b5",
"energy": 4944,
"energyCapacity": 5000,
"hits": 5000,
"hitsMax": 5000,
"notifyWhenAttacked": true,
"power": 94,
"powerCapacity": 100,
"room": "E9N23",
"type": "powerSpawn",
"user": "561e4d4645f3f7244a7622e8",
"x": 19,
"y": 14
});
let obj = StructurePowerSpawn::deserialize(json).unwrap();
assert_eq!(
obj,
StructurePowerSpawn {
id: "5825874e440f3fbd2caf30b5".to_owned(),
room: RoomName::new("E9N23").unwrap(),
x: 19,
y: 14,
energy: 4944,
energy_capacity: 5000,
power: 94,
power_capacity: 100,
hits: 5000,
hits_max: 5000,
notify_when_attacked: true,
disabled: false,
user: "561e4d4645f3f7244a7622e8".to_owned(),
}
);
}
}