cargo fmt

This commit is contained in:
endernon 2025-01-11 00:45:41 +00:00
parent 385a0af747
commit 9066e96a7c
5 changed files with 42 additions and 40 deletions

View file

@ -1 +1 @@
fn_params_layout = "Tall" fn_params_layout = "Compressed"

View file

@ -3,15 +3,15 @@ use crate::jsonstruct::{
CraftedTypesFr, Durability, FuncParams, Identificationer, ItemTypeDeser, PowderFr, CraftedTypesFr, Durability, FuncParams, Identificationer, ItemTypeDeser, PowderFr,
RequirementsDeser, Shinyjson, Shinystruct, RequirementsDeser, Shinyjson, Shinystruct,
}; };
use idmangler_lib::encoding::DataEncoder;
use idmangler_lib::{ use idmangler_lib::{
types::{ClassType, Element, ItemType, RollType, SkillType, Stat, Powder},
block::{ block::{
CraftedConsumableTypeData, CraftedGearTypeData, DurabilityData, EndData, CraftedConsumableTypeData, CraftedGearTypeData, DurabilityData, EndData,
IdentificationData, NameData, PowderData, RequirementsData, RerollData, ShinyData, StartData, IdentificationData, NameData, PowderData, RequirementsData, RerollData, ShinyData,
TypeData, StartData, TypeData,
} },
types::{ClassType, Element, ItemType, Powder, RollType, SkillType, Stat},
}; };
use idmangler_lib::encoding::DataEncoder;
use std::collections::HashMap; use std::collections::HashMap;
impl FuncParams<'_> { impl FuncParams<'_> {
@ -76,13 +76,14 @@ impl FuncParams<'_> {
// for 50% dura to 10% dura, the effectiveness is 100% to 50% // for 50% dura to 10% dura, the effectiveness is 100% to 50%
// see this answer from Stackoverflow for transcribing range // see this answer from Stackoverflow for transcribing range
// https://stackoverflow.com/a/929107 // https://stackoverflow.com/a/929107
// old range is 50-10 = 40 // old range is 50-10 = 40
let old_range = 40; let old_range = 40;
// new range is 100-50 = 50 // new range is 100-50 = 50
let new_range = 50; let new_range = 50;
// NewValue = (((OldValue - OldMin) * NewRange) / OldRange) + NewMin // 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 { } else if current_percentage >= 0 {
// for 10% dura to 0% dura, the effectiveness is 50% to 10% // for 10% dura to 0% dura, the effectiveness is 50% to 10%
// old range is 10-0 = 10 // old range is 10-0 = 10
@ -128,10 +129,10 @@ impl FuncParams<'_> {
} else if *self.fr_debug_mode { } else if *self.fr_debug_mode {
println!("Encoding RequirementData.Class: Undefined"); println!("Encoding RequirementData.Class: Undefined");
} }
let spvec: Vec<(SkillType, i32)> = match real_reqdata.sp { let spvec: Vec<(SkillType, i32)> = match real_reqdata.sp {
Some(real_sp) => {Vec::<(SkillType, i32)>::from(real_sp)}, Some(real_sp) => Vec::<(SkillType, i32)>::from(real_sp),
None => {Vec::new()} None => Vec::new(),
}; };
if *self.fr_debug_mode { if *self.fr_debug_mode {
println!("Encoding RequirementData.Skills: {:?}", spvec.clone()) println!("Encoding RequirementData.Skills: {:?}", spvec.clone())
@ -155,13 +156,17 @@ impl FuncParams<'_> {
.unwrap(); .unwrap();
Ok(()) Ok(())
} }
pub fn encode_iddata(&mut self, real_ids: &Vec<Identificationer>, idsmap: HashMap<String, u8>) -> Result<(), Errorfr> { pub fn encode_iddata(
&mut self,
real_ids: &Vec<Identificationer>,
idsmap: HashMap<String, u8>,
) -> Result<(), Errorfr> {
let mut idvec = Vec::new(); let mut idvec = Vec::new();
for eachid in real_ids { for eachid in real_ids {
let id_id = idsmap.get(eachid.id.trim()); let id_id = idsmap.get(eachid.id.trim());
let id_base = eachid.base; let id_base = eachid.base;
let id_roll = eachid.roll; let id_roll = eachid.roll;
idvec.push( idvec.push(
Stat { Stat {
kind: match id_id { kind: match id_id {
@ -175,7 +180,7 @@ impl FuncParams<'_> {
} }
} }
); );
// println!("{:?} {:?} {:?}",id_id,id_base,id_roll) // println!("{:?} {:?} {:?}",id_id,id_base,id_roll)
} }
if *self.fr_debug_mode { if *self.fr_debug_mode {
@ -202,22 +207,22 @@ impl FuncParams<'_> {
'w' => Element::Water, 'w' => Element::Water,
'f' => Element::Fire, 'f' => Element::Fire,
'a' => Element::Air, 'a' => Element::Air,
_ => {return Err(Errorfr::JsonUnknownPowderElement)}, _ => return Err(Errorfr::JsonUnknownPowderElement),
}; };
if *self.fr_debug_mode { if *self.fr_debug_mode {
dbg!(eletype); dbg!(eletype);
} }
powdervec.push( powdervec
Powder::new(eletype, 6).map_err(|_| Errorfr::JsonUnknownPowderTier)? .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. // 6 is the tier. Wynntils ONLY really uses tier 6 so theres no point keeping others.
} }
} }
if *self.fr_debug_mode { if *self.fr_debug_mode {
dbg!(&powdervec); 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) 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 // ENCODE: PowderData
// only occurs if the powders array is present and the powder limit is also present // only occurs if the powders array is present and the powder limit is also present
// //
@ -241,7 +246,11 @@ impl FuncParams<'_> {
} }
Ok(()) Ok(())
} }
pub fn encode_shinydata(&mut self, shiny: &Shinyjson, json_shiny: &Vec<Shinystruct>) -> Result<(), Errorfr> { pub fn encode_shinydata(
&mut self,
shiny: &Shinyjson,
json_shiny: &Vec<Shinystruct>,
) -> Result<(), Errorfr> {
let mut realshinykey: u8; let mut realshinykey: u8;
let _shinykey = &shiny.key; let _shinykey = &shiny.key;
let shinyvalue = shiny.value; let shinyvalue = shiny.value;
@ -272,9 +281,7 @@ impl FuncParams<'_> {
println!("Encoding EndData") println!("Encoding EndData")
} }
// ENCODE: EndData // ENCODE: EndData
EndData EndData.encode(self.fr_ver, self.fr_out).unwrap();
.encode(self.fr_ver, self.fr_out)
.unwrap();
Ok(()) Ok(())
} }
} }

