Add return Result<(),Errorfr> for everything just for the sake of future proofing

This commit is contained in:
endernon 2025-01-11 00:20:37 +00:00
parent 281ff67005
commit fb2a5e8c02

View file

@ -14,7 +14,7 @@ use idmangler_lib::{
use idmangler_lib::encoding::DataEncoder; use idmangler_lib::encoding::DataEncoder;
use std::collections::HashMap; use std::collections::HashMap;
pub fn encode_startdata(general_params: &mut FuncParams) { pub fn encode_startdata(general_params: &mut FuncParams) -> Result<(), Errorfr> {
if *general_params.fr_debug_mode { if *general_params.fr_debug_mode {
println!("Encoding StartData") println!("Encoding StartData")
} }
@ -22,8 +22,9 @@ pub fn encode_startdata(general_params: &mut FuncParams) {
StartData(general_params.fr_ver) StartData(general_params.fr_ver)
.encode(general_params.fr_ver, general_params.fr_out) .encode(general_params.fr_ver, general_params.fr_out)
.unwrap(); .unwrap();
Ok(())
} }
pub fn encode_typedata(general_params: &mut FuncParams, item_type_deser: ItemTypeDeser) { pub fn encode_typedata(general_params: &mut FuncParams, item_type_deser: ItemTypeDeser) -> Result<(), Errorfr> {
if *general_params.fr_debug_mode { if *general_params.fr_debug_mode {
println!("Encoding TypeData: {:?}", item_type_deser); println!("Encoding TypeData: {:?}", item_type_deser);
} }
@ -31,11 +32,9 @@ pub fn encode_typedata(general_params: &mut FuncParams, item_type_deser: ItemTyp
TypeData(ItemType::from(item_type_deser)) TypeData(ItemType::from(item_type_deser))
.encode(general_params.fr_ver, general_params.fr_out) .encode(general_params.fr_ver, general_params.fr_out)
.unwrap(); .unwrap();
Ok(())
} }
pub fn encode_typedata_custom( pub fn encode_typedata_custom(general_params: &mut FuncParams, crafted_type: &str) -> Result<(), Errorfr> {
general_params: &mut FuncParams,
crafted_type: &str,
) -> Result<(), Errorfr> {
let frfr_type = CraftedTypesFr::try_from(crafted_type)?; let frfr_type = CraftedTypesFr::try_from(crafted_type)?;
match frfr_type { match frfr_type {
CraftedTypesFr::Gear(a) => { CraftedTypesFr::Gear(a) => {
@ -57,10 +56,7 @@ pub fn encode_typedata_custom(
} }
Ok(()) Ok(())
} }
pub fn encode_duradata( pub fn encode_duradata(general_params: &mut FuncParams, real_dura: &Durability) -> Result<(), Errorfr> {
general_params: &mut FuncParams,
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. 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 let Some(effstr) = real_dura.effect_strength {
if *general_params.fr_debug_mode { if *general_params.fr_debug_mode {
@ -115,7 +111,7 @@ pub fn encode_duradata(
.unwrap(); .unwrap();
Ok(()) Ok(())
} }
pub fn encode_reqdata(general_params: &mut FuncParams, real_reqdata: RequirementsDeser) { pub fn encode_reqdata(general_params: &mut FuncParams, real_reqdata: RequirementsDeser) -> Result<(), Errorfr> {
if *general_params.fr_debug_mode { if *general_params.fr_debug_mode {
println!( println!(
"Encoding RequirementData.Level: {:?}", "Encoding RequirementData.Level: {:?}",
@ -145,9 +141,10 @@ pub fn encode_reqdata(general_params: &mut FuncParams, real_reqdata: Requirement
skills: spvec, skills: spvec,
} }
.encode(general_params.fr_ver, general_params.fr_out) .encode(general_params.fr_ver, general_params.fr_out)
.unwrap() .unwrap();
Ok(())
} }
pub fn encode_namedata(general_params: &mut FuncParams, real_name: &str) { pub fn encode_namedata(general_params: &mut FuncParams, real_name: &str) -> Result<(), Errorfr> {
// ENCODE: NameData // ENCODE: NameData
if *general_params.fr_debug_mode { if *general_params.fr_debug_mode {
println!("Encoding NameData: {:?}", &real_name) println!("Encoding NameData: {:?}", &real_name)
@ -155,12 +152,9 @@ pub fn encode_namedata(general_params: &mut FuncParams, real_name: &str) {
NameData(real_name.trim().to_string()) NameData(real_name.trim().to_string())
.encode(general_params.fr_ver, general_params.fr_out) .encode(general_params.fr_ver, general_params.fr_out)
.unwrap(); .unwrap();
Ok(())
} }
pub fn encode_iddata( pub fn encode_iddata(general_params: &mut FuncParams, real_ids: &Vec<Identificationer>, idsmap: HashMap<String, u8>) -> Result<(), Errorfr> {
general_params: &mut FuncParams,
real_ids: &Vec<Identificationer>,
idsmap: HashMap<String, u8>,
) {
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());
@ -193,6 +187,7 @@ pub fn encode_iddata(
} }
.encode(general_params.fr_ver, general_params.fr_out) .encode(general_params.fr_ver, general_params.fr_out)
.unwrap(); .unwrap();
Ok(())
} }
pub fn encode_powderdata(general_params: &mut FuncParams, real_powders: &Vec<PowderFr>) -> Result<(), Errorfr> { pub fn encode_powderdata(general_params: &mut FuncParams, real_powders: &Vec<PowderFr>) -> Result<(), Errorfr> {
let mut powdervec = Vec::new(); let mut powdervec = Vec::new();
@ -233,7 +228,7 @@ pub fn encode_powderdata(general_params: &mut FuncParams, real_powders: &Vec<Pow
.unwrap(); .unwrap();
Ok(()) Ok(())
} }
pub fn encode_rerolldata(general_params: &mut FuncParams, rerollcount: u8) { pub fn encode_rerolldata(general_params: &mut FuncParams, rerollcount: u8) -> Result<(), Errorfr> {
if rerollcount != 0 { if rerollcount != 0 {
// ENCODE: RerollData if applicable // ENCODE: RerollData if applicable
RerollData(rerollcount) RerollData(rerollcount)
@ -243,12 +238,9 @@ pub fn encode_rerolldata(general_params: &mut FuncParams, rerollcount: u8) {
dbg!(rerollcount); dbg!(rerollcount);
} }
} }
Ok(())
} }
pub fn encode_shinydata( pub fn encode_shinydata(general_params: &mut FuncParams, shiny: &Shinyjson, json_shiny: &Vec<Shinystruct>) -> Result<(), Errorfr> {
general_params: &mut FuncParams,
shiny: &Shinyjson,
json_shiny: &Vec<Shinystruct>,
) {
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,8 +264,9 @@ pub fn encode_shinydata(
} }
.encode(general_params.fr_ver, general_params.fr_out) .encode(general_params.fr_ver, general_params.fr_out)
.unwrap(); .unwrap();
Ok(())
} }
pub fn encode_enddata(general_params: &mut FuncParams) { pub fn encode_enddata(general_params: &mut FuncParams) -> Result<(), Errorfr> {
if *general_params.fr_debug_mode { if *general_params.fr_debug_mode {
println!("Encoding EndData") println!("Encoding EndData")
} }
@ -281,4 +274,5 @@ pub fn encode_enddata(general_params: &mut FuncParams) {
EndData EndData
.encode(general_params.fr_ver, general_params.fr_out) .encode(general_params.fr_ver, general_params.fr_out)
.unwrap(); .unwrap();
Ok(())
} }