From 78b6e9ddcc593f11b733f7c07bc77f3f4de9f65d Mon Sep 17 00:00:00 2001 From: endernon Date: Tue, 31 Dec 2024 00:06:08 +0000 Subject: [PATCH] better method of loading files, because this is necessary for implementing other item types --- src/main.rs | 81 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 27 deletions(-) diff --git a/src/main.rs b/src/main.rs index bb4044f..566f38b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,38 +81,37 @@ fn main() { }; if let Some(T) = &args.config { - if let Err(e) = cook(args, executable_path, debug_mode) { - println!("{}", e); + match load_jsonconfig(T) { + Ok(loaded_config) => { + if let Some(debugconfig) = loaded_config.debug { + if debugconfig { + debug_mode = true + } + } + match load_idkeys(executable_path) { + Ok(loaded_idkeys) => { + match load_shinystats(executable_path) { + Ok(loaded_shinystats) => { + if let Err(e) = cook_0(debug_mode, loaded_config, loaded_idkeys, loaded_shinystats) { + println!("{}", e); + } + println!("debug mode: {}", debug_mode) + }, + Err(E) => println!("{}",E) + } + } + Err(E) => println!("{}",E) + } + } + Err(E) => println!("{}",E) } } } - -fn cook(args: Args, executable_path: &str, mut debug_mode: bool) -> Result<(), Errorfr> { - let config = args.config; - - +// 0: Gear +fn cook_0(mut debug_mode: bool, json_config: Jsonconfig, idsmap: HashMap, json_shiny: Vec) -> Result<(), Errorfr> { // load configs - let json_config: Jsonconfig = - serde_json::from_reader(fs::File::open(config.unwrap()).map_err(|_| Errorfr::ItemJsonMissing)?) - .map_err(Errorfr::ItemJsonCorrupt)?; - let idsmap: HashMap = serde_json::from_reader( - fs::File::open(executable_path.to_owned() + "/id_keys.json") - .map_err(|_| Errorfr::IDMapJsonMissing)?, - ) - .map_err(|_| Errorfr::IDMapJsonCorrupt)?; - let json_shiny: Vec = serde_json::from_reader( - fs::File::open(executable_path.to_owned() + "/shiny_stats.json") - .map_err(|_| Errorfr::ShinyJsonMissing)?, - ) - .map_err(|_| Errorfr::ShinyJsonCorrupt)?; // println!("{:?}",idsmap.get("airDamage")); - if let Some(debugconfig) = json_config.debug { - if debugconfig { - debug_mode = true - } - } - // create necessary variables let mut out = Vec::new(); let ver = TransformVersion::Version1; @@ -262,4 +261,32 @@ fn cook(args: Args, executable_path: &str, mut debug_mode: bool) -> Result<(), E Ok(()) } -fn pass() {} \ No newline at end of file +fn pass() {} + +fn load_jsonconfig(path: &String) -> Result { + Ok( + serde_json::from_reader(fs::File::open(path).map_err(|_| Errorfr::ItemJsonMissing)?) + .map_err(Errorfr::ItemJsonCorrupt)? + ) +} +fn load_idkeys(executable_path: &str) -> Result, Errorfr> { + Ok( + // id_keys.json + serde_json::from_reader( + fs::File::open(executable_path.to_owned() + "/id_keys.json") + .map_err(|_| Errorfr::IDMapJsonMissing)?, + ).map_err(|_| Errorfr::IDMapJsonCorrupt)?, + ) +} +fn load_shinystats(executable_path: &str) -> Result, Errorfr> { + Ok( + // shiny_stats.json + serde_json::from_reader( + fs::File::open(executable_path.to_owned() + "/shiny_stats.json") + .map_err(|_| Errorfr::ShinyJsonMissing)?, + ).map_err(|_| Errorfr::ShinyJsonCorrupt)? + ) +} + +fn somer() -> Option { Some(1) } +fn oker() -> Result { Ok(2) }