-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
71 lines (65 loc) · 3.07 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use std::{collections::BTreeMap, env, fs, process::Command};
use colored::{control::set_override, Colorize};
const LOC: &str = "https://raw.githubusercontent.com/Skytils/SkytilsMod-Data/main/constants/sellprices.json";
static LOGO: &str = r#"
██╗ ██████╗ ██╗ ██╗███████╗███████╗████████╗██████╗ ██╗███╗ ██╗███████╗
██║ ██╔═══██╗██║ ██║██╔════╝██╔════╝╚══██╔══╝██╔══██╗██║████╗ ██║██╔════╝
██║ ██║ ██║██║ █╗ ██║█████╗ ███████╗ ██║ ██████╔╝██║██╔██╗ ██║███████╗
██║ ██║ ██║██║███╗██║██╔══╝ ╚════██║ ██║ ██╔══██╗██║██║╚██╗██║╚════██║
███████╗╚██████╔╝╚███╔███╔╝███████╗███████║ ██║ ██████╔╝██║██║ ╚████║███████║
╚══════╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚══════╝ ╚═╝ ╚═════╝ ╚═╝╚═╝ ╚═══╝╚══════╝
"#;
fn main() {
set_override(true);
let res: String = LOGO
.to_owned()
.trim()
.chars()
.map(|x| {
if x == '█' {
"█".dimmed().green().to_string()
} else if x == ' ' || x == '\n' {
x.to_string()
} else {
x.to_string().bright_green().to_string()
}
})
.collect::<_>();
fs::write(format!("{}/logo.txt", &env::var("OUT_DIR").unwrap()), res).unwrap();
let output = format!("{}/sellprices.json", &env::var("OUT_DIR").unwrap());
println!("cargo:rerun-if-changed={output}");
if fs::read(&output).is_err() {
let _cmd = Command::new("curl")
.arg("-o")
.arg(&output)
.arg(LOC)
.output()
.expect("failed to execute process");
}
if fs::read(&output).is_err() {
fs::write(&output, r#"{}"#).unwrap();
}
let file = fs::read(&output).unwrap();
let file = serde_json::from_slice::<BTreeMap<String, f64>>(&file)
.unwrap()
.into_iter()
.map(|(k, v)| {
let v_u64 = v as u64;
quote::quote! {
(#k.to_owned(), #v_u64),
}
});
let len = file.len();
let default_prices = quote::quote! {
pub fn get_prices_map() -> [(String, u64); #len] {
[
#(#file)*
]
}
};
fs::write(
format!("{}/prices_map.rs", &env::var("OUT_DIR").unwrap()),
default_prices.to_string(),
)
.unwrap();
}