diff --git a/src/encode.rs b/src/encode.rs index 33e5442..c86b3f5 100644 --- a/src/encode.rs +++ b/src/encode.rs @@ -251,6 +251,6 @@ impl FuncParams<'_> { Ok(()) } pub fn encode_damagedata(&mut self) -> Result<(), Errorfr> { - todo!(); + unimplemented!(); } } diff --git a/src/errorfr.rs b/src/errorfr.rs index 03905d8..8e3b043 100644 --- a/src/errorfr.rs +++ b/src/errorfr.rs @@ -95,4 +95,8 @@ pub enum Errorfr { /// Unrecognisable Powder element #[error("Error 4.8: Unknown powder element")] JsonUnknownPowderElement, + + /// Unrecognisable item for the Perfect gen function + #[error("Error 4.9: Unknown item for perfect gen...")] + PerfectItemNotFound, } diff --git a/src/gearjson.rs b/src/gearjson.rs index 9ab2db9..c2c25d5 100644 --- a/src/gearjson.rs +++ b/src/gearjson.rs @@ -1,8 +1,10 @@ use serde::{Deserialize, Serialize}; use std::collections::HashMap; +use crate::errorfr::Errorfr; +use crate::jsonstruct::Identificationer; // the struct for the stuff I need in in Hashmap gear.json. its a big ass pain -#[derive(Deserialize, Serialize, PartialEq, Eq, Debug)] +#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Clone)] pub struct GearJsonItem { identifications: Option< HashMap< @@ -10,15 +12,43 @@ pub struct GearJsonItem { > > } -#[derive(Deserialize, Serialize, PartialEq, Eq, Debug)] +#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Clone)] #[serde(untagged)] pub enum GearJsonItemInner { r#Struct(GearJsonItemInnerStruct), r#Int(i32) } -#[derive(Deserialize, Serialize, PartialEq, Eq, Debug)] +#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Clone)] pub struct GearJsonItemInnerStruct { max: i32, min: i32, raw: i32 +} + +pub fn gen_perfect(name: &str, frjson: &HashMap) -> Result, Errorfr> { + let mut a: Vec = Vec::new(); + let name = name.to_lowercase(); + match frjson.get(&name) { + Some(fr_idents) => { + if let Some(fr_identmap) = &fr_idents.identifications { + for i in fr_identmap { + if let &GearJsonItemInner::Struct(e) = &i.1 { + a.push( + Identificationer { + id: i.0.clone(), + base: e.clone().raw, + roll: Some(match &e.clone().raw { + fr if fr<&0 => 69, + fr if fr>&0 => 130, + _ => 0 + }), + } + ) + } + } + } + }, + None => return Err(Errorfr::PerfectItemNotFound) + } + Ok(a) } \ No newline at end of file diff --git a/src/jsondl.rs b/src/jsondl.rs index 7f7c62e..dac352c 100644 --- a/src/jsondl.rs +++ b/src/jsondl.rs @@ -25,11 +25,19 @@ pub fn load_shinystats(executable_path: &str) -> Result, Errorf .map_err(|_| Errorfr::ShinyJsonCorrupt) } pub fn load_gear(executable_path: &str) -> Result, Errorfr> { - // gear.json (ONLY FOR DL gear.json) - serde_json::from_reader(&mut BufReader::new( + // gear.json parse (ONLY FOR DL gear.json) + let a: HashMap = serde_json::from_reader(&mut BufReader::new( fs::File::open(executable_path.to_owned() + "/data/gear.json") .map_err(|_| Errorfr::GearJsonMissing)?)) - .map_err(Errorfr::GearJsonCacheCorrupt) + .map_err(Errorfr::GearJsonCacheCorrupt)?; + // parse the original, "a", into lowercase as "b" + let mut b: HashMap = HashMap::new(); + for i in &a { + let frname = i.0.to_lowercase(); + let frvalue = i.1.clone(); + b.insert(frname, frvalue); + } + Ok(b) } pub fn load_gear_cache(executable_path: &str) -> Result, Errorfr> { // gear_cache.json (ONLY FOR PERFECT ITEM FUNCTION GEN) @@ -72,14 +80,14 @@ pub fn dl_json_fr(dlvalue: &String, executable_path: &str) { // error handling below println!("{} Filename: {}", e, dlvalue); }, - Ok(t) => { - println!("Now generating gear_cache.json (otherwise, when running --perfect it will take ages each time!)"); + Ok(_) => { let frfrnocap = serde_json::to_vec( &load_gear(executable_path) .unwrap() ).unwrap(); let mut outer = fs::File::create(format!("{}{}",executable_path, "/data/gear_cache.json")).map_err(|_| Errorfr::GearJsonCacheCreateFail).unwrap(); outer.write_all(&frfrnocap).unwrap(); + println!("Making gearcache to {}/data/gear_cache.json", executable_path); } } } @@ -98,7 +106,7 @@ impl From for DownloadJsons { fn from(value: String) -> Self { match value.to_lowercase().as_str().trim() { "none" => { - println!("downloading NONE (Why?)"); + println!("downloading NONE (Why? it's pointless...)"); DownloadJsons::None } "id_keys" | "idkeys" | "idkeys.json" | "id_keys.json" => { diff --git a/src/main.rs b/src/main.rs index 132accd..ea07454 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,8 +12,8 @@ use crate::jsonstruct::*; use clap::Parser; use idmangler_lib::{encoding::string::encode_string, types::EncodingVersion}; use reqwest::Url; -use std::{collections::HashMap, env, fs, io, path::PathBuf}; -use std::io::Write; +use std::{collections::HashMap, env, fs, io::Write, path::PathBuf}; +use crate::gearjson::gen_perfect; #[derive(Parser, Debug, Clone)] #[command(version, about, long_about = None, arg_required_else_help(true))] @@ -157,7 +157,9 @@ fn cook(out: &mut Vec, debug_mode: &bool, ver: EncodingVersion, json_config: ItemTypeDeser::Gear | ItemTypeDeser::Tome | ItemTypeDeser::Charm => { if namefr != *"" { println!("Overriding IDs with perfect ones!"); - let fr_gear = load_gear_cache(executable_path)?; + let fr_gear_cache = load_gear_cache(executable_path)?; + let resultantvec = gen_perfect(&namefr, &fr_gear_cache)?; + fr_params.encode_iddata(&resultantvec, idsmap)? } else if let Some(real_ids) = &json_config.ids { fr_params.encode_iddata(real_ids, idsmap)? @@ -239,4 +241,4 @@ fn cook(out: &mut Vec, debug_mode: &bool, ver: EncodingVersion, json_config: } Ok(final_string) -} +} \ No newline at end of file