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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
use std::collections::{BTreeMap, BTreeSet};
use serde::{Deserialize, Serialize};
use crate::CityName;
#[derive(Serialize, Deserialize)]
pub struct Manifest {
pub entries: BTreeMap<String, Entry>,
}
#[derive(Serialize, Deserialize)]
pub struct Entry {
pub checksum: String,
pub uncompressed_size_bytes: u64,
pub compressed_size_bytes: u64,
}
impl Manifest {
#[cfg(not(target_arch = "wasm32"))]
pub fn load() -> Manifest {
crate::maybe_read_json(
crate::path("MANIFEST.json"),
&mut abstutil::Timer::throwaway(),
)
.unwrap()
}
#[cfg(target_arch = "wasm32")]
pub fn load() -> Manifest {
abstutil::from_json(&include_bytes!("../../data/MANIFEST.json").to_vec()).unwrap()
}
pub fn filter(mut self, data_packs: DataPacks) -> Manifest {
let mut remove = Vec::new();
for path in self.entries.keys() {
if path.starts_with("data/system/extra_fonts") {
continue;
}
if path.starts_with("data/input/shared") {
if path.ends_with("Road Safety Data - Accidents 2019.csv")
|| path.ends_with("wu03ew_v2.csv")
|| path.ends_with("zones_core.geojson")
{
if data_packs.input.iter().any(|x| x.starts_with("gb/")) {
continue;
}
} else if path.ends_with("kc_2016_lidar.tif")
|| path.ends_with("seattle_contours.geojson")
{
if data_packs.input.contains("us/seattle") {
continue;
}
} else if !data_packs.input.is_empty() {
continue;
}
}
let parts = path.split('/').collect::<Vec<_>>();
let mut data_pack = format!("{}/{}", parts[2], parts[3]);
if Manifest::is_file_part_of_huge_seattle(path) {
data_pack = "us/huge_seattle".to_string();
}
if parts[1] == "input" {
if data_packs.input.contains(&data_pack) {
continue;
}
} else if parts[1] == "system" {
if data_packs.runtime.contains(&data_pack) {
continue;
}
} else {
panic!("Wait what's {}", path);
}
remove.push(path.clone());
}
for path in remove {
self.entries.remove(&path).unwrap();
}
self
}
pub fn is_file_part_of_huge_seattle(path: &str) -> bool {
let path = path
.strip_prefix(&crate::path(""))
.or_else(|| path.strip_prefix("data/"))
.unwrap_or(path);
let name = if let Some(x) = path.strip_prefix("system/us/seattle/maps/") {
x.strip_suffix(".bin").unwrap()
} else if let Some(x) = path.strip_prefix("system/us/seattle/scenarios/") {
x.split('/').next().unwrap()
} else if let Some(x) = path.strip_prefix("system/us/seattle/prebaked_results/") {
x.split('/').next().unwrap()
} else {
return false;
};
name == "huge_seattle"
|| name == "north_seattle"
|| name == "south_seattle"
|| name == "west_seattle"
}
pub fn path_to_city(path: &str) -> Option<CityName> {
let parts = path.split('/').collect::<Vec<_>>();
if parts[1] == "system" {
if parts[2] == "assets"
|| parts[2] == "extra_fonts"
|| parts[2] == "ltn_proposals"
|| parts[2] == "proposals"
|| parts[2] == "study_areas"
{
return None;
}
return Some(CityName::new(parts[2], parts[3]));
}
None
}
pub fn get_entry(&self, path: &str) -> Option<&Entry> {
let path = path.strip_prefix(&crate::path("")).unwrap_or(path);
self.entries.get(&format!("data/{}", path))
}
}
#[derive(Serialize, Deserialize)]
pub struct DataPacks {
pub runtime: BTreeSet<String>,
pub input: BTreeSet<String>,
}
impl DataPacks {
#[cfg(not(target_arch = "wasm32"))]
pub fn load_or_create() -> DataPacks {
let path = crate::path_player("data.json");
match crate::maybe_read_json::<DataPacks>(path.clone(), &mut abstutil::Timer::throwaway()) {
Ok(cfg) => cfg,
Err(err) => {
warn!("player/data.json invalid, assuming defaults: {}", err);
let mut cfg = DataPacks {
runtime: BTreeSet::new(),
input: BTreeSet::new(),
};
cfg.runtime.insert("us/seattle".to_string());
crate::write_json(path, &cfg);
cfg
}
}
}
#[cfg(not(target_arch = "wasm32"))]
pub fn save(&self) {
crate::write_json(crate::path_player("data.json"), self);
}
pub fn all_data_packs() -> DataPacks {
let mut data_packs = DataPacks {
runtime: BTreeSet::new(),
input: BTreeSet::new(),
};
for path in Manifest::load().entries.keys() {
if path.starts_with("data/system/extra_fonts") || path.starts_with("data/input/shared")
{
continue;
}
let parts = path.split('/').collect::<Vec<_>>();
let mut city = format!("{}/{}", parts[2], parts[3]);
if Manifest::is_file_part_of_huge_seattle(path) {
city = "us/huge_seattle".to_string();
}
if parts[1] == "input" {
data_packs.input.insert(city);
} else if parts[1] == "system" {
data_packs.runtime.insert(city);
}
}
data_packs
}
}