truly cool tree
This commit is contained in:
parent
862ee83356
commit
192765a3ec
4 changed files with 39 additions and 15 deletions
|
@ -31,10 +31,15 @@ pub enum Errorfr {
|
||||||
#[error("Error 2.5: 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.5: gear.json is missing. It's only required for the \"perfect mode\" item gen. \nYou should run \"--download Gear\" or \"--download All\".")]
|
||||||
GearJsonMissing,
|
GearJsonMissing,
|
||||||
|
|
||||||
/// shiny data json is corrupt
|
/// gear data json is corrupt
|
||||||
#[error("Error 2.6: gear.json is corrupt. It's only required for the \"perfect mode\" item gen. \nYou should run \"--download Gear\" or \"--download All\".\n{0:?}")]
|
#[error("Error 2.6: gear.json is corrupt. It's only required for the \"perfect mode\" item gen. \nYou should run \"--download Gear\" or \"--download All\".\n{0:?}")]
|
||||||
GearJsonCorrupt(serde_json5::Error),
|
GearJsonCorrupt(serde_json5::Error),
|
||||||
|
|
||||||
|
/// gear data json cache could not be created
|
||||||
|
#[error("Error 2.7: unable to create file gear_cache.json.")]
|
||||||
|
GearJsonCacheCreateFail,
|
||||||
|
|
||||||
|
|
||||||
/// could not download the file
|
/// could not download the file
|
||||||
#[error("Error 3.1: Download request failed. Check your network settings.")]
|
#[error("Error 3.1: Download request failed. Check your network settings.")]
|
||||||
JsonDlReqFail,
|
JsonDlReqFail,
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use serde::Deserialize;
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
// the struct for the stuff I need in in Hashmap<String, GearJson> gear.json. its a big ass pain
|
// the struct for the stuff I need in in Hashmap<String, GearJson> gear.json. its a big ass pain
|
||||||
#[derive(Deserialize, PartialEq, Eq, Debug)]
|
#[derive(Deserialize, Serialize, PartialEq, Eq, Debug)]
|
||||||
pub struct GearJsonItem {
|
pub struct GearJsonItem {
|
||||||
identifications: Option<
|
identifications: Option<
|
||||||
HashMap<
|
HashMap<
|
||||||
|
@ -10,15 +10,15 @@ pub struct GearJsonItem {
|
||||||
>
|
>
|
||||||
>
|
>
|
||||||
}
|
}
|
||||||
#[derive(Deserialize, PartialEq, Eq, Debug)]
|
#[derive(Deserialize, Serialize, PartialEq, Eq, Debug)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum GearJsonItemInner {
|
pub enum GearJsonItemInner {
|
||||||
r#Struct(GearJsonItemInnerStruct),
|
r#Struct(GearJsonItemInnerStruct),
|
||||||
r#Int(i32)
|
r#Int(i32)
|
||||||
}
|
}
|
||||||
#[derive(Deserialize, PartialEq, Eq, Debug)]
|
#[derive(Deserialize, Serialize, PartialEq, Eq, Debug)]
|
||||||
pub struct GearJsonItemInnerStruct {
|
pub struct GearJsonItemInnerStruct {
|
||||||
max: i16,
|
max: i32,
|
||||||
min: i16,
|
min: i32,
|
||||||
raw: i16
|
raw: i32
|
||||||
}
|
}
|
|
@ -4,7 +4,8 @@ use crate::gearjson;
|
||||||
use crate::jsonstruct::Shinystruct;
|
use crate::jsonstruct::Shinystruct;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
use std::{fs, io};
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
pub fn load_idkeys(executable_path: &str) -> Result<HashMap<String, u8>, Errorfr> {
|
pub fn load_idkeys(executable_path: &str) -> Result<HashMap<String, u8>, Errorfr> {
|
||||||
// id_keys.json
|
// id_keys.json
|
||||||
|
@ -20,14 +21,21 @@ pub fn load_shinystats(executable_path: &str) -> Result<Vec<Shinystruct>, Errorf
|
||||||
.map_err(|_| Errorfr::ShinyJsonMissing)?)
|
.map_err(|_| Errorfr::ShinyJsonMissing)?)
|
||||||
.map_err(|_| Errorfr::ShinyJsonCorrupt)
|
.map_err(|_| Errorfr::ShinyJsonCorrupt)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_gear(executable_path: &str) -> Result<HashMap<String, gearjson::GearJsonItem>, Errorfr> {
|
pub fn load_gear(executable_path: &str) -> Result<HashMap<String, gearjson::GearJsonItem>, Errorfr> {
|
||||||
// gear.json (ONLY FOR PERFECT ITEM FUNCTION GEN)
|
// gear.json (ONLY FOR DL gear.json)
|
||||||
serde_json5::from_reader(
|
serde_json5::from_reader(
|
||||||
&mut fs::File::open(executable_path.to_owned() + "/data/gear.json")
|
&mut fs::File::open(executable_path.to_owned() + "/data/gear.json")
|
||||||
.map_err(|_| Errorfr::GearJsonMissing)?)
|
.map_err(|_| Errorfr::GearJsonMissing)?)
|
||||||
.map_err(Errorfr::GearJsonCorrupt)
|
.map_err(Errorfr::GearJsonCorrupt)
|
||||||
}
|
}
|
||||||
|
pub fn load_gear_cache(executable_path: &str) -> Result<HashMap<String, gearjson::GearJsonItem>, Errorfr> {
|
||||||
|
// gear_cache.json (ONLY FOR PERFECT ITEM FUNCTION GEN)
|
||||||
|
serde_json5::from_reader(
|
||||||
|
&mut fs::File::open(executable_path.to_owned() + "/data/gear_cache.json")
|
||||||
|
.map_err(|_| Errorfr::GearJsonMissing)?)
|
||||||
|
.map_err(Errorfr::GearJsonCorrupt)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn dl_json_fr(dlvalue: &String, executable_path: &str) {
|
pub fn dl_json_fr(dlvalue: &String, executable_path: &str) {
|
||||||
let jsons = DownloadJsons::from(dlvalue.clone());
|
let jsons = DownloadJsons::from(dlvalue.clone());
|
||||||
if let Err(e) = fs::create_dir_all(format!("{}{}", executable_path, "/data/")) {
|
if let Err(e) = fs::create_dir_all(format!("{}{}", executable_path, "/data/")) {
|
||||||
|
@ -53,12 +61,23 @@ pub fn dl_json_fr(dlvalue: &String, executable_path: &str) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if jsons == DownloadJsons::All || jsons == DownloadJsons::Gear {
|
if jsons == DownloadJsons::All || jsons == DownloadJsons::Gear {
|
||||||
if let Err(e) = dl_json(
|
match dl_json(
|
||||||
"https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/gear.json".parse().unwrap(),
|
"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"),
|
||||||
) {
|
) {
|
||||||
|
Err(e) => {
|
||||||
// error handling below
|
// error handling below
|
||||||
println!("{} Filename: {}", e, dlvalue)
|
println!("{} Filename: {}", e, dlvalue);
|
||||||
|
},
|
||||||
|
Ok(t) => {
|
||||||
|
println!("Now generating gear_cache.json (otherwise, when running --perfect it will take ages each time!)");
|
||||||
|
let frfrnocap = serde_json::to_vec(
|
||||||
|
&load_gear(executable_path)
|
||||||
|
.unwrap()
|
||||||
|
).unwrap();
|
||||||
|
let mut outer = fs::File::create(format!("{}{}",executable_path, "/data/gear.json")).map_err(|_| Errorfr::GearJsonCacheCreateFail).unwrap();
|
||||||
|
outer.write_all(&frfrnocap).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,7 +156,7 @@ fn cook(out: &mut Vec<u8>, debug_mode: &bool, ver: EncodingVersion, json_config:
|
||||||
ItemTypeDeser::Gear | ItemTypeDeser::Tome | ItemTypeDeser::Charm => {
|
ItemTypeDeser::Gear | ItemTypeDeser::Tome | ItemTypeDeser::Charm => {
|
||||||
if namefr != *"" {
|
if namefr != *"" {
|
||||||
println!("cool tree");
|
println!("cool tree");
|
||||||
let fr_gear = load_gear(executable_path)?;
|
let fr_gear = load_gear_cache(executable_path)?;
|
||||||
}
|
}
|
||||||
else if let Some(real_ids) = &json_config.ids {
|
else if let Some(real_ids) = &json_config.ids {
|
||||||
fr_params.encode_iddata(real_ids, idsmap)?
|
fr_params.encode_iddata(real_ids, idsmap)?
|
||||||
|
|
Loading…
Add table
Reference in a new issue