perfect flag
This commit is contained in:
parent
8d2e685957
commit
afa7971f17
5 changed files with 58 additions and 14 deletions
|
@ -251,6 +251,6 @@ impl FuncParams<'_> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn encode_damagedata(&mut self) -> Result<(), Errorfr> {
|
pub fn encode_damagedata(&mut self) -> Result<(), Errorfr> {
|
||||||
todo!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,4 +95,8 @@ pub enum Errorfr {
|
||||||
/// Unrecognisable Powder element
|
/// Unrecognisable Powder element
|
||||||
#[error("Error 4.8: Unknown powder element")]
|
#[error("Error 4.8: Unknown powder element")]
|
||||||
JsonUnknownPowderElement,
|
JsonUnknownPowderElement,
|
||||||
|
|
||||||
|
/// Unrecognisable item for the Perfect gen function
|
||||||
|
#[error("Error 4.9: Unknown item for perfect gen...")]
|
||||||
|
PerfectItemNotFound,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use crate::errorfr::Errorfr;
|
||||||
|
use crate::jsonstruct::Identificationer;
|
||||||
|
|
||||||
// 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, Serialize, PartialEq, Eq, Debug)]
|
#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Clone)]
|
||||||
pub struct GearJsonItem {
|
pub struct GearJsonItem {
|
||||||
identifications: Option<
|
identifications: Option<
|
||||||
HashMap<
|
HashMap<
|
||||||
|
@ -10,15 +12,43 @@ pub struct GearJsonItem {
|
||||||
>
|
>
|
||||||
>
|
>
|
||||||
}
|
}
|
||||||
#[derive(Deserialize, Serialize, PartialEq, Eq, Debug)]
|
#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Clone)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum GearJsonItemInner {
|
pub enum GearJsonItemInner {
|
||||||
r#Struct(GearJsonItemInnerStruct),
|
r#Struct(GearJsonItemInnerStruct),
|
||||||
r#Int(i32)
|
r#Int(i32)
|
||||||
}
|
}
|
||||||
#[derive(Deserialize, Serialize, PartialEq, Eq, Debug)]
|
#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Clone)]
|
||||||
pub struct GearJsonItemInnerStruct {
|
pub struct GearJsonItemInnerStruct {
|
||||||
max: i32,
|
max: i32,
|
||||||
min: i32,
|
min: i32,
|
||||||
raw: i32
|
raw: i32
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn gen_perfect(name: &str, frjson: &HashMap<String, GearJsonItem>) -> Result<Vec<Identificationer>, Errorfr> {
|
||||||
|
let mut a: Vec<Identificationer> = Vec::new();
|
||||||
|
let name = name.to_lowercase();
|
||||||
|
match frjson.get(&name) {
|
||||||
|
Some(fr_idents) => {
|
||||||
|
if let Some(fr_identmap) = &fr_idents.identifications {
|
||||||
|
for i in fr_identmap {
|
||||||
|
if let &GearJsonItemInner::Struct(e) = &i.1 {
|
||||||
|
a.push(
|
||||||
|
Identificationer {
|
||||||
|
id: i.0.clone(),
|
||||||
|
base: e.clone().raw,
|
||||||
|
roll: Some(match &e.clone().raw {
|
||||||
|
fr if fr<&0 => 69,
|
||||||
|
fr if fr>&0 => 130,
|
||||||
|
_ => 0
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => return Err(Errorfr::PerfectItemNotFound)
|
||||||
|
}
|
||||||
|
Ok(a)
|
||||||
}
|
}
|
|
@ -25,11 +25,19 @@ pub fn load_shinystats(executable_path: &str) -> Result<Vec<Shinystruct>, Errorf
|
||||||
.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 DL gear.json)
|
// gear.json parse (ONLY FOR DL gear.json)
|
||||||
serde_json::from_reader(&mut BufReader::new(
|
let a: HashMap<String, gearjson::GearJsonItem> = serde_json::from_reader(&mut BufReader::new(
|
||||||
fs::File::open(executable_path.to_owned() + "/data/gear.json")
|
fs::File::open(executable_path.to_owned() + "/data/gear.json")
|
||||||
.map_err(|_| Errorfr::GearJsonMissing)?))
|
.map_err(|_| Errorfr::GearJsonMissing)?))
|
||||||
.map_err(Errorfr::GearJsonCacheCorrupt)
|
.map_err(Errorfr::GearJsonCacheCorrupt)?;
|
||||||
|
// parse the original, "a", into lowercase as "b"
|
||||||
|
let mut b: HashMap<String, gearjson::GearJsonItem> = HashMap::new();
|
||||||
|
for i in &a {
|
||||||
|
let frname = i.0.to_lowercase();
|
||||||
|
let frvalue = i.1.clone();
|
||||||
|
b.insert(frname, frvalue);
|
||||||
|
}
|
||||||
|
Ok(b)
|
||||||
}
|
}
|
||||||
pub fn load_gear_cache(executable_path: &str) -> Result<HashMap<String, gearjson::GearJsonItem>, Errorfr> {
|
pub fn load_gear_cache(executable_path: &str) -> Result<HashMap<String, gearjson::GearJsonItem>, Errorfr> {
|
||||||
// gear_cache.json (ONLY FOR PERFECT ITEM FUNCTION GEN)
|
// gear_cache.json (ONLY FOR PERFECT ITEM FUNCTION GEN)
|
||||||
|
@ -72,14 +80,14 @@ pub fn dl_json_fr(dlvalue: &String, executable_path: &str) {
|
||||||
// error handling below
|
// error handling below
|
||||||
println!("{} Filename: {}", e, dlvalue);
|
println!("{} Filename: {}", e, dlvalue);
|
||||||
},
|
},
|
||||||
Ok(t) => {
|
Ok(_) => {
|
||||||
println!("Now generating gear_cache.json (otherwise, when running --perfect it will take ages each time!)");
|
|
||||||
let frfrnocap = serde_json::to_vec(
|
let frfrnocap = serde_json::to_vec(
|
||||||
&load_gear(executable_path)
|
&load_gear(executable_path)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
).unwrap();
|
).unwrap();
|
||||||
let mut outer = fs::File::create(format!("{}{}",executable_path, "/data/gear_cache.json")).map_err(|_| Errorfr::GearJsonCacheCreateFail).unwrap();
|
let mut outer = fs::File::create(format!("{}{}",executable_path, "/data/gear_cache.json")).map_err(|_| Errorfr::GearJsonCacheCreateFail).unwrap();
|
||||||
outer.write_all(&frfrnocap).unwrap();
|
outer.write_all(&frfrnocap).unwrap();
|
||||||
|
println!("Making gearcache to {}/data/gear_cache.json", executable_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,7 +106,7 @@ impl From<String> for DownloadJsons {
|
||||||
fn from(value: String) -> Self {
|
fn from(value: String) -> Self {
|
||||||
match value.to_lowercase().as_str().trim() {
|
match value.to_lowercase().as_str().trim() {
|
||||||
"none" => {
|
"none" => {
|
||||||
println!("downloading NONE (Why?)");
|
println!("downloading NONE (Why? it's pointless...)");
|
||||||
DownloadJsons::None
|
DownloadJsons::None
|
||||||
}
|
}
|
||||||
"id_keys" | "idkeys" | "idkeys.json" | "id_keys.json" => {
|
"id_keys" | "idkeys" | "idkeys.json" | "id_keys.json" => {
|
||||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -12,8 +12,8 @@ use crate::jsonstruct::*;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use idmangler_lib::{encoding::string::encode_string, types::EncodingVersion};
|
use idmangler_lib::{encoding::string::encode_string, types::EncodingVersion};
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use std::{collections::HashMap, env, fs, io, path::PathBuf};
|
use std::{collections::HashMap, env, fs, io::Write, path::PathBuf};
|
||||||
use std::io::Write;
|
use crate::gearjson::gen_perfect;
|
||||||
|
|
||||||
#[derive(Parser, Debug, Clone)]
|
#[derive(Parser, Debug, Clone)]
|
||||||
#[command(version, about, long_about = None, arg_required_else_help(true))]
|
#[command(version, about, long_about = None, arg_required_else_help(true))]
|
||||||
|
@ -157,7 +157,9 @@ 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!("Overriding IDs with perfect ones!");
|
println!("Overriding IDs with perfect ones!");
|
||||||
let fr_gear = load_gear_cache(executable_path)?;
|
let fr_gear_cache = load_gear_cache(executable_path)?;
|
||||||
|
let resultantvec = gen_perfect(&namefr, &fr_gear_cache)?;
|
||||||
|
fr_params.encode_iddata(&resultantvec, idsmap)?
|
||||||
}
|
}
|
||||||
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)?
|
||||||
|
@ -239,4 +241,4 @@ fn cook(out: &mut Vec<u8>, debug_mode: &bool, ver: EncodingVersion, json_config:
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(final_string)
|
Ok(final_string)
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue