make perfect set name for now
This commit is contained in:
parent
76108fa49f
commit
24bab0fb18
6 changed files with 130 additions and 26 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -23,3 +23,4 @@ product/
|
|||
releases
|
||||
id_keys.json
|
||||
shiny_stats.json
|
||||
data
|
|
@ -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,
|
||||
|
|
50
src/gearjson.rs
Normal file
50
src/gearjson.rs
Normal file
|
@ -0,0 +1,50 @@
|
|||
use std::collections::HashMap;
|
||||
use serde::Deserialize;
|
||||
|
||||
// the struct for each item in Hashmap<String, GearJson> gear.json. its a big ass pain
|
||||
#[derive(Deserialize, PartialEq, Eq, Debug)]
|
||||
pub struct GearJsonItem {
|
||||
attackSpeed: Option<String>,
|
||||
averageDps: Option<i16>,
|
||||
base: HashMap<String, ItemId>,
|
||||
dropMeta: Option<dropMeta>,
|
||||
dropRestriction: Option<String>,
|
||||
icon: Icon,
|
||||
identifications: Option<HashMap<String, i16>>,
|
||||
identified: Option<bool>,
|
||||
internalName: String,
|
||||
lore: Option<String>,
|
||||
powderSlots: Option<u8>,
|
||||
rarity: String,
|
||||
restrictions: Option<String>,
|
||||
r#type: String,
|
||||
weaponType: Option<String>,
|
||||
armourMaterial: Option<String>,
|
||||
armourType: Option<String>
|
||||
}
|
||||
#[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
|
||||
}
|
|
@ -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<HashMap<String, u8>, 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<Vec<Shinystruct>, 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<HashMap<String, gearjson::GearJsonItem>, Errorfr> {
|
||||
// shiny_stats.json
|
||||
let a: Result<HashMap<String, gearjson::GearJsonItem>, 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<String> 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<u8>,
|
||||
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<u8>,
|
||||
}
|
||||
#[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<u8>,
|
||||
}
|
||||
|
||||
#[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
|
||||
}
|
||||
|
|
23
src/main.rs
23
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<String>,
|
||||
|
||||
/// 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<String>,
|
||||
|
||||
/// Function to generate perfect value items
|
||||
#[arg(long)]
|
||||
perfect: Option<String>
|
||||
}
|
||||
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;
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue