From fe7ec985f29f5bf53d76ff103192642c8142228d Mon Sep 17 00:00:00 2001 From: endernon Date: Tue, 14 Jan 2025 18:14:35 +0000 Subject: [PATCH] frfr --- rustfmt.toml | 4 ++-- src/encode.rs | 8 +++----- src/errorfr.rs | 8 ++++++-- src/gearjson.rs | 14 +++++++------- src/jsondl.rs | 18 +++++++++--------- src/jsonstruct.rs | 14 +++++++------- src/main.rs | 28 ++++++++++++---------------- 7 files changed, 46 insertions(+), 48 deletions(-) diff --git a/rustfmt.toml b/rustfmt.toml index 63788ab..a07bb31 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,3 +1,3 @@ fn_params_layout = "Compressed" -attr_fn_like_width = 140 -max_width = 160 \ No newline at end of file +attr_fn_like_width = 160 +max_width = 200 \ No newline at end of file diff --git a/src/encode.rs b/src/encode.rs index feac56a..baf1563 100644 --- a/src/encode.rs +++ b/src/encode.rs @@ -1,12 +1,10 @@ use crate::errorfr::Errorfr; -use crate::jsonstruct::{ - CraftedTypesFr, Durability, FuncParams, Identificationer, ItemTypeDeser, PowderFr, RequirementsDeser, Shinyjson, Shinystruct, -}; +use crate::jsonstruct::{CraftedTypesFr, Durability, FuncParams, Identificationer, ItemTypeDeser, PowderFr, RequirementsDeser, Shinyjson, Shinystruct}; use idmangler_lib::encoding::DataEncoder; use idmangler_lib::{ block::{ - CraftedConsumableTypeData, CraftedGearTypeData, DurabilityData, EndData, IdentificationData, NameData, PowderData, - RequirementsData, RerollData, ShinyData, StartData, TypeData, + CraftedConsumableTypeData, CraftedGearTypeData, DurabilityData, EndData, IdentificationData, NameData, PowderData, RequirementsData, RerollData, + ShinyData, StartData, TypeData, }, types::{ClassType, Element, ItemType, Powder, RollType, SkillType, Stat}, }; diff --git a/src/errorfr.rs b/src/errorfr.rs index 4871cfd..15a3a4a 100644 --- a/src/errorfr.rs +++ b/src/errorfr.rs @@ -28,11 +28,15 @@ pub enum Errorfr { ShinyJsonCorrupt, /// gear json is missing - #[error("Error 2.3: gear.json is missing. It's only required for the \"perfect mode\" item gen. \nYou should run \"--download Gear\" or \"--download All\".")] + #[error( + "Error 2.3: gear.json is missing. It's only required for the \"perfect mode\" item gen. \nYou should run \"--download Gear\" or \"--download All\"." + )] GearJsonMissing, /// shiny data json is corrupt - #[error("Error 2.4: gear.json is corrupt. It's only required for the \"perfect mode\" item gen. \nYou should run \"--download Gear\" or \"--download All\".")] + #[error( + "Error 2.4: gear.json is corrupt. It's only required for the \"perfect mode\" item gen. \nYou should run \"--download Gear\" or \"--download All\"." + )] GearJsonCorrupt, /// could not download the file diff --git a/src/gearjson.rs b/src/gearjson.rs index 1fb2c80..d1e569b 100644 --- a/src/gearjson.rs +++ b/src/gearjson.rs @@ -1,5 +1,5 @@ -use std::collections::HashMap; use serde::Deserialize; +use std::collections::HashMap; // the struct for each item in Hashmap gear.json. its a big ass pain #[derive(Deserialize, PartialEq, Eq, Debug)] @@ -20,31 +20,31 @@ pub struct GearJsonItem { r#type: String, weaponType: Option, armourMaterial: Option, - armourType: Option + armourType: Option, } #[derive(Deserialize, PartialEq, Eq, Debug)] pub struct ItemId { max: i8, min: i8, - raw: i8 + raw: i8, } #[derive(Deserialize, PartialEq, Eq, Debug)] pub struct dropMeta { coordinates: [i64; 3], name: String, - r#type: String + r#type: String, } #[derive(Deserialize, PartialEq, Eq, Debug)] pub struct Icon { format: String, - value: IconValue + value: IconValue, } #[derive(Deserialize, PartialEq, Eq, Debug)] pub struct IconValue { customModelData: i16, id: String, - name: String -} \ No newline at end of file + name: String, +} diff --git a/src/jsondl.rs b/src/jsondl.rs index 28e74a3..4f06d24 100644 --- a/src/jsondl.rs +++ b/src/jsondl.rs @@ -1,6 +1,6 @@ use crate::dl_json; -use crate::gearjson; use crate::errorfr::Errorfr; +use crate::gearjson; use crate::jsonstruct::Shinystruct; use serde::Deserialize; use std::collections::HashMap; @@ -19,9 +19,10 @@ pub fn load_shinystats(executable_path: &str) -> Result, Errorf pub fn load_gear(executable_path: &str) -> Result, Errorfr> { // shiny_stats.json - let a: Result, Errorfr> = serde_json5::from_reader(&mut fs::File::open(executable_path.to_owned() + "/data/gear.json").map_err(|_| Errorfr::GearJsonMissing)?) - .map_err(|_| Errorfr::GearJsonCorrupt); - + let a: Result, Errorfr> = + serde_json5::from_reader(&mut fs::File::open(executable_path.to_owned() + "/data/gear.json").map_err(|_| Errorfr::GearJsonMissing)?) + .map_err(|_| Errorfr::GearJsonCorrupt); + a } pub fn dl_json_fr(dlvalue: &String, executable_path: &str) { @@ -29,13 +30,13 @@ pub fn dl_json_fr(dlvalue: &String, executable_path: &str) { if let Err(e) = fs::create_dir_all(format!("{}{}", executable_path, "/data/")) { println!("Unable to create path. Path: {} ", e) } - + if jsons == DownloadJsons::All || jsons == DownloadJsons::ShinyStats { if let Err(e) = dl_json( "https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Data-Storage/shiny_stats.json" .parse() .unwrap(), - format!("{}{}", executable_path, "/data/shiny_stats.json") + format!("{}{}", executable_path, "/data/shiny_stats.json"), ) { // error handling below println!("{} Filename: {}", e, dlvalue) @@ -46,7 +47,7 @@ pub fn dl_json_fr(dlvalue: &String, executable_path: &str) { "https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/id_keys.json" .parse() .unwrap(), - format!("{}{}", executable_path, "/data/id_keys.json") + format!("{}{}", executable_path, "/data/id_keys.json"), ) { // error handling below println!("{} Filename: {}", e, dlvalue) @@ -57,7 +58,7 @@ pub fn dl_json_fr(dlvalue: &String, executable_path: &str) { "https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/gear.json" .parse() .unwrap(), - format!("{}{}", executable_path, "/data/gear.json") + format!("{}{}", executable_path, "/data/gear.json"), ) { // error handling below println!("{} Filename: {}", e, dlvalue) @@ -104,4 +105,3 @@ impl From for DownloadJsons { } } } - diff --git a/src/jsonstruct.rs b/src/jsonstruct.rs index 934b4de..3c55650 100644 --- a/src/jsonstruct.rs +++ b/src/jsonstruct.rs @@ -1,7 +1,7 @@ use crate::errorfr::Errorfr; use crate::jsonstruct::CraftedTypesFr::{Consu, Gear}; -use idmangler_lib::{ - types::{ClassType, ConsumableType, ConsumableType::*, CraftedGearType, CraftedGearType::*, EncodingVersion, ItemType, SkillType, AttackSpeed}, +use idmangler_lib::types::{ + AttackSpeed, ClassType, ConsumableType, ConsumableType::*, CraftedGearType, CraftedGearType::*, EncodingVersion, ItemType, SkillType, }; use serde::Deserialize; use std::fs; @@ -64,7 +64,7 @@ pub struct Jsonconfig { // requirements data (Crafted) #[serde(alias = "requirement", alias = "Requirement", alias = "REQUIREMENT", alias = "requirements", alias = "Requirements", alias = "REQUIREMENTS")] pub crafted_requirements: Option, - + // identifications (Crafted) // to be honest i wish there was a better way instead of too many aliases #[serde( @@ -84,8 +84,8 @@ pub struct Jsonconfig { alias = "Craftedidentifications" )] pub crafted_ids: Option>, - - pub crafted_damage: Option + + pub crafted_damage: Option, } // reimplementing this because it doesnt have Deserialize. // Also, changing the SkillPoint stuff into NOT a vec. @@ -231,7 +231,7 @@ pub struct FuncParams<'a> { #[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone)] pub struct DamageDeser { - pub attack_speed: AttackSpeed + pub attack_speed: AttackSpeed, } // I had to clone this and add Deserialize because the original idmangler_lib::types::ItemType does not #[repr(u8)] @@ -262,4 +262,4 @@ impl From for ItemType { pub fn load_jsonconfig(path: &String) -> Result { serde_json5::from_reader(&mut fs::File::open(path).map_err(|_| Errorfr::ItemJsonMissing)?).map_err(Errorfr::ItemJsonCorrupt) -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index 1b7c13c..d4a5cf0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,20 +1,18 @@ #![allow(clippy::single_match)] #![allow(non_camel_case_types, non_snake_case)] - mod encode; mod errorfr; +mod gearjson; mod jsondl; mod jsonstruct; -mod gearjson; -use idmangler_lib::{encoding::string::encode_string, types::EncodingVersion}; -use std::{collections::HashMap, env, fs, io, path::PathBuf}; -use clap::Parser; -use reqwest::Url; use crate::errorfr::Errorfr; use crate::jsondl::*; use crate::jsonstruct::*; - +use clap::Parser; +use idmangler_lib::{encoding::string::encode_string, types::EncodingVersion}; +use reqwest::Url; +use std::{collections::HashMap, env, fs, io, path::PathBuf}; #[derive(Parser, Debug, Clone)] #[command(version, about, long_about = None, arg_required_else_help(true))] @@ -30,14 +28,14 @@ struct Args { /// Download jsons (for ease of use) #[arg(short, long)] download: Option, - + /// Function to generate perfect value items #[arg(long)] - perfect: Option + perfect: Option, } pub enum PerfectStatus { None, - Some(String) + Some(String), } fn dl_json(url: Url, savename: String) -> Result<(), Errorfr> { @@ -92,7 +90,7 @@ fn main() { if let Some(t1) = args.perfect { loaded_config_borrow.name = Some(t1) } - + // ENCODE: A Lot Of Stuff // Also print any mapped errors let cooking = cook(&mut out, &debug_mode, ver, &mut loaded_config_borrow, loaded_idkeys, loaded_shinystats); @@ -115,8 +113,7 @@ fn main() { } fn cook( - out: &mut Vec, debug_mode: &bool, ver: EncodingVersion, json_config: &mut Jsonconfig, idsmap: HashMap, - json_shiny: Vec, + out: &mut Vec, debug_mode: &bool, ver: EncodingVersion, json_config: &mut Jsonconfig, idsmap: HashMap, json_shiny: Vec, ) -> Result { let mut fr_params = FuncParams { fr_out: out, @@ -238,8 +235,7 @@ fn cook( } fn cook_perfect( - out: &mut Vec, debug_mode: &bool, ver: EncodingVersion, json_config: &Jsonconfig, idsmap: HashMap, - json_shiny: Vec, + out: &mut Vec, debug_mode: &bool, ver: EncodingVersion, json_config: &Jsonconfig, idsmap: HashMap, json_shiny: Vec, ) -> Result { Ok("fr".parse().unwrap()) -} \ No newline at end of file +}