From 13e4eb76a9095adbe460676be55e378cf2d80395 Mon Sep 17 00:00:00 2001 From: endernon Date: Wed, 1 Jan 2025 18:07:46 +0000 Subject: [PATCH] modular mode hellyeah --- src/main.rs | 117 ++++++++++++++++++++++++------------------ src/structures/mod.rs | 12 ++++- 2 files changed, 76 insertions(+), 53 deletions(-) diff --git a/src/main.rs b/src/main.rs index 27922db..54e3c4b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,19 +81,16 @@ fn main() { // create necessary variables let ver = TransformVersion::Version1; - // StartData and TypeData are always present - encode_startdata(&mut out, ver); - encode_typedata(&mut out, ver, loaded_config.item_type); - // ENCODE: ALotOfStuff // Also print any mapped errors if let Err(e) = cook( + &mut out, &debug_mode, + ver, loaded_config, loaded_idkeys, loaded_shinystats, - &mut out, - ver, + ) { println!("{}", e); }; @@ -113,30 +110,31 @@ fn main() { } } } -fn cook( - debug_mode: &bool, - json_config: Jsonconfig, - idsmap: HashMap, - json_shiny: Vec, - out: &mut Vec, - ver: TransformVersion, +fn cook(out: &mut Vec, debug_mode: &bool, ver: TransformVersion, json_config: Jsonconfig, idsmap: HashMap, json_shiny: Vec, + ) -> Result<(), Errorfr> { + + let mut func_params_outer = FuncParams { + fr_out: &mut out, + fr_debug_mode: &debug_mode, + fr_ver: ver, + }; + + // StartData and TypeData are always present + encode_startdata(out, ver); + encode_typedata(out, ver, json_config.item_type); + // ENCODE: NameData if let Some(real_name) = json_config.name { - NameData(real_name.trim().to_string()) - .encode(ver, out) - .unwrap(); + encode_namedata(out, ver, &real_name) } - // json identification data handling for type GEAR (0) // only occurs if identifications block is present if let Some(real_ids) = json_config.ids { encode_ids(out, real_ids, ver, idsmap) } - - // json powder data handling if let Some(real_powders) = json_config.powders { encode_powder(out, debug_mode, real_powders, ver) @@ -144,39 +142,12 @@ fn cook( if let Some(rerollcount) = json_config.rerolls { - if rerollcount != 0 { - // ENCODE: RerollData if applicable - RerollData(rerollcount).encode(ver, out).unwrap(); - if *debug_mode { - dbg!(rerollcount); - }; - }; + // rerolldata + encode_reroll(out, debug_mode, ver, rerollcount) }; - let mut realshinykey: u8; if let Some(shiny) = json_config.shiny { - let _shinykey = &shiny.key; - let shinyvalue = shiny.value; - realshinykey = 1; - for i in json_shiny { - if i.key == shiny.key { - realshinykey = i.id; - if *debug_mode { - dbg!(&shiny.key); - } - } - } - if *debug_mode { - dbg!(&realshinykey); - dbg!(&shinyvalue); - } - // ENCODE: ShinyData (if applicable) - ShinyData { - id: realshinykey, - val: shinyvalue, - } - .encode(ver, out) - .unwrap(); + encode_shiny(out, debug_mode, ver, shiny, json_shiny) } Ok(()) @@ -223,7 +194,9 @@ fn dl_json_fr(dlvalue: &String, executable_path: &str) { } fn encode_startdata(out: &mut Vec, ver: TransformVersion) { // ENCODE: StartData - StartData(ver).encode(ver, out).unwrap(); + StartData(ver) + .encode(ver, out) + .unwrap(); } fn encode_typedata(out: &mut Vec, ver: TransformVersion, item_type_deser: ItemTypeDeser) { // ENCODE: TypeData @@ -231,6 +204,12 @@ fn encode_typedata(out: &mut Vec, ver: TransformVersion, item_type_deser: It .encode(ver, out) .unwrap(); } +fn encode_namedata(out: &mut Vec, ver: TransformVersion, real_name: &String) { + // ENCODE: NameData + NameData(real_name.trim().to_string()) + .encode(ver, out) + .unwrap(); +} fn encode_powder(out: &mut Vec, debug_mode: &bool, real_powders: Vec, ver: TransformVersion) { let mut powdervec = Vec::new(); for eachpowder in real_powders { @@ -268,6 +247,15 @@ fn encode_powder(out: &mut Vec, debug_mode: &bool, real_powders: Vec .encode(ver, out) .unwrap(); } +fn encode_reroll(out: &mut Vec, debug_mode: &bool, ver: TransformVersion, rerollcount: u8) { + if rerollcount != 0 { + // ENCODE: RerollData if applicable + RerollData(rerollcount).encode(ver, out).unwrap(); + if *debug_mode { + dbg!(rerollcount); + } + } +} fn encode_ids(out: &mut Vec, real_ids: Vec, ver: TransformVersion, idsmap: HashMap) { let mut idvec = Vec::new(); for eachid in real_ids { @@ -299,7 +287,34 @@ fn encode_ids(out: &mut Vec, real_ids: Vec, ver: Transform .encode(ver, out) .unwrap(); } +fn encode_shiny(out: &mut Vec, debug_mode: &bool, ver: TransformVersion, shiny: Shinyjson, json_shiny: Vec) { + let mut realshinykey: u8; + let _shinykey = &shiny.key; + let shinyvalue = shiny.value; + realshinykey = 1; + for i in json_shiny { + if i.key == shiny.key { + realshinykey = i.id; + if *debug_mode { + dbg!(&shiny.key); + } + } + } + if *debug_mode { + dbg!(&realshinykey); + dbg!(&shinyvalue); + } + // ENCODE: ShinyData (if applicable) + ShinyData { + id: realshinykey, + val: shinyvalue, + } + .encode(ver, out) + .unwrap(); +} fn encode_enddata(out: &mut Vec, ver: TransformVersion) { // ENCODE: EndData - EndData.encode(ver, out).unwrap(); + EndData + .encode(ver, out) + .unwrap(); } \ No newline at end of file diff --git a/src/structures/mod.rs b/src/structures/mod.rs index 50f0ba6..bb2e688 100644 --- a/src/structures/mod.rs +++ b/src/structures/mod.rs @@ -1,6 +1,6 @@ -use idmangler_lib::types::ItemType; +use idmangler_lib::types::{ItemType, TransformVersion}; use serde::Deserialize; -// structs +// structs for the json parsing #[derive(Deserialize)] pub struct Powder { pub r#type: char, @@ -34,6 +34,13 @@ pub struct Shinyjson { pub value: i64, } +pub struct FuncParams<'a> { + pub fr_out: &'a mut Vec, + pub fr_debug_mode: &'a bool, + pub fr_ver: TransformVersion +} + + // I had to clone this and add Deserialize because the original idmangler_lib::types::ItemType does not #[repr(u8)] #[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash, Debug, Deserialize)] @@ -56,6 +63,7 @@ impl From for ItemType { } } +// stuff for the bit for downloading data jsons for ease of use #[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash, Debug, Deserialize)] pub enum DownloadJsons { None,