diff --git a/Cargo.lock b/Cargo.lock index 77767b3..b1f543d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -650,6 +650,7 @@ dependencies = [ "idmangler-lib", "reqwest", "serde", + "serde_json", "serde_json5", "thiserror", ] diff --git a/Cargo.toml b/Cargo.toml index 727a7f0..bf9aa97 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,5 +12,6 @@ clap = { version = "4.5.20", features = ["derive"] } idmangler-lib = { version = "0.5.0", features = ["serde"] } reqwest = { version = "0.12.9", features = ["blocking", "json"] } serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0.135" serde_json5 = "0.1.0" thiserror = "2.0.9" diff --git a/src/encode.rs b/src/encode.rs index b0714a9..33e5442 100644 --- a/src/encode.rs +++ b/src/encode.rs @@ -251,6 +251,6 @@ impl FuncParams<'_> { Ok(()) } pub fn encode_damagedata(&mut self) -> Result<(), Errorfr> { - Ok(()) + todo!(); } } diff --git a/src/errorfr.rs b/src/errorfr.rs index 4871cfd..d82b49e 100644 --- a/src/errorfr.rs +++ b/src/errorfr.rs @@ -28,12 +28,12 @@ pub enum Errorfr { ShinyJsonCorrupt, /// gear json is missing - #[error("Error 2.3: gear.json is missing. It's only required for the \"perfect mode\" item gen. \nYou should run \"--download Gear\" or \"--download All\".")] + #[error("Error 2.5: gear.json is missing. It's only required for the \"perfect mode\" item gen. \nYou should run \"--download Gear\" or \"--download All\".")] GearJsonMissing, /// shiny data json is corrupt - #[error("Error 2.4: gear.json is corrupt. It's only required for the \"perfect mode\" item gen. \nYou should run \"--download Gear\" or \"--download All\".")] - GearJsonCorrupt, + #[error("Error 2.6: gear.json is corrupt. It's only required for the \"perfect mode\" item gen. \nYou should run \"--download Gear\" or \"--download All\".\n{0:?}")] + GearJsonCorrupt(serde_json5::Error), /// could not download the file #[error("Error 3.1: Download request failed. Check your network settings.")] diff --git a/src/gearjson.rs b/src/gearjson.rs index d1e569b..97071d5 100644 --- a/src/gearjson.rs +++ b/src/gearjson.rs @@ -1,50 +1,24 @@ use serde::Deserialize; use std::collections::HashMap; -// the struct for each item in Hashmap gear.json. its a big ass pain +// the struct for the stuff I need in in Hashmap gear.json. its a big ass pain #[derive(Deserialize, PartialEq, Eq, Debug)] pub struct GearJsonItem { - attackSpeed: Option, - averageDps: Option, - base: HashMap, - dropMeta: Option, - dropRestriction: Option, - icon: Icon, - identifications: Option>, - identified: Option, - internalName: String, - lore: Option, - powderSlots: Option, - rarity: String, - restrictions: Option, - r#type: String, - weaponType: Option, - armourMaterial: Option, - armourType: Option, + identifications: Option< + HashMap< + String, GearJsonItemInner + > + > } #[derive(Deserialize, PartialEq, Eq, Debug)] -pub struct ItemId { - max: i8, - min: i8, - raw: i8, +#[serde(untagged)] +pub enum GearJsonItemInner { + r#Struct(GearJsonItemInnerStruct), + r#Int(i32) } - #[derive(Deserialize, PartialEq, Eq, Debug)] -pub struct dropMeta { - coordinates: [i64; 3], - name: String, - r#type: String, -} - -#[derive(Deserialize, PartialEq, Eq, Debug)] -pub struct Icon { - format: String, - value: IconValue, -} - -#[derive(Deserialize, PartialEq, Eq, Debug)] -pub struct IconValue { - customModelData: i16, - id: String, - name: String, -} +pub struct GearJsonItemInnerStruct { + max: i16, + min: i16, + raw: i16 +} \ No newline at end of file diff --git a/src/jsondl.rs b/src/jsondl.rs index f47917d..ef11deb 100644 --- a/src/jsondl.rs +++ b/src/jsondl.rs @@ -8,16 +8,25 @@ use std::fs; pub fn load_idkeys(executable_path: &str) -> Result, Errorfr> { // id_keys.json - serde_json5::from_reader(&mut fs::File::open(executable_path.to_owned() + "/data/id_keys.json").map_err(|_| Errorfr::IDMapJsonMissing)?).map_err(|_| Errorfr::IDMapJsonCorrupt) + serde_json5::from_reader( + &mut fs::File::open(executable_path.to_owned() + "/data/id_keys.json") + .map_err(|_| Errorfr::IDMapJsonMissing)?) + .map_err(|_| Errorfr::IDMapJsonCorrupt) } pub fn load_shinystats(executable_path: &str) -> Result, Errorfr> { // shiny_stats.json - serde_json5::from_reader(&mut fs::File::open(executable_path.to_owned() + "/data/shiny_stats.json").map_err(|_| Errorfr::ShinyJsonMissing)?).map_err(|_| Errorfr::ShinyJsonCorrupt) + serde_json5::from_reader( + &mut fs::File::open(executable_path.to_owned() + "/data/shiny_stats.json") + .map_err(|_| Errorfr::ShinyJsonMissing)?) + .map_err(|_| Errorfr::ShinyJsonCorrupt) } pub fn load_gear(executable_path: &str) -> Result, Errorfr> { // gear.json (ONLY FOR PERFECT ITEM FUNCTION GEN) - serde_json5::from_reader(&mut fs::File::open(executable_path.to_owned() + "/data/gear.json").map_err(|_| Errorfr::GearJsonMissing)?).map_err(|_| Errorfr::GearJsonCorrupt) + serde_json5::from_reader( + &mut fs::File::open(executable_path.to_owned() + "/data/gear.json") + .map_err(|_| Errorfr::GearJsonMissing)?) + .map_err(Errorfr::GearJsonCorrupt) } pub fn dl_json_fr(dlvalue: &String, executable_path: &str) { let jsons = DownloadJsons::from(dlvalue.clone()); diff --git a/src/jsonstruct.rs b/src/jsonstruct.rs index bcc2f04..f0b31fd 100644 --- a/src/jsonstruct.rs +++ b/src/jsonstruct.rs @@ -243,5 +243,7 @@ impl From for ItemType { } pub fn load_jsonconfig(path: &String) -> Result { - serde_json5::from_reader(&mut fs::File::open(path).map_err(|_| Errorfr::ItemJsonMissing)?).map_err(Errorfr::ItemJsonCorrupt) + serde_json5::from_reader(&mut fs::File::open(path) + .map_err(|_| Errorfr::ItemJsonMissing)?) + .map_err(Errorfr::ItemJsonCorrupt) } diff --git a/src/main.rs b/src/main.rs index ae80700..c6abdac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,10 +33,7 @@ struct Args { #[arg(long)] perfect: Option, } -pub enum PerfectStatus { - None, - Some(String), -} + fn dl_json(url: Url, savename: String) -> Result<(), Errorfr> { let resp = reqwest::blocking::get(url).map_err(|_| Errorfr::JsonDlReqFail)?; @@ -71,6 +68,13 @@ fn main() { Ok(loaded_idkeys) => { match load_shinystats(executable_path) { Ok(loaded_shinystats) => { + + // check if perfect status and change name if so. otherwise blank yep + let mut namefr: String = "".to_string(); + if let Some(t1) = args.perfect { + namefr = t1 + } + match load_jsonconfig(t) { Ok(loaded_config) => { // debug mode on if in the loaded config @@ -86,15 +90,11 @@ fn main() { let ver = EncodingVersion::Version1; let mut loaded_config_clone = loaded_config.clone(); - // check if perfect status and change name if so. otherwise blank yep - let mut namefr: String = "".to_string(); - if let Some(t1) = args.perfect { - namefr = t1 - } + // ENCODE: A Lot Of Stuff // Also print any mapped errors - let cooking = cook(&mut out, &debug_mode, ver, &mut loaded_config_clone, loaded_idkeys, loaded_shinystats, namefr); + let cooking = cook(&mut out, &debug_mode, ver, &mut loaded_config_clone, loaded_idkeys, loaded_shinystats, namefr, executable_path); if let Err(e) = cooking { println!("{}", e); // print error if there is an error } else { @@ -113,7 +113,7 @@ fn main() { } } -fn cook(out: &mut Vec, debug_mode: &bool, ver: EncodingVersion, json_config: &mut Jsonconfig, idsmap: HashMap, json_shiny: Vec, namefr: String) -> Result { +fn cook(out: &mut Vec, debug_mode: &bool, ver: EncodingVersion, json_config: &mut Jsonconfig, idsmap: HashMap, json_shiny: Vec, namefr: String, executable_path: &str) -> Result { let mut fr_params = FuncParams { fr_out: out, fr_debug_mode: debug_mode, @@ -139,7 +139,10 @@ fn cook(out: &mut Vec, debug_mode: &bool, ver: EncodingVersion, json_config: // ENCODE: NameData, if ItemType is Gear, Tome, Charm match json_config.item_type { ItemTypeDeser::Gear | ItemTypeDeser::Tome | ItemTypeDeser::Charm => { - if let Some(real_name) = &json_config.name { + if namefr != *"" { + fr_params.encode_namedata(&namefr)? + } + else if let Some(real_name) = &json_config.name { fr_params.encode_namedata(real_name)? } else { return Err(Errorfr::JsonNotFoundName); @@ -151,7 +154,11 @@ fn cook(out: &mut Vec, debug_mode: &bool, ver: EncodingVersion, json_config: // ENCODE: IdentificationData match json_config.item_type { ItemTypeDeser::Gear | ItemTypeDeser::Tome | ItemTypeDeser::Charm => { - if let Some(real_ids) = &json_config.ids { + if namefr != *"" { + println!("cool tree"); + let fr_gear = load_gear(executable_path)?; + } + else if let Some(real_ids) = &json_config.ids { fr_params.encode_iddata(real_ids, idsmap)? } }