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
use std::collections::{BTreeMap, BTreeSet};
use serde::{Deserialize, Serialize};
use crate::Timer;
#[derive(Serialize, Deserialize)]
pub struct Manifest {
pub entries: BTreeMap<String, Entry>,
}
#[derive(Serialize, Deserialize)]
pub struct Entry {
pub checksum: String,
pub size_bytes: usize,
}
impl Manifest {
#[cfg(not(target_arch = "wasm32"))]
pub fn load() -> Manifest {
crate::maybe_read_json(crate::path("MANIFEST.json"), &mut Timer::throwaway()).unwrap()
}
#[cfg(target_arch = "wasm32")]
pub fn load() -> Manifest {
crate::from_json(&include_bytes!("../../data/MANIFEST.json").to_vec()).unwrap()
}
}
#[derive(Serialize, Deserialize)]
pub struct DataPacks {
pub runtime: BTreeSet<String>,
pub input: BTreeSet<String>,
}
impl DataPacks {
pub fn load_or_create() -> DataPacks {
if cfg!(target_arch = "wasm32") {
panic!("DataPacks::load_or_create shouldn't be called on wasm");
}
let path = crate::path("player/data.json");
match crate::maybe_read_json::<DataPacks>(path.clone(), &mut Timer::throwaway()) {
Ok(mut cfg) => {
cfg.runtime.insert("seattle".to_string());
cfg
}
Err(err) => {
warn!("player/data.json invalid, assuming defaults: {}", err);
let mut cfg = DataPacks {
runtime: BTreeSet::new(),
input: BTreeSet::new(),
};
cfg.runtime.insert("seattle".to_string());
crate::write_json(path, &cfg);
cfg
}
}
}
}