let me cook

This commit is contained in:
endernon 2025-01-14 18:19:16 +00:00
parent fe7ec985f2
commit 7d4dcfa2b9
5 changed files with 18 additions and 56 deletions

View file

@ -2,10 +2,7 @@ use crate::errorfr::Errorfr;
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,
},
block::{CraftedConsumableTypeData, CraftedGearTypeData, DurabilityData, EndData, IdentificationData, NameData, PowderData, RequirementsData, RerollData, ShinyData, StartData, TypeData},
types::{ClassType, Element, ItemType, Powder, RollType, SkillType, Stat},
};
use std::collections::HashMap;
@ -242,12 +239,7 @@ impl FuncParams<'_> {
dbg!(&shinyvalue);
}
// ENCODE: ShinyData (if applicable)
ShinyData {
id: realshinykey,
val: shinyvalue,
}
.encode(self.fr_ver, self.fr_out)
.unwrap();
ShinyData { id: realshinykey, val: shinyvalue }.encode(self.fr_ver, self.fr_out).unwrap();
Ok(())
}
pub fn encode_enddata(&mut self) -> Result<(), Errorfr> {

View file

@ -28,15 +28,11 @@ 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

View file

@ -8,20 +8,17 @@ 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> {
// 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);
serde_json5::from_reader(&mut fs::File::open(executable_path.to_owned() + "/data/gear.json").map_err(|_| Errorfr::GearJsonMissing)?).map_err(|_| Errorfr::GearJsonCorrupt);
a
}
@ -33,9 +30,7 @@ pub fn dl_json_fr(dlvalue: &String, executable_path: &str) {
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(),
"https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Data-Storage/shiny_stats.json".parse().unwrap(),
format!("{}{}", executable_path, "/data/shiny_stats.json"),
) {
// error handling below
@ -44,9 +39,7 @@ pub fn dl_json_fr(dlvalue: &String, executable_path: &str) {
}
if jsons == DownloadJsons::All || jsons == DownloadJsons::IdKeys {
if let Err(e) = dl_json(
"https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/id_keys.json"
.parse()
.unwrap(),
"https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/id_keys.json".parse().unwrap(),
format!("{}{}", executable_path, "/data/id_keys.json"),
) {
// error handling below
@ -55,9 +48,7 @@ pub fn dl_json_fr(dlvalue: &String, executable_path: &str) {
}
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(),
"https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/gear.json".parse().unwrap(),
format!("{}{}", executable_path, "/data/gear.json"),
) {
// error handling below

View file

@ -1,8 +1,6 @@
use crate::errorfr::Errorfr;
use crate::jsonstruct::CraftedTypesFr::{Consu, Gear};
use idmangler_lib::types::{
AttackSpeed, ClassType, ConsumableType, ConsumableType::*, CraftedGearType, CraftedGearType::*, EncodingVersion, ItemType, SkillType,
};
use idmangler_lib::types::{AttackSpeed, ClassType, ConsumableType, ConsumableType::*, CraftedGearType, CraftedGearType::*, EncodingVersion, ItemType, SkillType};
use serde::Deserialize;
use std::fs;
@ -14,15 +12,7 @@ pub struct Jsonconfig {
pub debug: Option<bool>,
// Item Types (Gear, Tome, Charm, Crafted Gear, Crafted Consum)
#[serde(
alias = "itemtype",
alias = "ITEM_TYPE",
alias = "ITEMTYPE",
alias = "Item_Type",
alias = "Item_type",
alias = "ItemType",
alias = "Itemtype"
)]
#[serde(alias = "itemtype", alias = "ITEM_TYPE", alias = "ITEMTYPE", alias = "Item_Type", alias = "Item_type", alias = "ItemType", alias = "Itemtype")]
pub item_type: ItemTypeDeser,
// Crafted type for Crafted item types

View file

@ -85,15 +85,16 @@ fn main() {
// create necessary variables
let ver = EncodingVersion::Version1;
let mut loaded_config_borrow = loaded_config.clone();
// check if perfect status
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 {
loaded_config_borrow.name = Some(t1)
namefr = 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);
let cooking = cook(&mut out, &debug_mode, ver, &mut loaded_config_clone, loaded_idkeys, loaded_shinystats, namefr);
if let Err(e) = cooking {
println!("{}", e); // print error if there is an error
} else {
@ -112,9 +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>,
) -> 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) -> Result<String, Errorfr> {
let mut fr_params = FuncParams {
fr_out: out,
fr_debug_mode: debug_mode,
@ -233,9 +232,3 @@ fn cook(
Ok(final_string)
}
fn cook_perfect(
out: &mut Vec<u8>, debug_mode: &bool, ver: EncodingVersion, json_config: &Jsonconfig, idsmap: HashMap<String, u8>, json_shiny: Vec<Shinystruct>,
) -> Result<String, Errorfr> {
Ok("fr".parse().unwrap())
}