-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate_display_names.rs
71 lines (65 loc) · 1.91 KB
/
update_display_names.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 serde::Deserialize;
use std::{collections::BTreeMap, fs};
#[derive(Deserialize)]
struct Item {
internalname: String,
displayname: String,
}
fn remove_color_codes(input_str: &str) -> String {
let mut result = String::new();
let mut chars = input_str.chars().peekable();
while let Some(c) = chars.next() {
if c == '§' {
// skip the color code
let _ = chars.next();
continue;
}
result.push(c);
}
result
}
fn main() {
if !std::path::Path::new("./neudata").exists() {
std::process::Command::new("git")
.args([
"clone",
"https://github.com/NotEnoughUpdates/NotEnoughUpdates-REPO",
"neudata",
])
.output()
.unwrap();
} else {
std::process::Command::new("git")
.args(["pull"])
.current_dir("./neudata")
.output()
.unwrap();
}
let mut data = BTreeMap::new();
for file in fs::read_dir("./neudata/items").unwrap() {
let file = file.unwrap();
if !file.file_type().unwrap().is_dir() && file.path().extension().unwrap() == "json" {
let file = fs::read(file.path()).unwrap();
let file: Item = serde_json::from_slice(&file).unwrap();
let displayname = remove_color_codes(&file.displayname);
data.insert(file.internalname, displayname);
}
}
let match_arms = data
.iter()
.map(|(key, value)| {
quote::quote! {
#key => #value,
}
})
.collect::<Vec<_>>();
let res = quote::quote! {
pub fn to_display_name(name: &str) -> &str {
match name {
#(#match_arms)*
_ => name.to_string(),
}
}
};
fs::write("generated/to_display_name.rs", res.to_string()).unwrap();
}