-
Notifications
You must be signed in to change notification settings - Fork 21
/
build.rs
55 lines (43 loc) · 1.85 KB
/
build.rs
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
use std::env;
use std::fs::File;
use std::path::Path;
use reliquary::resource::excel::{
AvatarConfigMap, AvatarSkillTreeConfigMap, EquipmentConfigMap, MultiplePathAvatarConfigMap,
RelicConfigMap, RelicMainAffixConfigMap, RelicSetConfigMap, RelicSubAffixConfigMap,
};
use reliquary::resource::ResourceMap;
use ureq::serde_json::Value;
const BASE_RESOURCE_URL: &str = "https://gitlab.com/Dimbreath/turnbasedgamedata/-/raw/main";
const KEY_URL: &str =
"https://raw.githubusercontent.com/tamilpp25/Iridium-SR/refs/heads/main/data/Keys.json";
fn main() {
println!("cargo:rerun-if-changed=Cargo.toml");
println!("cargo:rerun-if-changed=Cargo.lock");
download_config::<AvatarConfigMap>();
download_config::<AvatarSkillTreeConfigMap>();
download_config::<EquipmentConfigMap>();
download_config::<MultiplePathAvatarConfigMap>();
download_config::<RelicConfigMap>();
download_config::<RelicMainAffixConfigMap>();
download_config::<RelicSetConfigMap>();
download_config::<RelicSubAffixConfigMap>();
download_and_write_to_out(
"TextMapEN.json",
format!("{BASE_RESOURCE_URL}/TextMap/TextMapEN.json").as_str(),
);
download_and_write_to_out("keys.json", KEY_URL);
}
fn download_config<T: ResourceMap>() {
let file_name = T::get_json_name();
let url = format!("{BASE_RESOURCE_URL}/ExcelOutput/{file_name}");
download_and_write_to_out(file_name, &url);
}
fn download_and_write_to_out(file: &str, url: &str) {
// downloaded files are in pretty format, deserialize and serialize
// to compress file size
let value: Value = ureq::get(url).call().unwrap().into_json().unwrap();
let out_dir = env::var_os("OUT_DIR").unwrap();
let out_path = Path::new(&out_dir).join(file);
let mut file = File::create(out_path).unwrap();
ureq::serde_json::to_writer(&mut file, &value).unwrap();
}