test global vars (this is pain)
This commit is contained in:
parent
6efad16944
commit
73e0a94cc2
1 changed files with 22 additions and 17 deletions
39
src/main.rs
39
src/main.rs
|
@ -7,7 +7,7 @@ use idmangler_lib::{
|
||||||
StartData, TypeData,
|
StartData, TypeData,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::{collections::HashMap, env, fs, io, panic, path::PathBuf};
|
use std::{collections::HashMap, env, fs, io, panic, path::PathBuf, sync::{LazyLock, Mutex}};
|
||||||
|
|
||||||
mod structures;
|
mod structures;
|
||||||
use crate::structures::*;
|
use crate::structures::*;
|
||||||
|
@ -33,6 +33,10 @@ struct Args {
|
||||||
download: Option<String>,
|
download: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSONCONFIG: Mutex<Option<Jsonconfig>> = Mutex::new(None);
|
||||||
|
static IDSMAP: Mutex<Option<HashMap<String, u8>>> = Mutex::new(None);
|
||||||
|
static JSONSHINY: Mutex<Option<Vec<Shinystruct>>> = Mutex::new(None);
|
||||||
|
|
||||||
fn dl_json(
|
fn dl_json(
|
||||||
url: Url,
|
url: Url,
|
||||||
savename: String,
|
savename: String,
|
||||||
|
@ -84,28 +88,29 @@ fn main() {
|
||||||
println!("{}", e);
|
println!("{}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fn testfrfr() -> Result<(), Errorfr> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
fn cook(args: Args, executable_path: &str, mut debug_mode: bool) -> Result<(), Errorfr> {
|
fn cook(args: Args, executable_path: &str, mut debug_mode: bool) -> Result<(), Errorfr> {
|
||||||
let config = args.config;
|
let config = args.config;
|
||||||
|
|
||||||
|
|
||||||
// load configs
|
// load configs
|
||||||
let json_config: Jsonconfig =
|
*JSONCONFIG.lock().unwrap() =
|
||||||
serde_json::from_reader(fs::File::open(config).map_err(|_| Errorfr::ItemJsonMissing)?)
|
serde_json::from_reader(fs::File::open(config)
|
||||||
|
.map_err(|_| Errorfr::ItemJsonMissing)?)
|
||||||
.map_err(Errorfr::ItemJsonCorrupt)?;
|
.map_err(Errorfr::ItemJsonCorrupt)?;
|
||||||
let idsmap: HashMap<String, u8> = serde_json::from_reader(
|
*IDSMAP.lock().unwrap() = serde_json::from_reader(
|
||||||
fs::File::open(executable_path.to_owned() + "/id_keys.json")
|
fs::File::open(executable_path.to_owned() + "/id_keys.json")
|
||||||
.map_err(|_| Errorfr::IDMapJsonMissing)?,
|
.map_err(|_| Errorfr::IDMapJsonMissing)?)
|
||||||
)
|
|
||||||
.map_err(|_| Errorfr::IDMapJsonCorrupt)?;
|
.map_err(|_| Errorfr::IDMapJsonCorrupt)?;
|
||||||
let json_shiny: Vec<Shinystruct> = serde_json::from_reader(
|
let json_shiny: Vec<Shinystruct> = serde_json::from_reader(
|
||||||
fs::File::open(executable_path.to_owned() + "/ShinyStats.json")
|
fs::File::open(executable_path.to_owned() + "/ShinyStats.json")
|
||||||
.map_err(|_| Errorfr::ShinyJsonMissing)?,
|
.map_err(|_| Errorfr::ShinyJsonMissing)?,
|
||||||
)
|
)
|
||||||
.map_err(|_| Errorfr::ShinyJsonCorrupt)?;
|
.map_err(|_| Errorfr::ShinyJsonCorrupt)?;
|
||||||
// println!("{:?}",idsmap.get("airDamage"));
|
|
||||||
|
|
||||||
if let Some(debugconfig) = json_config.debug {
|
if let Some(debugconfig) = *&JSONCONFIG.lock().unwrap().as_ref().unwrap().debug {
|
||||||
if debugconfig {
|
if debugconfig {
|
||||||
debug_mode = true
|
debug_mode = true
|
||||||
}
|
}
|
||||||
|
@ -119,19 +124,19 @@ fn cook(args: Args, executable_path: &str, mut debug_mode: bool) -> Result<(), E
|
||||||
StartData(ver).encode(ver, &mut out).unwrap();
|
StartData(ver).encode(ver, &mut out).unwrap();
|
||||||
|
|
||||||
// ENCODE: TypeData
|
// ENCODE: TypeData
|
||||||
TypeData(ItemType::from(json_config.item_type))
|
TypeData(ItemType::from(*&JSONCONFIG.lock().unwrap().as_ref().unwrap().item_type))
|
||||||
.encode(ver, &mut out)
|
.encode(ver, &mut out)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// ENCODE: NameData
|
// ENCODE: NameData
|
||||||
NameData(json_config.name.trim().to_string())
|
NameData(JSONCONFIG.lock().unwrap().as_ref().unwrap().name.trim().to_string())
|
||||||
.encode(ver, &mut out)
|
.encode(ver, &mut out)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// json identification data handling
|
// json identification data handling
|
||||||
let mut idvec = Vec::new();
|
let mut idvec = Vec::new();
|
||||||
for eachid in json_config.ids {
|
for eachid in &JSONCONFIG.lock().unwrap().as_ref().unwrap().ids {
|
||||||
let id_id = idsmap.get(eachid.id.trim());
|
let id_id = *IDSMAP.lock().unwrap().as_ref().unwrap().get(eachid.id.trim());
|
||||||
let id_base = eachid.base;
|
let id_base = eachid.base;
|
||||||
let id_roll = eachid.roll;
|
let id_roll = eachid.roll;
|
||||||
|
|
||||||
|
@ -162,7 +167,7 @@ fn cook(args: Args, executable_path: &str, mut debug_mode: bool) -> Result<(), E
|
||||||
|
|
||||||
// json powder data handling
|
// json powder data handling
|
||||||
let mut powdervec = Vec::new();
|
let mut powdervec = Vec::new();
|
||||||
for eachpowder in json_config.powders {
|
for eachpowder in &JSONCONFIG.lock().unwrap().as_ref().unwrap().powders {
|
||||||
let powdertier = eachpowder.tier; // get the powder tier
|
let powdertier = eachpowder.tier; // get the powder tier
|
||||||
let powderamount: u8 = eachpowder.amount.unwrap_or(1);
|
let powderamount: u8 = eachpowder.amount.unwrap_or(1);
|
||||||
// match for the powder type
|
// match for the powder type
|
||||||
|
@ -188,13 +193,13 @@ fn cook(args: Args, executable_path: &str, mut debug_mode: bool) -> Result<(), E
|
||||||
|
|
||||||
// ENCODE: PowderData
|
// ENCODE: PowderData
|
||||||
PowderData {
|
PowderData {
|
||||||
powder_slots: json_config.powder_limit,
|
powder_slots: *&JSONCONFIG.lock().unwrap().as_ref().unwrap().powder_limit,
|
||||||
powders: powdervec,
|
powders: powdervec,
|
||||||
}
|
}
|
||||||
.encode(ver, &mut out)
|
.encode(ver, &mut out)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
match json_config.rerolls {
|
match *&JSONCONFIG.lock().unwrap().as_ref().unwrap().rerolls {
|
||||||
Some(rerollcount) => {
|
Some(rerollcount) => {
|
||||||
if rerollcount != 0 {
|
if rerollcount != 0 {
|
||||||
// ENCODE: RerollData if applicable
|
// ENCODE: RerollData if applicable
|
||||||
|
@ -208,7 +213,7 @@ fn cook(args: Args, executable_path: &str, mut debug_mode: bool) -> Result<(), E
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut realshinykey: u8;
|
let mut realshinykey: u8;
|
||||||
if let Some(shiny) = json_config.shiny {
|
if let Some(shiny) = &JSONCONFIG.lock().unwrap().as_ref().unwrap().shiny {
|
||||||
let _shinykey = &shiny.key;
|
let _shinykey = &shiny.key;
|
||||||
let shinyvalue = shiny.value;
|
let shinyvalue = shiny.value;
|
||||||
realshinykey = 1;
|
realshinykey = 1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue