Move all encode functions into an impl for FuncParams
This commit is contained in:
parent
bde76d6548
commit
3d00b8306a
2 changed files with 260 additions and 259 deletions
106
src/encode.rs
106
src/encode.rs
|
@ -14,52 +14,53 @@ use idmangler_lib::{
|
|||
use idmangler_lib::encoding::DataEncoder;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn encode_startdata(general_params: &mut FuncParams) -> Result<(), Errorfr> {
|
||||
if *general_params.fr_debug_mode {
|
||||
impl FuncParams<'_> {
|
||||
pub fn encode_startdata(&mut self) -> Result<(), Errorfr> {
|
||||
if *self.fr_debug_mode {
|
||||
println!("Encoding StartData")
|
||||
}
|
||||
// ENCODE: StartData
|
||||
StartData(general_params.fr_ver)
|
||||
.encode(general_params.fr_ver, general_params.fr_out)
|
||||
StartData(self.fr_ver)
|
||||
.encode(self.fr_ver, self.fr_out)
|
||||
.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
pub fn encode_typedata(general_params: &mut FuncParams, item_type_deser: ItemTypeDeser) -> Result<(), Errorfr> {
|
||||
if *general_params.fr_debug_mode {
|
||||
}
|
||||
pub fn encode_typedata(&mut self, item_type_deser: ItemTypeDeser) -> Result<(), Errorfr> {
|
||||
if *self.fr_debug_mode {
|
||||
println!("Encoding TypeData: {:?}", item_type_deser);
|
||||
}
|
||||
// ENCODE: TypeData
|
||||
TypeData(ItemType::from(item_type_deser))
|
||||
.encode(general_params.fr_ver, general_params.fr_out)
|
||||
.encode(self.fr_ver, self.fr_out)
|
||||
.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
pub fn encode_typedata_custom(general_params: &mut FuncParams, crafted_type: &str) -> Result<(), Errorfr> {
|
||||
}
|
||||
pub fn encode_typedata_custom(&mut self, crafted_type: &str) -> Result<(), Errorfr> {
|
||||
let frfr_type = CraftedTypesFr::try_from(crafted_type)?;
|
||||
match frfr_type {
|
||||
CraftedTypesFr::Gear(a) => {
|
||||
if *general_params.fr_debug_mode {
|
||||
if *self.fr_debug_mode {
|
||||
println!("Encoding CustomTypeData: Gear");
|
||||
}
|
||||
CraftedGearTypeData(a)
|
||||
.encode(general_params.fr_ver, general_params.fr_out)
|
||||
.encode(self.fr_ver, self.fr_out)
|
||||
.unwrap()
|
||||
}
|
||||
CraftedTypesFr::Consu(a) => {
|
||||
if *general_params.fr_debug_mode {
|
||||
if *self.fr_debug_mode {
|
||||
println!("Encoding CustomTypeData: Consumable");
|
||||
}
|
||||
CraftedConsumableTypeData(a)
|
||||
.encode(general_params.fr_ver, general_params.fr_out)
|
||||
.encode(self.fr_ver, self.fr_out)
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub fn encode_duradata(general_params: &mut FuncParams, real_dura: &Durability) -> Result<(), Errorfr> {
|
||||
}
|
||||
pub fn encode_duradata(&mut self, real_dura: &Durability) -> Result<(), Errorfr> {
|
||||
let effect_strength_fr: u8; // but actually it should be 0 to 100, not 0 to 255. But i dunno how to use u7 data type.
|
||||
if let Some(effstr) = real_dura.effect_strength {
|
||||
if *general_params.fr_debug_mode {
|
||||
if *self.fr_debug_mode {
|
||||
println!("Encoding DurabilityData: Defined");
|
||||
}
|
||||
effect_strength_fr = effstr
|
||||
|
@ -94,7 +95,7 @@ pub fn encode_duradata(general_params: &mut FuncParams, real_dura: &Durability)
|
|||
return Err(Errorfr::JsonDuraOutOfRange);
|
||||
}
|
||||
}
|
||||
if *general_params.fr_debug_mode {
|
||||
if *self.fr_debug_mode {
|
||||
println!(
|
||||
"Encoding DurabilityData.effect_strenght: {}",
|
||||
effect_strength_fr
|
||||
|
@ -107,12 +108,12 @@ pub fn encode_duradata(general_params: &mut FuncParams, real_dura: &Durability)
|
|||
current: real_dura.dura_cur,
|
||||
max: real_dura.dura_max,
|
||||
}
|
||||
.encode(general_params.fr_ver, general_params.fr_out)
|
||||
.encode(self.fr_ver, self.fr_out)
|
||||
.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
pub fn encode_reqdata(general_params: &mut FuncParams, real_reqdata: RequirementsDeser) -> Result<(), Errorfr> {
|
||||
if *general_params.fr_debug_mode {
|
||||
}
|
||||
pub fn encode_reqdata(&mut self, real_reqdata: RequirementsDeser) -> Result<(), Errorfr> {
|
||||
if *self.fr_debug_mode {
|
||||
println!(
|
||||
"Encoding RequirementData.Level: {:?}",
|
||||
real_reqdata.level.clone()
|
||||
|
@ -121,10 +122,10 @@ pub fn encode_reqdata(general_params: &mut FuncParams, real_reqdata: Requirement
|
|||
let mut fr_class: Option<ClassType> = None;
|
||||
if let Some(actualclass) = real_reqdata.class {
|
||||
fr_class = Some(ClassType::from(actualclass));
|
||||
if *general_params.fr_debug_mode {
|
||||
if *self.fr_debug_mode {
|
||||
println!("Encoding RequirementData.Class: {:?}", actualclass.clone())
|
||||
}
|
||||
} else if *general_params.fr_debug_mode {
|
||||
} else if *self.fr_debug_mode {
|
||||
println!("Encoding RequirementData.Class: Undefined");
|
||||
}
|
||||
|
||||
|
@ -132,7 +133,7 @@ pub fn encode_reqdata(general_params: &mut FuncParams, real_reqdata: Requirement
|
|||
Some(real_sp) => {Vec::<(SkillType, i32)>::from(real_sp)},
|
||||
None => {Vec::new()}
|
||||
};
|
||||
if *general_params.fr_debug_mode {
|
||||
if *self.fr_debug_mode {
|
||||
println!("Encoding RequirementData.Skills: {:?}", spvec.clone())
|
||||
}
|
||||
RequirementsData {
|
||||
|
@ -140,21 +141,21 @@ pub fn encode_reqdata(general_params: &mut FuncParams, real_reqdata: Requirement
|
|||
class: fr_class,
|
||||
skills: spvec,
|
||||
}
|
||||
.encode(general_params.fr_ver, general_params.fr_out)
|
||||
.encode(self.fr_ver, self.fr_out)
|
||||
.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
pub fn encode_namedata(general_params: &mut FuncParams, real_name: &str) -> Result<(), Errorfr> {
|
||||
}
|
||||
pub fn encode_namedata(&mut self, real_name: &str) -> Result<(), Errorfr> {
|
||||
// ENCODE: NameData
|
||||
if *general_params.fr_debug_mode {
|
||||
if *self.fr_debug_mode {
|
||||
println!("Encoding NameData: {:?}", &real_name)
|
||||
}
|
||||
NameData(real_name.trim().to_string())
|
||||
.encode(general_params.fr_ver, general_params.fr_out)
|
||||
.encode(self.fr_ver, self.fr_out)
|
||||
.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
pub fn encode_iddata(general_params: &mut FuncParams, 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();
|
||||
for eachid in real_ids {
|
||||
let id_id = idsmap.get(eachid.id.trim());
|
||||
|
@ -177,7 +178,7 @@ pub fn encode_iddata(general_params: &mut FuncParams, real_ids: &Vec<Identificat
|
|||
|
||||
// println!("{:?} {:?} {:?}",id_id,id_base,id_roll)
|
||||
}
|
||||
if *general_params.fr_debug_mode {
|
||||
if *self.fr_debug_mode {
|
||||
println!("Encoding IdentificationData: {:?}", &idvec)
|
||||
}
|
||||
// ENCODE: IdentificationsData
|
||||
|
@ -185,11 +186,11 @@ pub fn encode_iddata(general_params: &mut FuncParams, real_ids: &Vec<Identificat
|
|||
identifications: idvec,
|
||||
extended_encoding: true,
|
||||
}
|
||||
.encode(general_params.fr_ver, general_params.fr_out)
|
||||
.encode(self.fr_ver, self.fr_out)
|
||||
.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
pub fn encode_powderdata(general_params: &mut FuncParams, real_powders: &Vec<PowderFr>) -> Result<(), Errorfr> {
|
||||
}
|
||||
pub fn encode_powderdata(&mut self, real_powders: &Vec<PowderFr>) -> Result<(), Errorfr> {
|
||||
let mut powdervec = Vec::new();
|
||||
for eachpowder in real_powders {
|
||||
let powderamount: u8 = eachpowder.amount.unwrap_or(1);
|
||||
|
@ -203,7 +204,7 @@ pub fn encode_powderdata(general_params: &mut FuncParams, real_powders: &Vec<Pow
|
|||
'a' => Element::Air,
|
||||
_ => {return Err(Errorfr::JsonUnknownPowderElement)},
|
||||
};
|
||||
if *general_params.fr_debug_mode {
|
||||
if *self.fr_debug_mode {
|
||||
dbg!(eletype);
|
||||
}
|
||||
powdervec.push(
|
||||
|
@ -211,7 +212,7 @@ pub fn encode_powderdata(general_params: &mut FuncParams, real_powders: &Vec<Pow
|
|||
); // 6 is the tier. Wynntils ONLY really uses tier 6 so theres no point keeping others.
|
||||
}
|
||||
}
|
||||
if *general_params.fr_debug_mode {
|
||||
if *self.fr_debug_mode {
|
||||
dbg!(&powdervec);
|
||||
}
|
||||
|
||||
|
@ -224,23 +225,23 @@ pub fn encode_powderdata(general_params: &mut FuncParams, real_powders: &Vec<Pow
|
|||
powder_slots: powderlimitfr,
|
||||
powders: powdervec,
|
||||
}
|
||||
.encode(general_params.fr_ver, general_params.fr_out)
|
||||
.encode(self.fr_ver, self.fr_out)
|
||||
.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
pub fn encode_rerolldata(general_params: &mut FuncParams, rerollcount: u8) -> Result<(), Errorfr> {
|
||||
}
|
||||
pub fn encode_rerolldata(&mut self, rerollcount: u8) -> Result<(), Errorfr> {
|
||||
if rerollcount != 0 {
|
||||
// ENCODE: RerollData if applicable
|
||||
RerollData(rerollcount)
|
||||
.encode(general_params.fr_ver, general_params.fr_out)
|
||||
.encode(self.fr_ver, self.fr_out)
|
||||
.unwrap();
|
||||
if *general_params.fr_debug_mode {
|
||||
if *self.fr_debug_mode {
|
||||
dbg!(rerollcount);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub fn encode_shinydata(general_params: &mut FuncParams, 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 _shinykey = &shiny.key;
|
||||
let shinyvalue = shiny.value;
|
||||
|
@ -248,12 +249,12 @@ pub fn encode_shinydata(general_params: &mut FuncParams, shiny: &Shinyjson, json
|
|||
for i in json_shiny {
|
||||
if i.key == shiny.key {
|
||||
realshinykey = i.id;
|
||||
if *general_params.fr_debug_mode {
|
||||
if *self.fr_debug_mode {
|
||||
dbg!(&shiny.key);
|
||||
}
|
||||
}
|
||||
}
|
||||
if *general_params.fr_debug_mode {
|
||||
if *self.fr_debug_mode {
|
||||
dbg!(&realshinykey);
|
||||
dbg!(&shinyvalue);
|
||||
}
|
||||
|
@ -262,17 +263,18 @@ pub fn encode_shinydata(general_params: &mut FuncParams, shiny: &Shinyjson, json
|
|||
id: realshinykey,
|
||||
val: shinyvalue,
|
||||
}
|
||||
.encode(general_params.fr_ver, general_params.fr_out)
|
||||
.encode(self.fr_ver, self.fr_out)
|
||||
.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
pub fn encode_enddata(general_params: &mut FuncParams) -> Result<(), Errorfr> {
|
||||
if *general_params.fr_debug_mode {
|
||||
}
|
||||
pub fn encode_enddata(&mut self) -> Result<(), Errorfr> {
|
||||
if *self.fr_debug_mode {
|
||||
println!("Encoding EndData")
|
||||
}
|
||||
// ENCODE: EndData
|
||||
EndData
|
||||
.encode(general_params.fr_ver, general_params.fr_out)
|
||||
.encode(self.fr_ver, self.fr_out)
|
||||
.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
}
|
23
src/main.rs
23
src/main.rs
|
@ -8,7 +8,6 @@ mod encode;
|
|||
mod errorfr;
|
||||
mod jsondl;
|
||||
mod jsonstruct;
|
||||
use crate::encode::*;
|
||||
use crate::errorfr::Errorfr;
|
||||
use crate::jsondl::*;
|
||||
use crate::jsonstruct::*;
|
||||
|
@ -126,14 +125,14 @@ fn cook(
|
|||
};
|
||||
|
||||
// ENCODE: StartData and TypeData, ALWAYS
|
||||
encode_startdata(&mut fr_params)?;
|
||||
encode_typedata(&mut fr_params, json_config.item_type)?;
|
||||
fr_params.encode_startdata()?;
|
||||
fr_params.encode_typedata(json_config.item_type)?;
|
||||
|
||||
// ENCODE: CustomGearTypeData / CustomConsumableTypeData
|
||||
match json_config.item_type {
|
||||
ItemTypeDeser::CraftedGear | ItemTypeDeser::CraftedConsu => {
|
||||
if let Some(real_crafted_type) = &json_config.crafted_type {
|
||||
encode_typedata_custom(&mut fr_params, real_crafted_type)?;
|
||||
fr_params.encode_typedata_custom(real_crafted_type)?;
|
||||
} else {
|
||||
return Err(JsonNotFoundCraftedType);
|
||||
}
|
||||
|
@ -145,7 +144,7 @@ fn cook(
|
|||
match json_config.item_type {
|
||||
ItemTypeDeser::Gear | ItemTypeDeser::Tome | ItemTypeDeser::Charm => {
|
||||
if let Some(real_name) = &json_config.name {
|
||||
encode_namedata(&mut fr_params, real_name)?
|
||||
fr_params.encode_namedata(real_name)?
|
||||
} else {
|
||||
return Err(Errorfr::JsonNotFoundName);
|
||||
}
|
||||
|
@ -157,7 +156,7 @@ fn cook(
|
|||
match json_config.item_type {
|
||||
ItemTypeDeser::Gear | ItemTypeDeser::Tome | ItemTypeDeser::Charm => {
|
||||
if let Some(real_ids) = &json_config.ids {
|
||||
encode_iddata(&mut fr_params, real_ids, idsmap)?
|
||||
fr_params.encode_iddata(real_ids, idsmap)?
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
@ -167,7 +166,7 @@ fn cook(
|
|||
match json_config.item_type {
|
||||
ItemTypeDeser::CraftedGear => {
|
||||
if let Some(real_dura) = &json_config.durability {
|
||||
encode_duradata(&mut fr_params, real_dura)?;
|
||||
fr_params.encode_duradata(real_dura)?;
|
||||
} else {
|
||||
return Err(Errorfr::JsonNotFoundDura);
|
||||
}
|
||||
|
@ -179,7 +178,7 @@ fn cook(
|
|||
match json_config.item_type {
|
||||
ItemTypeDeser::CraftedGear | ItemTypeDeser::CraftedConsu => {
|
||||
if let Some(real_reqs) = json_config.requirements {
|
||||
encode_reqdata(&mut fr_params, real_reqs)?
|
||||
fr_params.encode_reqdata(real_reqs)?
|
||||
} else {
|
||||
return Err(Errorfr::JsonNotFoundReqs);
|
||||
}
|
||||
|
@ -191,7 +190,7 @@ fn cook(
|
|||
match json_config.item_type {
|
||||
ItemTypeDeser::Gear | ItemTypeDeser::CraftedGear => {
|
||||
if let Some(real_powders) = &json_config.powders {
|
||||
encode_powderdata(&mut fr_params, real_powders)?
|
||||
fr_params.encode_powderdata(real_powders)?
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
@ -202,7 +201,7 @@ fn cook(
|
|||
ItemTypeDeser::Gear | ItemTypeDeser::Tome | ItemTypeDeser::Charm => {
|
||||
if let Some(rerollcount) = json_config.rerolls {
|
||||
// rerolldata
|
||||
encode_rerolldata(&mut fr_params, rerollcount)?
|
||||
fr_params.encode_rerolldata(rerollcount)?
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
@ -212,14 +211,14 @@ fn cook(
|
|||
match json_config.item_type {
|
||||
ItemTypeDeser::Gear => {
|
||||
if let Some(shiny) = &json_config.shiny {
|
||||
encode_shinydata(&mut fr_params, shiny, &json_shiny)?
|
||||
fr_params.encode_shinydata(shiny, &json_shiny)?
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
// ENCODE: EndData, ALWAYS
|
||||
encode_enddata(&mut fr_params)?;
|
||||
fr_params.encode_enddata()?;
|
||||
|
||||
let mut final_string: String = encode_string(out);
|
||||
|
||||
|
|
Loading…
Reference in a new issue