Compare commits
2 commits
8bc131c7fe
...
0c7f30a73d
Author | SHA1 | Date | |
---|---|---|---|
0c7f30a73d | |||
7570f39402 |
5 changed files with 67 additions and 33 deletions
13
Cargo.lock
generated
13
Cargo.lock
generated
|
@ -127,6 +127,7 @@ dependencies = [
|
|||
"idmangler-lib",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -211,9 +212,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.77"
|
||||
version = "2.0.87"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed"
|
||||
checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -222,18 +223,18 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.63"
|
||||
version = "1.0.68"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724"
|
||||
checksum = "02dd99dc800bbb97186339685293e1cc5d9df1f8fae2d0aecd9ff1c77efea892"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.63"
|
||||
version = "1.0.68"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261"
|
||||
checksum = "a7c61ec9a6f64d2793d8a45faba21efbe3ced62a886d44c36a009b2b519b4c7e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
@ -9,3 +9,4 @@ clap = { version = "4.5.20", features = ["derive"] }
|
|||
idmangler-lib = "0.3.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
thiserror = "1.0.68"
|
||||
|
|
31
src/errorfr/mod.rs
Normal file
31
src/errorfr/mod.rs
Normal file
|
@ -0,0 +1,31 @@
|
|||
use thiserror::Error;
|
||||
|
||||
/// Errors yep
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Errorfr {
|
||||
/// config json is missing
|
||||
#[error("Error 1: json config json is missing, obtain it from https://git.frfrnocap.men/endernon/idmangler-cli/raw/branch/main/config.json and move it to this directory. "
|
||||
)]
|
||||
JsonMissing,
|
||||
|
||||
/// config json is corrupt
|
||||
#[error("Error 2: json config json is corrupt. Reread config.md or reobtain it from https://git.frfrnocap.men/endernon/idmangler-cli/raw/branch/main/config.json and move it to this diirectory. "
|
||||
)]
|
||||
JsonCorrupt,
|
||||
|
||||
/// idmap is missing
|
||||
#[error("Error 3: Identifications hashmap is missing. Get it from https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/id_keys.json and move it to this directory. ")]
|
||||
IDMapMissing,
|
||||
|
||||
/// idmap is corrupt
|
||||
#[error("Error 4: Identifications hashmap is corrupt. Reobtain it from https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/id_keys.json and move it to this directory. ")]
|
||||
IDMapCorrupt,
|
||||
|
||||
/// shiny data json is missing
|
||||
#[error("Error 5: Shiny data json is missing. Get it from https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Data-Storage/shiny_stats.json and move it to this directory. ")]
|
||||
ShinyJsonMissing,
|
||||
|
||||
/// shiny data json is corrupt
|
||||
#[error("Error 6: Shiny data json is corrupt. Get it from https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Data-Storage/shiny_stats.json and move it to this directory. ")]
|
||||
ShinyJsonCorrupt
|
||||
}
|
47
src/main.rs
47
src/main.rs
|
@ -10,9 +10,10 @@ use idmangler_lib::{
|
|||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
use std::panic;
|
||||
use std::string::ToString;
|
||||
mod structures;
|
||||
use crate::structures::*;
|
||||
mod errorfr;
|
||||
use crate::errorfr::Errorfr;
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
|
@ -30,14 +31,14 @@ struct Args {
|
|||
|
||||
// const fallbackconfigpath: String = "config.json".to_owned();
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<(), Errors> {
|
||||
// enable fancypanic when building for release
|
||||
// fancypanic();
|
||||
let args = Args::parse();
|
||||
|
||||
let mut debugMode = false;
|
||||
let mut debug_mode = false;
|
||||
if args.debugmode == true {
|
||||
debugMode = true;
|
||||
debug_mode = true;
|
||||
println!("Debug mode enabled");
|
||||
};
|
||||
let mut configpath: String = String::from("config.json");
|
||||
|
@ -46,11 +47,12 @@ fn main() {
|
|||
}
|
||||
|
||||
// newest json reading code
|
||||
let json_config: jsonconfig =
|
||||
serde_json::from_reader(fs::File::open(configpath).expect(ERROR[1])).expect(ERROR[2]);
|
||||
let json_config: Jsonconfig = serde_json::from_reader(fs::File::open(configpath)
|
||||
.map_err(|_| Errorfr::JsonMissing)?)
|
||||
.map_err(|_| Errorfr::JsonCorrupt)?;
|
||||
let idsmap: HashMap<String, u8> =
|
||||
serde_json::from_reader(fs::File::open("id_keys.json").expect(ERROR[3])).expect(ERROR[4]);
|
||||
let json_shiny: Vec<shinystruct> =
|
||||
let json_shiny: Vec<Shinystruct> =
|
||||
serde_json::from_reader(fs::File::open("shiny_stats.json").expect(ERROR[5]))
|
||||
.expect(ERROR[6]);
|
||||
// println!("{:?}",idsmap.get("airDamage"));
|
||||
|
@ -109,7 +111,7 @@ fn main() {
|
|||
for _i in 0..powderamount {
|
||||
powdervec.push((Powders::EARTH, powdertier))
|
||||
}
|
||||
if debugMode {
|
||||
if debug_mode {
|
||||
println!("Powder type: Earth");
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +119,7 @@ fn main() {
|
|||
for _i in 0..powderamount {
|
||||
powdervec.push((Powders::THUNDER, powdertier))
|
||||
}
|
||||
if debugMode {
|
||||
if debug_mode {
|
||||
println!("Powder type: Thunder");
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +127,7 @@ fn main() {
|
|||
for _i in 0..powderamount {
|
||||
powdervec.push((Powders::WATER, powdertier))
|
||||
}
|
||||
if debugMode {
|
||||
if debug_mode {
|
||||
println!("Powder type: Water");
|
||||
}
|
||||
}
|
||||
|
@ -133,7 +135,7 @@ fn main() {
|
|||
for _i in 0..powderamount {
|
||||
powdervec.push((Powders::FIRE, powdertier))
|
||||
}
|
||||
if debugMode {
|
||||
if debug_mode {
|
||||
println!("Powder type: Fire");
|
||||
}
|
||||
}
|
||||
|
@ -141,7 +143,7 @@ fn main() {
|
|||
for _i in 0..powderamount {
|
||||
powdervec.push((Powders::AIR, powdertier))
|
||||
}
|
||||
if debugMode {
|
||||
if debug_mode {
|
||||
println!("Powder type: Air");
|
||||
}
|
||||
}
|
||||
|
@ -149,18 +151,18 @@ fn main() {
|
|||
for _i in 0..powderamount {
|
||||
powdervec.push((Powders::THUNDER, powdertier))
|
||||
}
|
||||
if debugMode {
|
||||
if debug_mode {
|
||||
println!("Powder type: Broken, fallback Thunder");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if debugMode {
|
||||
if debug_mode {
|
||||
println!("Powder tier: {}", powdertier);
|
||||
println!("Powder amount: {}", powderamount);
|
||||
}
|
||||
}
|
||||
if debugMode {
|
||||
if debug_mode {
|
||||
println!("Powders Vec: {:?}", powdervec);
|
||||
}
|
||||
|
||||
|
@ -176,7 +178,7 @@ fn main() {
|
|||
Some(i) => {
|
||||
if i != 0 {
|
||||
RerollData(i).encode(ver, &mut out).unwrap();
|
||||
if debugMode {
|
||||
if debug_mode {
|
||||
println!("Rerolls: {}", i)
|
||||
}
|
||||
}
|
||||
|
@ -186,21 +188,21 @@ fn main() {
|
|||
|
||||
let mut realshinykey: u8;
|
||||
if let Some(shiny) = json_config.shiny {
|
||||
if let ref shinykey = shiny.key {
|
||||
if let ref _shinykey = shiny.key {
|
||||
if let shinyvalue = shiny.value {
|
||||
|
||||
realshinykey = 1;
|
||||
for i in json_shiny {
|
||||
if i.key == shiny.key {
|
||||
realshinykey = i.id;
|
||||
if debugMode {
|
||||
if debug_mode {
|
||||
println!("shiny key {}", shiny.key);
|
||||
}
|
||||
}
|
||||
}
|
||||
if debugMode {
|
||||
println!("realshinykey: {}", realshinykey);
|
||||
println!("shinyvalue: {}", shinyvalue);
|
||||
if debug_mode {
|
||||
dbg!(&realshinykey);
|
||||
dbg!(&shinyvalue);
|
||||
}
|
||||
|
||||
ShinyData {
|
||||
|
@ -246,8 +248,7 @@ fn fancypanic() {
|
|||
"{}",
|
||||
panic_msg
|
||||
.lines()
|
||||
.skip(1)
|
||||
.next()
|
||||
.nth(1)
|
||||
.unwrap_or("HOW DID YOU BREAK THE PANIC HANDLER???")
|
||||
);
|
||||
}));
|
||||
|
|
|
@ -13,10 +13,10 @@ pub struct Identificationer {
|
|||
pub roll: Option<u8>,
|
||||
}
|
||||
#[derive(Deserialize)]
|
||||
pub struct jsonconfig {
|
||||
pub struct Jsonconfig {
|
||||
pub debug: Option<bool>,
|
||||
pub name: String,
|
||||
pub shiny: Option<shinyjson>,
|
||||
pub shiny: Option<Shinyjson>,
|
||||
pub ids: Vec<Identificationer>,
|
||||
pub powder_limit: u8,
|
||||
pub powders: Vec<Powder>,
|
||||
|
@ -24,12 +24,12 @@ pub struct jsonconfig {
|
|||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct shinystruct {
|
||||
pub struct Shinystruct {
|
||||
pub id: u8,
|
||||
pub key: String,
|
||||
}
|
||||
#[derive(Deserialize)]
|
||||
pub struct shinyjson {
|
||||
pub struct Shinyjson {
|
||||
pub key: String,
|
||||
pub value: i64,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue