-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
50 lines (46 loc) · 1.51 KB
/
build.rs
File metadata and controls
50 lines (46 loc) · 1.51 KB
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
use std::{fs, io::Write};
fn main() -> Result<(), Box<dyn std::error::Error>> {
generate_protos()?;
generate_level_xp();
generate_mnstr_xp();
Ok(())
}
fn generate_protos() -> Result<(), Box<dyn std::error::Error>> {
tonic_prost_build::configure()
.build_server(true)
.build_client(true)
.compile_protos(
&[
"adventure_proto/user.proto",
"adventure_proto/session.proto",
"adventure_proto/chat.proto",
],
&["adventure_proto"],
)?;
Ok(())
}
fn generate_level_xp() {
let mut levels = vec![];
levels.push(0);
levels.push(100);
for i in 2..101 {
let previous_xp = levels[i - 1];
let xp = (previous_xp + ((previous_xp as f64).log10() * 100.0).ceil() as i32) as i32;
levels.push(xp);
}
let ouput = format!("pub const XP_FOR_LEVEL: [i32; 101] = {:?};", levels);
let mut file = fs::File::create("src/models/generated/level_xp.rs").unwrap();
file.write_all(ouput.as_bytes()).unwrap();
}
fn generate_mnstr_xp() {
let mut levels = vec![];
levels.push(50);
for i in 1..101 {
let previous_xp = levels[i - 1];
let xp = (previous_xp + ((previous_xp as f64).log10() * 10.0).ceil() as i32) as i32;
levels.push(xp);
}
let ouput = format!("pub const XP_FOR_LEVEL: [i32; 101] = {:?};", levels);
let mut file = fs::File::create("src/models/generated/mnstr_xp.rs").unwrap();
file.write_all(ouput.as_bytes()).unwrap();
}