From 9066e96a7c9f1f989d94688c0d152fa020d3aa1d Mon Sep 17 00:00:00 2001 From: endernon Date: Sat, 11 Jan 2025 00:45:41 +0000 Subject: [PATCH] cargo fmt --- rustfmt.toml | 2 +- src/encode.rs | 55 ++++++++++++++++++++++++++--------------------- src/errorfr.rs | 10 +++------ src/jsonstruct.rs | 2 +- src/main.rs | 13 ++++++----- 5 files changed, 42 insertions(+), 40 deletions(-) diff --git a/rustfmt.toml b/rustfmt.toml index 4fa0153..e3d2c6b 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1 @@ -fn_params_layout = "Tall" \ No newline at end of file +fn_params_layout = "Compressed" \ No newline at end of file diff --git a/src/encode.rs b/src/encode.rs index fa3b6a8..7c828c1 100644 --- a/src/encode.rs +++ b/src/encode.rs @@ -3,15 +3,15 @@ use crate::jsonstruct::{ CraftedTypesFr, Durability, FuncParams, Identificationer, ItemTypeDeser, PowderFr, RequirementsDeser, Shinyjson, Shinystruct, }; +use idmangler_lib::encoding::DataEncoder; use idmangler_lib::{ - types::{ClassType, Element, ItemType, RollType, SkillType, Stat, Powder}, block::{ CraftedConsumableTypeData, CraftedGearTypeData, DurabilityData, EndData, - IdentificationData, NameData, PowderData, RequirementsData, RerollData, ShinyData, StartData, - TypeData, - } + IdentificationData, NameData, PowderData, RequirementsData, RerollData, ShinyData, + StartData, TypeData, + }, + types::{ClassType, Element, ItemType, Powder, RollType, SkillType, Stat}, }; -use idmangler_lib::encoding::DataEncoder; use std::collections::HashMap; impl FuncParams<'_> { @@ -76,13 +76,14 @@ impl FuncParams<'_> { // for 50% dura to 10% dura, the effectiveness is 100% to 50% // see this answer from Stackoverflow for transcribing range // https://stackoverflow.com/a/929107 - + // old range is 50-10 = 40 let old_range = 40; // new range is 100-50 = 50 let new_range = 50; // NewValue = (((OldValue - OldMin) * NewRange) / OldRange) + NewMin - effect_strength_fr = ((((current_percentage - 10) * new_range) / old_range) + 50) as u8 + effect_strength_fr = + ((((current_percentage - 10) * new_range) / old_range) + 50) as u8 } else if current_percentage >= 0 { // for 10% dura to 0% dura, the effectiveness is 50% to 10% // old range is 10-0 = 10 @@ -128,10 +129,10 @@ impl FuncParams<'_> { } else if *self.fr_debug_mode { println!("Encoding RequirementData.Class: Undefined"); } - + let spvec: Vec<(SkillType, i32)> = match real_reqdata.sp { - Some(real_sp) => {Vec::<(SkillType, i32)>::from(real_sp)}, - None => {Vec::new()} + Some(real_sp) => Vec::<(SkillType, i32)>::from(real_sp), + None => Vec::new(), }; if *self.fr_debug_mode { println!("Encoding RequirementData.Skills: {:?}", spvec.clone()) @@ -155,13 +156,17 @@ impl FuncParams<'_> { .unwrap(); Ok(()) } - pub fn encode_iddata(&mut self, real_ids: &Vec, idsmap: HashMap) -> Result<(), Errorfr> { + pub fn encode_iddata( + &mut self, + real_ids: &Vec, + idsmap: HashMap, + ) -> Result<(), Errorfr> { let mut idvec = Vec::new(); for eachid in real_ids { let id_id = idsmap.get(eachid.id.trim()); let id_base = eachid.base; let id_roll = eachid.roll; - + idvec.push( Stat { kind: match id_id { @@ -175,7 +180,7 @@ impl FuncParams<'_> { } } ); - + // println!("{:?} {:?} {:?}",id_id,id_base,id_roll) } if *self.fr_debug_mode { @@ -202,22 +207,22 @@ impl FuncParams<'_> { 'w' => Element::Water, 'f' => Element::Fire, 'a' => Element::Air, - _ => {return Err(Errorfr::JsonUnknownPowderElement)}, + _ => return Err(Errorfr::JsonUnknownPowderElement), }; if *self.fr_debug_mode { dbg!(eletype); } - powdervec.push( - Powder::new(eletype, 6).map_err(|_| Errorfr::JsonUnknownPowderTier)? - ); // 6 is the tier. Wynntils ONLY really uses tier 6 so theres no point keeping others. + powdervec + .push(Powder::new(eletype, 6).map_err(|_| Errorfr::JsonUnknownPowderTier)?); + // 6 is the tier. Wynntils ONLY really uses tier 6 so theres no point keeping others. } } if *self.fr_debug_mode { dbg!(&powdervec); } - + let powderlimitfr: u8 = powdervec.len() as u8; // min of the current number of powders and 255 (if you have over 255 powders stuff breaks) - + // ENCODE: PowderData // only occurs if the powders array is present and the powder limit is also present // @@ -241,7 +246,11 @@ impl FuncParams<'_> { } Ok(()) } - pub fn encode_shinydata(&mut self, shiny: &Shinyjson, json_shiny: &Vec) -> Result<(), Errorfr> { + pub fn encode_shinydata( + &mut self, + shiny: &Shinyjson, + json_shiny: &Vec, + ) -> Result<(), Errorfr> { let mut realshinykey: u8; let _shinykey = &shiny.key; let shinyvalue = shiny.value; @@ -272,9 +281,7 @@ impl FuncParams<'_> { println!("Encoding EndData") } // ENCODE: EndData - EndData - .encode(self.fr_ver, self.fr_out) - .unwrap(); + EndData.encode(self.fr_ver, self.fr_out).unwrap(); Ok(()) } -} \ No newline at end of file +} diff --git a/src/errorfr.rs b/src/errorfr.rs index ef12013..59a3f76 100644 --- a/src/errorfr.rs +++ b/src/errorfr.rs @@ -70,16 +70,12 @@ pub enum Errorfr { "Error 4.6: \"requirements\" was not found (necessary for Crafted Gear / Consumable items)" )] JsonNotFoundReqs, - + /// Unrecognisable Powder tier - #[error( - "Error 4.7: Unknown powder tier" - )] + #[error("Error 4.7: Unknown powder tier")] JsonUnknownPowderTier, /// Unrecognisable Powder element - #[error( - "Error 4.8: Unknown powder element" - )] + #[error("Error 4.8: Unknown powder element")] JsonUnknownPowderElement, } diff --git a/src/jsonstruct.rs b/src/jsonstruct.rs index 0cef12e..89abafd 100644 --- a/src/jsonstruct.rs +++ b/src/jsonstruct.rs @@ -1,7 +1,7 @@ use crate::errorfr::Errorfr; use crate::jsonstruct::CraftedTypesFr::{Consu, Gear}; use idmangler_lib::types::{ClassType, ConsumableType::*, CraftedGearType::*, SkillType}; -use idmangler_lib::types::{ConsumableType, CraftedGearType, ItemType, EncodingVersion}; +use idmangler_lib::types::{ConsumableType, CraftedGearType, EncodingVersion, ItemType}; use serde::Deserialize; use std::fs; diff --git a/src/main.rs b/src/main.rs index 0b96d68..46a1b44 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,8 +78,7 @@ fn main() { // create necessary variables let ver = EncodingVersion::Version1; - - + let loaded_config_borrow = &loaded_config; // ENCODE: ALotOfStuff // Also print any mapped errors @@ -96,7 +95,7 @@ fn main() { } else { // final string print if there is no error - println!("{}",cooking.unwrap()) + println!("{}", cooking.unwrap()) } } Err(e) => println!("{}", e), @@ -123,7 +122,7 @@ fn cook( fr_debug_mode: debug_mode, fr_ver: ver, }; - + // ENCODE: StartData and TypeData, ALWAYS fr_params.encode_startdata()?; fr_params.encode_typedata(json_config.item_type)?; @@ -219,9 +218,9 @@ fn cook( // ENCODE: EndData, ALWAYS fr_params.encode_enddata()?; - + let mut final_string: String = encode_string(out); - + // add NameAfter match json_config.item_type { ItemTypeDeser::CraftedGear | ItemTypeDeser::CraftedConsu => { @@ -233,6 +232,6 @@ fn cook( } _ => {} } - + Ok(final_string) }