From 24bab0fb183d83c6ebc09fe4f597215addeacae3 Mon Sep 17 00:00:00 2001 From: endernon Date: Tue, 14 Jan 2025 18:09:49 +0000 Subject: [PATCH] make perfect set name for now --- .gitignore | 1 + src/errorfr.rs | 16 +++++++++++---- src/gearjson.rs | 50 +++++++++++++++++++++++++++++++++++++++++++++++ src/jsondl.rs | 48 ++++++++++++++++++++++++++++++++++++--------- src/jsonstruct.rs | 16 +++++++-------- src/main.rs | 25 +++++++++++++++++++----- 6 files changed, 130 insertions(+), 26 deletions(-) create mode 100644 src/gearjson.rs diff --git a/.gitignore b/.gitignore index 551c152..92f96c2 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ product/ releases id_keys.json shiny_stats.json +data \ No newline at end of file diff --git a/src/errorfr.rs b/src/errorfr.rs index 27c5861..4871cfd 100644 --- a/src/errorfr.rs +++ b/src/errorfr.rs @@ -12,21 +12,29 @@ pub enum Errorfr { ItemJsonCorrupt(serde_json5::Error), /// idmap is missing - #[error("Error 1.3: id_keys.json is missing. \nYou should run \"--download id_keys\" or \"--download All\".")] + #[error("Error 2.1: id_keys.json is missing. \nYou should run \"--download id_keys\" or \"--download All\".")] IDMapJsonMissing, /// idmap is corrupt - #[error("Error 2.1: id_keys.json is corrupt. \nYou should run \"--download id_keys\" or \"--download All\".")] + #[error("Error 2.2: id_keys.json is corrupt. \nYou should run \"--download id_keys\" or \"--download All\".")] IDMapJsonCorrupt, /// shiny data json is missing - #[error("Error 2.2: shiny_stats.json is missing. \nYou should run \"--download ShinyStats\" or \"--download All\".")] + #[error("Error 2.3: shiny_stats.json is missing. \nYou should run \"--download ShinyStats\" or \"--download All\".")] ShinyJsonMissing, /// shiny data json is corrupt - #[error("Error 2.3: shiny_stats.json is corrupt. \nYou should run \"--download ShinyStats\" or \"--download All\".")] + #[error("Error 2.4: shiny_stats.json is corrupt. \nYou should run \"--download ShinyStats\" or \"--download All\".")] 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\".")] + 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\".")] + GearJsonCorrupt, + /// could not download the file #[error("Error 3.1: Download request failed. Check your network settings.")] JsonDlReqFail, diff --git a/src/gearjson.rs b/src/gearjson.rs new file mode 100644 index 0000000..1fb2c80 --- /dev/null +++ b/src/gearjson.rs @@ -0,0 +1,50 @@ +use std::collections::HashMap; +use serde::Deserialize; + +// the struct for each item in Hashmap gear.json. its a big ass pain +#[derive(Deserialize, PartialEq, Eq, Debug)] +pub struct GearJsonItem { + attackSpeed: Option, + averageDps: Option, + base: HashMap, + dropMeta: Option, + dropRestriction: Option, + icon: Icon, + identifications: Option>, + identified: Option, + internalName: String, + lore: Option, + powderSlots: Option, + rarity: String, + restrictions: Option, + r#type: String, + weaponType: Option, + armourMaterial: Option, + armourType: Option +} +#[derive(Deserialize, PartialEq, Eq, Debug)] +pub struct ItemId { + max: i8, + min: i8, + raw: i8 +} + +#[derive(Deserialize, PartialEq, Eq, Debug)] +pub struct dropMeta { + coordinates: [i64; 3], + name: String, + r#type: String +} + +#[derive(Deserialize, PartialEq, Eq, Debug)] +pub struct Icon { + format: String, + value: IconValue +} + +#[derive(Deserialize, PartialEq, Eq, Debug)] +pub struct IconValue { + customModelData: i16, + id: String, + name: String +} \ No newline at end of file diff --git a/src/jsondl.rs b/src/jsondl.rs index b7decda..28e74a3 100644 --- a/src/jsondl.rs +++ b/src/jsondl.rs @@ -1,4 +1,5 @@ use crate::dl_json; +use crate::gearjson; use crate::errorfr::Errorfr; use crate::jsonstruct::Shinystruct; use serde::Deserialize; @@ -7,22 +8,34 @@ use std::fs; pub fn load_idkeys(executable_path: &str) -> Result, Errorfr> { // id_keys.json - serde_json5::from_reader(&mut fs::File::open(executable_path.to_owned() + "/id_keys.json").map_err(|_| Errorfr::IDMapJsonMissing)?) + serde_json5::from_reader(&mut fs::File::open(executable_path.to_owned() + "/data/id_keys.json").map_err(|_| Errorfr::IDMapJsonMissing)?) .map_err(|_| Errorfr::IDMapJsonCorrupt) } pub fn load_shinystats(executable_path: &str) -> Result, Errorfr> { // shiny_stats.json - serde_json5::from_reader(&mut fs::File::open(executable_path.to_owned() + "/shiny_stats.json").map_err(|_| Errorfr::ShinyJsonMissing)?) + serde_json5::from_reader(&mut fs::File::open(executable_path.to_owned() + "/data/shiny_stats.json").map_err(|_| Errorfr::ShinyJsonMissing)?) .map_err(|_| Errorfr::ShinyJsonCorrupt) } + +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); + + a +} pub fn dl_json_fr(dlvalue: &String, executable_path: &str) { let jsons = DownloadJsons::from(dlvalue.clone()); + 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, "/shiny_stats.json"), + format!("{}{}", executable_path, "/data/shiny_stats.json") ) { // error handling below println!("{} Filename: {}", e, dlvalue) @@ -33,7 +46,18 @@ 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, "/id_keys.json"), + format!("{}{}", executable_path, "/data/id_keys.json") + ) { + // error handling below + println!("{} Filename: {}", e, dlvalue) + } + } + if jsons == DownloadJsons::All || jsons == DownloadJsons::Gear { + if let Err(e) = dl_json( + "https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/gear.json" + .parse() + .unwrap(), + format!("{}{}", executable_path, "/data/gear.json") ) { // error handling below println!("{} Filename: {}", e, dlvalue) @@ -47,31 +71,37 @@ pub enum DownloadJsons { None, IdKeys, ShinyStats, + Gear, All, } impl From for DownloadJsons { fn from(value: String) -> Self { match value.to_lowercase().as_str().trim() { "none" => { - println!("download NONE"); + println!("downloading NONE (Why?)"); DownloadJsons::None } "id_keys" | "idkeys" | "idkeys.json" | "id_keys.json" => { - println!("download ID_KEYS"); + println!("downloading ID_KEYS"); DownloadJsons::IdKeys } "shiny_stats" | "shinystats" | "shiny_stats.json" | "shinystats.json" => { - println!("download SHINY_STATS"); + println!("downloading SHINY_STATS"); DownloadJsons::ShinyStats } + "gear" | "gear.json" => { + println!("downloading GEAR"); + DownloadJsons::Gear + } "all" | "everything" | "both" => { - println!("download BOTH"); + println!("downloading ALL jsons"); DownloadJsons::All } _ => { - println!("Could not understand what Jsons to download, sorry."); + println!("downloading NONE (unable to understand prompt)"); DownloadJsons::None } } } } + diff --git a/src/jsonstruct.rs b/src/jsonstruct.rs index 3d80f6e..934b4de 100644 --- a/src/jsonstruct.rs +++ b/src/jsonstruct.rs @@ -7,7 +7,7 @@ use serde::Deserialize; use std::fs; // structs for the json parsing -#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone)] pub struct Jsonconfig { // not a thing to be encoded, this just toggles debug prints. Also settable using --debug #[serde(alias = "Debug", alias = "DEBUG")] @@ -187,7 +187,7 @@ impl TryFrom<&str> for CraftedTypesFr { } } } -#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone)] pub struct Durability { pub effect_strength: Option, pub dura_cur: i32, @@ -198,24 +198,24 @@ pub struct Shinystruct { pub id: u8, pub key: String, } -#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone)] pub struct Identificationer { pub id: String, pub base: i32, pub roll: Option, } -#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone)] pub struct IdentificationerCrafted { pub name: String, pub max_roll: i32, } -#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone)] pub struct PowderFr { pub r#type: char, pub amount: Option, } -#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone)] pub struct Shinyjson { pub key: String, pub value: i64, @@ -229,7 +229,7 @@ pub struct FuncParams<'a> { pub fr_ver: EncodingVersion, } -#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone)] pub struct DamageDeser { pub attack_speed: AttackSpeed } @@ -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 28cc830..7d81223 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ #![allow(clippy::single_match)] +#![allow(non_camel_case_types, non_snake_case)] use idmangler_lib::{encoding::string::encode_string, types::EncodingVersion}; @@ -8,6 +9,8 @@ mod encode; mod errorfr; mod jsondl; mod jsonstruct; +mod gearjson; + use crate::errorfr::Errorfr; use crate::jsondl::*; use crate::jsonstruct::*; @@ -21,13 +24,21 @@ struct Args { #[arg(short, long)] config: Option, - /// Enable debug mode + /// Enable debug mode (for now this just prints debug info) #[arg(long, default_value_t = false)] debug: bool, /// Download jsons (for ease of use) #[arg(short, long)] download: Option, + + /// Function to generate perfect value items + #[arg(long)] + perfect: Option +} +pub enum PerfectStatus { + None, + Some(String) } fn dl_json(url: Url, savename: String) -> Result<(), Errorfr> { @@ -77,15 +88,19 @@ fn main() { // create necessary variables let ver = EncodingVersion::Version1; - let loaded_config_borrow = &loaded_config; - // ENCODE: ALotOfStuff + let mut loaded_config_borrow = loaded_config.clone(); + // check if perfect status + 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, loaded_config_borrow, loaded_idkeys, loaded_shinystats); + let cooking = cook(&mut out, &debug_mode, ver, &loaded_config_borrow, loaded_idkeys, loaded_shinystats); if let Err(e) = cooking { println!("{}", e); // print error if there is an error } else { // final string print if there is no error - println!("{}", cooking.unwrap()) } }