From 7d4dcfa2b9099780ef947f4588480306e644af1a Mon Sep 17 00:00:00 2001 From: endernon Date: Tue, 14 Jan 2025 18:19:16 +0000 Subject: [PATCH] let me cook --- src/encode.rs | 12 ++---------- src/errorfr.rs | 8 ++------ src/jsondl.rs | 21 ++++++--------------- src/jsonstruct.rs | 14 ++------------ src/main.rs | 19 ++++++------------- 5 files changed, 18 insertions(+), 56 deletions(-) diff --git a/src/encode.rs b/src/encode.rs index baf1563..b0714a9 100644 --- a/src/encode.rs +++ b/src/encode.rs @@ -2,10 +2,7 @@ use crate::errorfr::Errorfr; use crate::jsonstruct::{CraftedTypesFr, Durability, FuncParams, Identificationer, ItemTypeDeser, PowderFr, RequirementsDeser, Shinyjson, Shinystruct}; use idmangler_lib::encoding::DataEncoder; use idmangler_lib::{ - block::{ - CraftedConsumableTypeData, CraftedGearTypeData, DurabilityData, EndData, IdentificationData, NameData, PowderData, RequirementsData, RerollData, - ShinyData, StartData, TypeData, - }, + block::{CraftedConsumableTypeData, CraftedGearTypeData, DurabilityData, EndData, IdentificationData, NameData, PowderData, RequirementsData, RerollData, ShinyData, StartData, TypeData}, types::{ClassType, Element, ItemType, Powder, RollType, SkillType, Stat}, }; use std::collections::HashMap; @@ -242,12 +239,7 @@ impl FuncParams<'_> { dbg!(&shinyvalue); } // ENCODE: ShinyData (if applicable) - ShinyData { - id: realshinykey, - val: shinyvalue, - } - .encode(self.fr_ver, self.fr_out) - .unwrap(); + ShinyData { id: realshinykey, val: shinyvalue }.encode(self.fr_ver, self.fr_out).unwrap(); Ok(()) } pub fn encode_enddata(&mut self) -> Result<(), Errorfr> { diff --git a/src/errorfr.rs b/src/errorfr.rs index 15a3a4a..4871cfd 100644 --- a/src/errorfr.rs +++ b/src/errorfr.rs @@ -28,15 +28,11 @@ 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.3: 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\"." - )] + #[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, /// could not download the file diff --git a/src/jsondl.rs b/src/jsondl.rs index 4f06d24..df1414c 100644 --- a/src/jsondl.rs +++ b/src/jsondl.rs @@ -8,20 +8,17 @@ 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> { // shiny_stats.json let a: Result, Errorfr> = - 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); a } @@ -33,9 +30,7 @@ pub fn dl_json_fr(dlvalue: &String, executable_path: &str) { if jsons == DownloadJsons::All || jsons == DownloadJsons::ShinyStats { if let Err(e) = dl_json( - "https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Data-Storage/shiny_stats.json" - .parse() - .unwrap(), + "https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Data-Storage/shiny_stats.json".parse().unwrap(), format!("{}{}", executable_path, "/data/shiny_stats.json"), ) { // error handling below @@ -44,9 +39,7 @@ pub fn dl_json_fr(dlvalue: &String, executable_path: &str) { } if jsons == DownloadJsons::All || jsons == DownloadJsons::IdKeys { if let Err(e) = dl_json( - "https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/id_keys.json" - .parse() - .unwrap(), + "https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/id_keys.json".parse().unwrap(), format!("{}{}", executable_path, "/data/id_keys.json"), ) { // error handling below @@ -55,9 +48,7 @@ pub fn dl_json_fr(dlvalue: &String, executable_path: &str) { } if jsons == DownloadJsons::All || jsons == DownloadJsons::Gear { if let Err(e) = dl_json( - "https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/gear.json" - .parse() - .unwrap(), + "https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/gear.json".parse().unwrap(), format!("{}{}", executable_path, "/data/gear.json"), ) { // error handling below diff --git a/src/jsonstruct.rs b/src/jsonstruct.rs index 3c55650..1c8d971 100644 --- a/src/jsonstruct.rs +++ b/src/jsonstruct.rs @@ -1,8 +1,6 @@ use crate::errorfr::Errorfr; use crate::jsonstruct::CraftedTypesFr::{Consu, Gear}; -use idmangler_lib::types::{ - AttackSpeed, ClassType, ConsumableType, ConsumableType::*, CraftedGearType, CraftedGearType::*, EncodingVersion, ItemType, SkillType, -}; +use idmangler_lib::types::{AttackSpeed, ClassType, ConsumableType, ConsumableType::*, CraftedGearType, CraftedGearType::*, EncodingVersion, ItemType, SkillType}; use serde::Deserialize; use std::fs; @@ -14,15 +12,7 @@ pub struct Jsonconfig { pub debug: Option, // Item Types (Gear, Tome, Charm, Crafted Gear, Crafted Consum) - #[serde( - alias = "itemtype", - alias = "ITEM_TYPE", - alias = "ITEMTYPE", - alias = "Item_Type", - alias = "Item_type", - alias = "ItemType", - alias = "Itemtype" - )] + #[serde(alias = "itemtype", alias = "ITEM_TYPE", alias = "ITEMTYPE", alias = "Item_Type", alias = "Item_type", alias = "ItemType", alias = "Itemtype")] pub item_type: ItemTypeDeser, // Crafted type for Crafted item types diff --git a/src/main.rs b/src/main.rs index d4a5cf0..ae80700 100644 --- a/src/main.rs +++ b/src/main.rs @@ -85,15 +85,16 @@ fn main() { // create necessary variables let ver = EncodingVersion::Version1; - let mut loaded_config_borrow = loaded_config.clone(); - // check if perfect status + 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 { - loaded_config_borrow.name = Some(t1) + namefr = t1 } // ENCODE: A Lot Of Stuff // Also print any mapped errors - let cooking = cook(&mut out, &debug_mode, ver, &mut loaded_config_borrow, loaded_idkeys, loaded_shinystats); + let cooking = cook(&mut out, &debug_mode, ver, &mut loaded_config_clone, loaded_idkeys, loaded_shinystats, namefr); if let Err(e) = cooking { println!("{}", e); // print error if there is an error } else { @@ -112,9 +113,7 @@ fn main() { } } -fn cook( - out: &mut Vec, debug_mode: &bool, ver: EncodingVersion, json_config: &mut Jsonconfig, idsmap: HashMap, json_shiny: Vec, -) -> Result { +fn cook(out: &mut Vec, debug_mode: &bool, ver: EncodingVersion, json_config: &mut Jsonconfig, idsmap: HashMap, json_shiny: Vec, namefr: String) -> Result { let mut fr_params = FuncParams { fr_out: out, fr_debug_mode: debug_mode, @@ -233,9 +232,3 @@ fn cook( Ok(final_string) } - -fn cook_perfect( - out: &mut Vec, debug_mode: &bool, ver: EncodingVersion, json_config: &Jsonconfig, idsmap: HashMap, json_shiny: Vec, -) -> Result { - Ok("fr".parse().unwrap()) -}