View file

@ -70,16 +70,12 @@ pub enum Errorfr {
"Error 4.6: \"requirements\" was not found (necessary for Crafted Gear / Consumable items)" "Error 4.6: \"requirements\" was not found (necessary for Crafted Gear / Consumable items)"
)] )]
JsonNotFoundReqs, JsonNotFoundReqs,
/// Unrecognisable Powder tier /// Unrecognisable Powder tier
#[error( #[error("Error 4.7: Unknown powder tier")]
"Error 4.7: Unknown powder tier"
)]
JsonUnknownPowderTier, JsonUnknownPowderTier,
/// Unrecognisable Powder element /// Unrecognisable Powder element
#[error( #[error("Error 4.8: Unknown powder element")]
"Error 4.8: Unknown powder element"
)]
JsonUnknownPowderElement, JsonUnknownPowderElement,
} }

View file

@ -1,7 +1,7 @@
use crate::errorfr::Errorfr; use crate::errorfr::Errorfr;
use crate::jsonstruct::CraftedTypesFr::{Consu, Gear}; use crate::jsonstruct::CraftedTypesFr::{Consu, Gear};
use idmangler_lib::types::{ClassType, ConsumableType::*, CraftedGearType::*, SkillType}; 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 serde::Deserialize;
use std::fs; use std::fs;

View file

@ -78,8 +78,7 @@ fn main() {
// create necessary variables // create necessary variables
let ver = EncodingVersion::Version1; let ver = EncodingVersion::Version1;
let loaded_config_borrow = &loaded_config; let loaded_config_borrow = &loaded_config;
// ENCODE: ALotOfStuff // ENCODE: ALotOfStuff
// Also print any mapped errors // Also print any mapped errors
@ -96,7 +95,7 @@ fn main() {
} else { } else {
// final string print if there is no error // final string print if there is no error
println!("{}",cooking.unwrap()) println!("{}", cooking.unwrap())
} }
} }
Err(e) => println!("{}", e), Err(e) => println!("{}", e),
@ -123,7 +122,7 @@ fn cook(
fr_debug_mode: debug_mode, fr_debug_mode: debug_mode,
fr_ver: ver, fr_ver: ver,
}; };
// ENCODE: StartData and TypeData, ALWAYS // ENCODE: StartData and TypeData, ALWAYS
fr_params.encode_startdata()?; fr_params.encode_startdata()?;
fr_params.encode_typedata(json_config.item_type)?; fr_params.encode_typedata(json_config.item_type)?;
@ -219,9 +218,9 @@ fn cook(
// ENCODE: EndData, ALWAYS // ENCODE: EndData, ALWAYS
fr_params.encode_enddata()?; fr_params.encode_enddata()?;
let mut final_string: String = encode_string(out); let mut final_string: String = encode_string(out);
// add NameAfter // add NameAfter
match json_config.item_type { match json_config.item_type {
ItemTypeDeser::CraftedGear | ItemTypeDeser::CraftedConsu => { ItemTypeDeser::CraftedGear | ItemTypeDeser::CraftedConsu => {
@ -233,6 +232,6 @@ fn cook(
} }
_ => {} _ => {}
} }
Ok(final_string) Ok(final_string)
} }