cool tree

This commit is contained in:
endernon 2025-01-14 20:08:26 +00:00
parent 116fd90232
commit 862ee83356
8 changed files with 56 additions and 62 deletions

1
Cargo.lock generated
View file

@ -650,6 +650,7 @@ dependencies = [
"idmangler-lib",
"reqwest",
"serde",
"serde_json",
"serde_json5",
"thiserror",
]

View file

@ -12,5 +12,6 @@ clap = { version = "4.5.20", features = ["derive"] }
idmangler-lib = { version = "0.5.0", features = ["serde"] }
reqwest = { version = "0.12.9", features = ["blocking", "json"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.135"
serde_json5 = "0.1.0"
thiserror = "2.0.9"

View file

@ -251,6 +251,6 @@ impl FuncParams<'_> {
Ok(())
}
pub fn encode_damagedata(&mut self) -> Result<(), Errorfr> {
Ok(())
todo!();
}
}

View file

@ -28,12 +28,12 @@ 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.5: 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,
#[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),
/// could not download the file
#[error("Error 3.1: Download request failed. Check your network settings.")]

View file

@ -1,50 +1,24 @@
use serde::Deserialize;
use std::collections::HashMap;
// the struct for each item 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)]
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>,
identifications: Option<
HashMap<
String, GearJsonItemInner
>
>
}
#[derive(Deserialize, PartialEq, Eq, Debug)]
pub struct ItemId {
max: i8,
min: i8,
raw: i8,
#[serde(untagged)]
pub enum GearJsonItemInner {
r#Struct(GearJsonItemInnerStruct),
r#Int(i32)
}
#[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,
pub struct GearJsonItemInnerStruct {
max: i16,
min: i16,
raw: i16
}

View file

@ -8,16 +8,25 @@ 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() + "/data/id_keys.json").map_err(|_| Errorfr::IDMapJsonMissing)?).map_err(|_| Errorfr::IDMapJsonCorrupt)
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() + "/data/shiny_stats.json").map_err(|_| Errorfr::ShinyJsonMissing)?).map_err(|_| Errorfr::ShinyJsonCorrupt)
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> {
// gear.json (ONLY FOR PERFECT ITEM FUNCTION GEN)
serde_json5::from_reader(&mut fs::File::open(executable_path.to_owned() + "/data/gear.json").map_err(|_| Errorfr::GearJsonMissing)?).map_err(|_| Errorfr::GearJsonCorrupt)
serde_json5::from_reader(
&mut fs::File::open(executable_path.to_owned() + "/data/gear.json")
.map_err(|_| Errorfr::GearJsonMissing)?)
.map_err(Errorfr::GearJsonCorrupt)
}
pub fn dl_json_fr(dlvalue: &String, executable_path: &str) {
let jsons = DownloadJsons::from(dlvalue.clone());

View file

@ -243,5 +243,7 @@ impl From<ItemTypeDeser> for ItemType {
}
pub fn load_jsonconfig(path: &String) -> Result<Jsonconfig, Errorfr> {
serde_json5::from_reader(&mut fs::File::open(path).map_err(|_| Errorfr::ItemJsonMissing)?).map_err(Errorfr::ItemJsonCorrupt)
serde_json5::from_reader(&mut fs::File::open(path)
.map_err(|_| Errorfr::ItemJsonMissing)?)
.map_err(Errorfr::ItemJsonCorrupt)
}

View file

@ -33,10 +33,7 @@ struct Args {
#[arg(long)]
perfect: Option<String>,
}
pub enum PerfectStatus {
None,
Some(String),
}
fn dl_json(url: Url, savename: String) -> Result<(), Errorfr> {
let resp = reqwest::blocking::get(url).map_err(|_| Errorfr::JsonDlReqFail)?;
@ -71,6 +68,13 @@ fn main() {
Ok(loaded_idkeys) => {
match load_shinystats(executable_path) {
Ok(loaded_shinystats) => {
// check if perfect status and change name if so. otherwise blank yep
let mut namefr: String = "".to_string();
if let Some(t1) = args.perfect {
namefr = t1
}
match load_jsonconfig(t) {
Ok(loaded_config) => {
// debug mode on if in the loaded config
@ -86,15 +90,11 @@ fn main() {
let ver = EncodingVersion::Version1;
let mut loaded_config_clone = loaded_config.clone();
// check if perfect status and change name if so. otherwise blank yep
let mut namefr: String = "".to_string();
if let Some(t1) = args.perfect {
namefr = t1
}
// ENCODE: A Lot Of Stuff
// Also print any mapped errors
let cooking = cook(&mut out, &debug_mode, ver, &mut loaded_config_clone, loaded_idkeys, loaded_shinystats, namefr);
let cooking = cook(&mut out, &debug_mode, ver, &mut loaded_config_clone, loaded_idkeys, loaded_shinystats, namefr, executable_path);
if let Err(e) = cooking {
println!("{}", e); // print error if there is an error
} else {
@ -113,7 +113,7 @@ fn main() {
}
}
fn cook(out: &mut Vec<u8>, debug_mode: &bool, ver: EncodingVersion, json_config: &mut Jsonconfig, idsmap: HashMap<String, u8>, json_shiny: Vec<Shinystruct>, namefr: String) -> Result<String, Errorfr> {
fn cook(out: &mut Vec<u8>, debug_mode: &bool, ver: EncodingVersion, json_config: &mut Jsonconfig, idsmap: HashMap<String, u8>, json_shiny: Vec<Shinystruct>, namefr: String, executable_path: &str) -> Result<String, Errorfr> {
let mut fr_params = FuncParams {
fr_out: out,
fr_debug_mode: debug_mode,
@ -139,7 +139,10 @@ fn cook(out: &mut Vec<u8>, debug_mode: &bool, ver: EncodingVersion, json_config:
// ENCODE: NameData, if ItemType is Gear, Tome, Charm
match json_config.item_type {
ItemTypeDeser::Gear | ItemTypeDeser::Tome | ItemTypeDeser::Charm => {
if let Some(real_name) = &json_config.name {
if namefr != *"" {
fr_params.encode_namedata(&namefr)?
}
else if let Some(real_name) = &json_config.name {
fr_params.encode_namedata(real_name)?
} else {
return Err(Errorfr::JsonNotFoundName);
@ -151,7 +154,11 @@ fn cook(out: &mut Vec<u8>, debug_mode: &bool, ver: EncodingVersion, json_config:
// ENCODE: IdentificationData
match json_config.item_type {
ItemTypeDeser::Gear | ItemTypeDeser::Tome | ItemTypeDeser::Charm => {
if let Some(real_ids) = &json_config.ids {
if namefr != *"" {
println!("cool tree");
let fr_gear = load_gear(executable_path)?;
}
else if let Some(real_ids) = &json_config.ids {
fr_params.encode_iddata(real_ids, idsmap)?
}
}