Compare commits

..

2 commits

5 changed files with 67 additions and 33 deletions

13
Cargo.lock generated
View file

@ -127,6 +127,7 @@ dependencies = [
"idmangler-lib", "idmangler-lib",
"serde", "serde",
"serde_json", "serde_json",
"thiserror",
] ]
[[package]] [[package]]
@ -211,9 +212,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.77" version = "2.0.87"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -222,18 +223,18 @@ dependencies = [
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "1.0.63" version = "1.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" checksum = "02dd99dc800bbb97186339685293e1cc5d9df1f8fae2d0aecd9ff1c77efea892"
dependencies = [ dependencies = [
"thiserror-impl", "thiserror-impl",
] ]
[[package]] [[package]]
name = "thiserror-impl" name = "thiserror-impl"
version = "1.0.63" version = "1.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" checksum = "a7c61ec9a6f64d2793d8a45faba21efbe3ced62a886d44c36a009b2b519b4c7e"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

View file

@ -9,3 +9,4 @@ clap = { version = "4.5.20", features = ["derive"] }
idmangler-lib = "0.3.0" idmangler-lib = "0.3.0"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
thiserror = "1.0.68"

31
src/errorfr/mod.rs Normal file
View 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
}

View file

@ -10,9 +10,10 @@ use idmangler_lib::{
use std::collections::HashMap; use std::collections::HashMap;
use std::fs; use std::fs;
use std::panic; use std::panic;
use std::string::ToString;
mod structures; mod structures;
use crate::structures::*; use crate::structures::*;
mod errorfr;
use crate::errorfr::Errorfr;
use clap::Parser; use clap::Parser;
@ -30,14 +31,14 @@ struct Args {
// const fallbackconfigpath: String = "config.json".to_owned(); // const fallbackconfigpath: String = "config.json".to_owned();
fn main() { fn main() -> Result<(), Errors> {
// enable fancypanic when building for release // enable fancypanic when building for release
// fancypanic(); // fancypanic();
let args = Args::parse(); let args = Args::parse();
let mut debugMode = false; let mut debug_mode = false;
if args.debugmode == true { if args.debugmode == true {
debugMode = true; debug_mode = true;
println!("Debug mode enabled"); println!("Debug mode enabled");
}; };
let mut configpath: String = String::from("config.json"); let mut configpath: String = String::from("config.json");
@ -46,11 +47,12 @@ fn main() {
} }
// newest json reading code // newest json reading code
let json_config: jsonconfig = let json_config: Jsonconfig = serde_json::from_reader(fs::File::open(configpath)
serde_json::from_reader(fs::File::open(configpath).expect(ERROR[1])).expect(ERROR[2]); .map_err(|_| Errorfr::JsonMissing)?)
.map_err(|_| Errorfr::JsonCorrupt)?;
let idsmap: HashMap<String, u8> = let idsmap: HashMap<String, u8> =
serde_json::from_reader(fs::File::open("id_keys.json").expect(ERROR[3])).expect(ERROR[4]); 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])) serde_json::from_reader(fs::File::open("shiny_stats.json").expect(ERROR[5]))
.expect(ERROR[6]); .expect(ERROR[6]);
// println!("{:?}",idsmap.get("airDamage")); // println!("{:?}",idsmap.get("airDamage"));
@ -109,7 +111,7 @@ fn main() {
for _i in 0..powderamount { for _i in 0..powderamount {
powdervec.push((Powders::EARTH, powdertier)) powdervec.push((Powders::EARTH, powdertier))
} }
if debugMode { if debug_mode {
println!("Powder type: Earth"); println!("Powder type: Earth");
} }
} }
@ -117,7 +119,7 @@ fn main() {
for _i in 0..powderamount { for _i in 0..powderamount {
powdervec.push((Powders::THUNDER, powdertier)) powdervec.push((Powders::THUNDER, powdertier))
} }
if debugMode { if debug_mode {
println!("Powder type: Thunder"); println!("Powder type: Thunder");
} }
} }
@ -125,7 +127,7 @@ fn main() {
for _i in 0..powderamount { for _i in 0..powderamount {
powdervec.push((Powders::WATER, powdertier)) powdervec.push((Powders::WATER, powdertier))
} }
if debugMode { if debug_mode {
println!("Powder type: Water"); println!("Powder type: Water");
} }
} }
@ -133,7 +135,7 @@ fn main() {
for _i in 0..powderamount { for _i in 0..powderamount {
powdervec.push((Powders::FIRE, powdertier)) powdervec.push((Powders::FIRE, powdertier))
} }
if debugMode { if debug_mode {
println!("Powder type: Fire"); println!("Powder type: Fire");
} }
} }
@ -141,7 +143,7 @@ fn main() {
for _i in 0..powderamount { for _i in 0..powderamount {
powdervec.push((Powders::AIR, powdertier)) powdervec.push((Powders::AIR, powdertier))
} }
if debugMode { if debug_mode {
println!("Powder type: Air"); println!("Powder type: Air");
} }
} }
@ -149,18 +151,18 @@ fn main() {
for _i in 0..powderamount { for _i in 0..powderamount {
powdervec.push((Powders::THUNDER, powdertier)) powdervec.push((Powders::THUNDER, powdertier))
} }
if debugMode { if debug_mode {
println!("Powder type: Broken, fallback Thunder"); println!("Powder type: Broken, fallback Thunder");
} }
} }
}; };
if debugMode { if debug_mode {
println!("Powder tier: {}", powdertier); println!("Powder tier: {}", powdertier);
println!("Powder amount: {}", powderamount); println!("Powder amount: {}", powderamount);
} }
} }
if debugMode { if debug_mode {
println!("Powders Vec: {:?}", powdervec); println!("Powders Vec: {:?}", powdervec);
} }
@ -176,7 +178,7 @@ fn main() {
Some(i) => { Some(i) => {
if i != 0 { if i != 0 {
RerollData(i).encode(ver, &mut out).unwrap(); RerollData(i).encode(ver, &mut out).unwrap();
if debugMode { if debug_mode {
println!("Rerolls: {}", i) println!("Rerolls: {}", i)
} }
} }
@ -186,21 +188,21 @@ fn main() {
let mut realshinykey: u8; let mut realshinykey: u8;
if let Some(shiny) = json_config.shiny { if let Some(shiny) = json_config.shiny {
if let ref shinykey = shiny.key { if let ref _shinykey = shiny.key {
if let shinyvalue = shiny.value { if let shinyvalue = shiny.value {
realshinykey = 1; realshinykey = 1;
for i in json_shiny { for i in json_shiny {
if i.key == shiny.key { if i.key == shiny.key {
realshinykey = i.id; realshinykey = i.id;
if debugMode { if debug_mode {
println!("shiny key {}", shiny.key); println!("shiny key {}", shiny.key);
} }
} }
} }
if debugMode { if debug_mode {
println!("realshinykey: {}", realshinykey); dbg!(&realshinykey);
println!("shinyvalue: {}", shinyvalue); dbg!(&shinyvalue);
} }
ShinyData { ShinyData {
@ -246,8 +248,7 @@ fn fancypanic() {
"{}", "{}",
panic_msg panic_msg
.lines() .lines()
.skip(1) .nth(1)
.next()
.unwrap_or("HOW DID YOU BREAK THE PANIC HANDLER???") .unwrap_or("HOW DID YOU BREAK THE PANIC HANDLER???")
); );
})); }));

View file

@ -13,10 +13,10 @@ pub struct Identificationer {
pub roll: Option<u8>, pub roll: Option<u8>,
} }
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct jsonconfig { pub struct Jsonconfig {
pub debug: Option<bool>, pub debug: Option<bool>,
pub name: String, pub name: String,
pub shiny: Option<shinyjson>, pub shiny: Option<Shinyjson>,
pub ids: Vec<Identificationer>, pub ids: Vec<Identificationer>,
pub powder_limit: u8, pub powder_limit: u8,
pub powders: Vec<Powder>, pub powders: Vec<Powder>,
@ -24,12 +24,12 @@ pub struct jsonconfig {
} }
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct shinystruct { pub struct Shinystruct {
pub id: u8, pub id: u8,
pub key: String, pub key: String,
} }
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct shinyjson { pub struct Shinyjson {
pub key: String, pub key: String,
pub value: i64, pub value: i64,
} }