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
use crate::data::RoomName;
#[derive(Clone, Debug, PartialEq, Eq, serde_derive::Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum StructureType {
Spawn,
Extension,
Road,
ConstructedWall,
Rampart,
KeeperLair,
Portal,
Controller,
Link,
Storage,
Tower,
Observer,
PowerBank,
PowerSpawn,
Extractor,
Lab,
Terminal,
Container,
Nuker,
}
basic_updatable!(StructureType);
with_base_fields_and_update_struct! {
#[derive(Clone, Debug, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct ConstructionSite {
pub user: String,
pub name: Option<String>,
pub progress: u32,
pub progress_total: u32,
pub structure_type: StructureType,
}
#[derive(Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ConstructionSiteUpdate { ... }
}
#[cfg(test)]
mod test {
use serde::Deserialize;
use crate::data::RoomName;
use super::{ConstructionSite, StructureType};
#[test]
fn parse_simple_site() {
let json = json!({
"_id": "5ce54eadab500847fda00973",
"name": null,
"progress": 211,
"progressTotal": 300,
"room": "E9S32",
"structureType": "road",
"type": "constructionSite",
"user": "59cec9e20dd629146b767d96",
"x": 4,
"y": 25,
});
let obj = ConstructionSite::deserialize(json).unwrap();
assert_eq!(
obj,
ConstructionSite {
id: "5ce54eadab500847fda00973".to_owned(),
room: RoomName::new("E9S32").unwrap(),
x: 4,
y: 25,
user: "59cec9e20dd629146b767d96".to_owned(),
name: None,
progress: 211,
progress_total: 300,
structure_type: StructureType::Road,
}
);
}
}