download jsons function for ease of use
This commit is contained in:
parent
5cdfcfeca2
commit
142c548057
5 changed files with 196 additions and 88 deletions
59
Cargo.lock
generated
59
Cargo.lock
generated
|
@ -163,7 +163,7 @@ dependencies = [
|
||||||
"heck",
|
"heck",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.87",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -194,6 +194,17 @@ version = "0.8.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "derive-deref-rs"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fb44ba65b4c7afe45d03d8e33ecb53a21c57d0ffff196f04aefa15c43671f8a6"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "displaydoc"
|
name = "displaydoc"
|
||||||
version = "0.2.5"
|
version = "0.2.5"
|
||||||
|
@ -202,7 +213,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.87",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -273,6 +284,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10"
|
checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
|
"futures-sink",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -281,6 +293,12 @@ version = "0.3.31"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"
|
checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-io"
|
||||||
|
version = "0.3.31"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-sink"
|
name = "futures-sink"
|
||||||
version = "0.3.31"
|
version = "0.3.31"
|
||||||
|
@ -300,9 +318,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"
|
checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
|
"futures-io",
|
||||||
|
"futures-sink",
|
||||||
"futures-task",
|
"futures-task",
|
||||||
|
"memchr",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"pin-utils",
|
"pin-utils",
|
||||||
|
"slab",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -580,7 +602,7 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.87",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -589,6 +611,7 @@ version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"clap",
|
"clap",
|
||||||
|
"derive-deref-rs",
|
||||||
"idmangler-lib",
|
"idmangler-lib",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -776,7 +799,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.87",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -848,6 +871,7 @@ dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"bytes",
|
"bytes",
|
||||||
"encoding_rs",
|
"encoding_rs",
|
||||||
|
"futures-channel",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"h2",
|
"h2",
|
||||||
|
@ -1010,7 +1034,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.87",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1092,6 +1116,17 @@ version = "2.6.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "1.0.109"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.87"
|
version = "2.0.87"
|
||||||
|
@ -1120,7 +1155,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.87",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1174,7 +1209,7 @@ checksum = "a7c61ec9a6f64d2793d8a45faba21efbe3ced62a886d44c36a009b2b519b4c7e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.87",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1358,7 +1393,7 @@ dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.87",
|
||||||
"wasm-bindgen-shared",
|
"wasm-bindgen-shared",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1393,7 +1428,7 @@ checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.87",
|
||||||
"wasm-bindgen-backend",
|
"wasm-bindgen-backend",
|
||||||
"wasm-bindgen-shared",
|
"wasm-bindgen-shared",
|
||||||
]
|
]
|
||||||
|
@ -1558,7 +1593,7 @@ checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.87",
|
||||||
"synstructure",
|
"synstructure",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1579,7 +1614,7 @@ checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.87",
|
||||||
"synstructure",
|
"synstructure",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1608,5 +1643,5 @@ checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.87",
|
||||||
]
|
]
|
||||||
|
|
|
@ -10,8 +10,9 @@ description = "A cli tool to generate fake wynntils items"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
base64 = "0.22.1"
|
base64 = "0.22.1"
|
||||||
clap = { version = "4.5.20", features = ["derive"] }
|
clap = { version = "4.5.20", features = ["derive"] }
|
||||||
|
derive-deref-rs = "0.1.1"
|
||||||
idmangler-lib = "0.4.0"
|
idmangler-lib = "0.4.0"
|
||||||
reqwest = "0.12.9"
|
reqwest = { version = "0.12.9", features = ["blocking", "json"] }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
thiserror = "1.0.68"
|
thiserror = "1.0.68"
|
||||||
|
|
|
@ -4,30 +4,42 @@ use thiserror::Error;
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum Errorfr {
|
pub enum Errorfr {
|
||||||
/// item config json is missing
|
/// item config json is missing
|
||||||
#[error("Error 1: item config json is missing")]
|
#[error("Error 1.1: item config json is missing.")]
|
||||||
ItemJsonMissing,
|
ItemJsonMissing,
|
||||||
|
|
||||||
/// item config json is corrupt
|
/// item config json is corrupt
|
||||||
#[error("Error 2: item config json is corrupt, Reread config.md\n{0}")]
|
#[error("Error 1.2: item config json is corrupt, Reread config.md.\n{0}")]
|
||||||
ItemJsonCorrupt(serde_json::Error),
|
ItemJsonCorrupt(serde_json::Error),
|
||||||
|
|
||||||
/// idmap is missing
|
/// idmap is missing
|
||||||
#[error("Error 3: id_keys.json is missing")]
|
#[error("Error 1.3: id_keys.json is missing")]
|
||||||
IDMapJsonMissing,
|
IDMapJsonMissing,
|
||||||
|
|
||||||
/// idmap is corrupt
|
/// idmap is corrupt
|
||||||
#[error("Error 4: id_keys.json is corrupt")]
|
#[error("Error 2.1: id_keys.json is corrupt")]
|
||||||
IDMapJsonCorrupt,
|
IDMapJsonCorrupt,
|
||||||
|
|
||||||
/// shiny data json is missing
|
/// shiny data json is missing
|
||||||
#[error("Error 5: shiny_stats.json is missing.")]
|
#[error("Error 2.2: shiny_stats.json is missing.")]
|
||||||
ShinyJsonMissing,
|
ShinyJsonMissing,
|
||||||
|
|
||||||
/// shiny data json is corrupt
|
/// shiny data json is corrupt
|
||||||
#[error("Error 6: shiny_stats.json is corrupt.")]
|
#[error("Error 2.3: shiny_stats.json is corrupt.")]
|
||||||
ShinyJsonCorrupt,
|
ShinyJsonCorrupt,
|
||||||
|
|
||||||
///
|
/// could not download the file
|
||||||
#[error("Error 7: Item Type is missing from json (add an \"item_type\" field")]
|
#[error("Error 3.1: Download request failed. Check your network settings.")]
|
||||||
ItemTypeMissing
|
JsonDlReqFail,
|
||||||
}
|
|
||||||
|
/// invalid body response after downloading
|
||||||
|
#[error("Error 3.2: Download body is invalid. Something is broken.")]
|
||||||
|
JsonDlReqBodyInvalid,
|
||||||
|
|
||||||
|
/// unable to create file after download
|
||||||
|
#[error("Error 3.3: Download successful, but unable to actually create the file.")]
|
||||||
|
JsonDlReqFileCreateFail,
|
||||||
|
|
||||||
|
/// unable to copy (write in) file content
|
||||||
|
#[error("Error 9: Download successful, but unable to write to file.")]
|
||||||
|
JsonDlReqFileWriteFail,
|
||||||
|
}
|
||||||
|
|
152
src/main.rs
152
src/main.rs
|
@ -1,19 +1,14 @@
|
||||||
use idmangler_lib::{
|
use idmangler_lib::{
|
||||||
encoding::encode_string,
|
encoding::encode_string,
|
||||||
types::{
|
types::{
|
||||||
ItemType, TransformVersion, {RollType, Stat}, Element
|
Element, ItemType, TransformVersion, {RollType, Stat},
|
||||||
},
|
},
|
||||||
DataEncoder, EndData, IdentificationData, NameData, PowderData, RerollData, ShinyData,
|
DataEncoder, EndData, IdentificationData, NameData, PowderData, RerollData, ShinyData,
|
||||||
StartData, TypeData,
|
StartData, TypeData,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::{
|
use std::ops::Deref;
|
||||||
collections::HashMap,
|
use std::{collections::HashMap, env, fs, io, panic, path::PathBuf};
|
||||||
env,
|
|
||||||
fs,
|
|
||||||
panic
|
|
||||||
};
|
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
mod structures;
|
mod structures;
|
||||||
use crate::structures::*;
|
use crate::structures::*;
|
||||||
|
@ -21,8 +16,9 @@ mod errorfr;
|
||||||
use crate::errorfr::Errorfr;
|
use crate::errorfr::Errorfr;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use reqwest::Url;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug, Clone)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
struct Args {
|
struct Args {
|
||||||
/// Path for config path
|
/// Path for config path
|
||||||
|
@ -32,67 +28,120 @@ struct Args {
|
||||||
/// Enable debug mode
|
/// Enable debug mode
|
||||||
#[arg(short, long, default_value_t = false)]
|
#[arg(short, long, default_value_t = false)]
|
||||||
debug: bool,
|
debug: bool,
|
||||||
|
|
||||||
|
/// Download jsons (for ease of use)
|
||||||
|
#[arg(long)]
|
||||||
|
download: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// const fallbackconfigpath: String = "config.json".to_owned();
|
fn dl_json(
|
||||||
|
url: Url,
|
||||||
|
savename: String,
|
||||||
|
args: Args,
|
||||||
|
executablePath: &str,
|
||||||
|
debug_mode: bool,
|
||||||
|
) -> Result<(), Errorfr> {
|
||||||
|
let resp = reqwest::blocking::get(url).map_err(|_| Errorfr::JsonDlReqFail)?;
|
||||||
|
let body = resp.text().map_err(|_| Errorfr::JsonDlReqBodyInvalid)?;
|
||||||
|
let savepath = format!("{}",savename);
|
||||||
|
println!("Downloading to {savepath}");
|
||||||
|
let mut out = fs::File::create(savepath)
|
||||||
|
.map_err(|_| Errorfr::JsonDlReqFileCreateFail)?;
|
||||||
|
io::copy(&mut body.as_bytes(), &mut out).map_err(|_| Errorfr::JsonDlReqFileWriteFail)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
if let Err(e) = cook() {
|
|
||||||
println!("{}",e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn cook() -> Result<(), Errorfr> {
|
|
||||||
// enable fancypanic when building for release
|
// enable fancypanic when building for release
|
||||||
// fancypanic();
|
// fancypanic();
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
let mut executablePath = env::current_exe().unwrap();
|
let mut executablePath = env::current_exe().unwrap();
|
||||||
PathBuf::pop(&mut executablePath);
|
PathBuf::pop(&mut executablePath);
|
||||||
let executablePath = executablePath.to_str().unwrap();
|
let executable_path = executablePath.to_str().unwrap();
|
||||||
|
|
||||||
let mut debug_mode = false;
|
let mut debug_mode = false;
|
||||||
if args.debug == true {
|
if args.debug == true {
|
||||||
debug_mode = true;
|
debug_mode = true;
|
||||||
println!("Debug mode enabled");
|
println!("Debug mode enabled");
|
||||||
};
|
};
|
||||||
let mut config: String = String::from(executablePath.to_owned()+"config.json");
|
|
||||||
|
// download jsons if necessary
|
||||||
|
if let Some(dlvalue) = &args.download {
|
||||||
|
let jsons = DownloadJsons::from(dlvalue.clone());
|
||||||
|
if jsons == DownloadJsons::all || jsons == DownloadJsons::shiny_stats {
|
||||||
|
if let Err(e) = dl_json(
|
||||||
|
"https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Data-Storage/shiny_stats.json".parse().unwrap(),
|
||||||
|
format!("{}{}", executable_path, "shiny_stats.json"),
|
||||||
|
args.clone(),
|
||||||
|
executable_path,
|
||||||
|
debug_mode
|
||||||
|
) { // error handling below
|
||||||
|
println!("{} Filename: {}",e,dlvalue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if jsons == DownloadJsons::all || jsons == DownloadJsons::id_keys {
|
||||||
|
if let Err(e) = dl_json(
|
||||||
|
"https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/id_keys.json".parse().unwrap(),
|
||||||
|
format!("{}{}", executable_path, "id_keys.json"),
|
||||||
|
args.clone(),
|
||||||
|
executable_path,
|
||||||
|
debug_mode
|
||||||
|
) { // error handling below
|
||||||
|
println!("{} Filename: {}",e,dlvalue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(e) = cook(args, executable_path, debug_mode) {
|
||||||
|
println!("{}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cook(args: Args, executable_path: &str, mut debug_mode: bool) -> Result<(), Errorfr> {
|
||||||
|
let mut config: String = String::from(executable_path.to_owned() + "config.json");
|
||||||
if let Some(configpathargs) = args.config {
|
if let Some(configpathargs) = args.config {
|
||||||
config = configpathargs;
|
config = configpathargs;
|
||||||
}
|
}
|
||||||
|
|
||||||
// load configs
|
// load configs
|
||||||
let json_config: Jsonconfig = serde_json::from_reader(fs::File::open(config)
|
let json_config: Jsonconfig =
|
||||||
.map_err(|_| Errorfr::ItemJsonMissing)?)
|
serde_json::from_reader(fs::File::open(config).map_err(|_| Errorfr::ItemJsonMissing)?)
|
||||||
.map_err(|e| Errorfr::ItemJsonCorrupt(e))?;
|
.map_err(|e| Errorfr::ItemJsonCorrupt(e))?;
|
||||||
let idsmap: HashMap<String, u8> = serde_json::from_reader(fs::File::open(executablePath.to_owned()+"id_keys.json")
|
let idsmap: HashMap<String, u8> = serde_json::from_reader(
|
||||||
.map_err(|_| Errorfr::IDMapJsonMissing)?)
|
fs::File::open(executable_path.to_owned() + "id_keys.json")
|
||||||
.map_err(|_| Errorfr::IDMapJsonCorrupt)?;
|
.map_err(|_| Errorfr::IDMapJsonMissing)?,
|
||||||
let json_shiny: Vec<Shinystruct> = serde_json::from_reader(fs::File::open(executablePath.to_owned()+"shiny_stats.json")
|
)
|
||||||
.map_err(|_| Errorfr::ShinyJsonMissing)?)
|
.map_err(|_| Errorfr::IDMapJsonCorrupt)?;
|
||||||
.map_err(|_| Errorfr::ShinyJsonCorrupt)?;
|
let json_shiny: Vec<Shinystruct> = serde_json::from_reader(
|
||||||
|
fs::File::open(executable_path.to_owned() + "shiny_stats.json")
|
||||||
|
.map_err(|_| Errorfr::ShinyJsonMissing)?,
|
||||||
|
)
|
||||||
|
.map_err(|_| Errorfr::ShinyJsonCorrupt)?;
|
||||||
// println!("{:?}",idsmap.get("airDamage"));
|
// println!("{:?}",idsmap.get("airDamage"));
|
||||||
|
|
||||||
|
if let Some(debugconfig) = json_config.debug {
|
||||||
|
if debugconfig {
|
||||||
|
debug_mode = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// create necessary variables
|
// create necessary variables
|
||||||
let mut out = Vec::new();
|
let mut out = Vec::new();
|
||||||
let ver = TransformVersion::Version1;
|
let ver = TransformVersion::Version1;
|
||||||
|
|
||||||
|
|
||||||
// ENCODE: StartData
|
// ENCODE: StartData
|
||||||
StartData(ver)
|
StartData(ver).encode(ver, &mut out).unwrap();
|
||||||
.encode(ver, &mut out)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// ENCODE: TypeData
|
// ENCODE: TypeData
|
||||||
TypeData(ItemType::from(json_config.item_type))
|
TypeData(ItemType::from(json_config.item_type))
|
||||||
.encode(ver, &mut out)
|
.encode(ver, &mut out)
|
||||||
.map_err(|_| Errorfr::ItemTypeMissing)?;
|
.unwrap();
|
||||||
|
|
||||||
// ENCODE: NameData
|
// ENCODE: NameData
|
||||||
NameData(String::from(format!("{}", json_config.name.trim())))
|
NameData(String::from(format!("{}", json_config.name.trim())))
|
||||||
.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 json_config.ids {
|
||||||
|
@ -125,8 +174,6 @@ fn cook() -> Result<(), Errorfr> {
|
||||||
.encode(ver, &mut out)
|
.encode(ver, &mut out)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 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 json_config.powders {
|
||||||
|
@ -135,34 +182,19 @@ fn cook() -> Result<(), Errorfr> {
|
||||||
// match for the powder type
|
// match for the powder type
|
||||||
for _ in 0..powderamount {
|
for _ in 0..powderamount {
|
||||||
let eletype = match eachpowder.r#type.to_ascii_lowercase() {
|
let eletype = match eachpowder.r#type.to_ascii_lowercase() {
|
||||||
'e' => {
|
'e' => Element::Earth,
|
||||||
Element::Earth
|
't' => Element::Thunder,
|
||||||
}
|
'w' => Element::Water,
|
||||||
't' => {
|
'f' => Element::Fire,
|
||||||
Element::Thunder
|
'a' => Element::Air,
|
||||||
}
|
_ => Element::Thunder,
|
||||||
'w' => {
|
|
||||||
Element::Water
|
|
||||||
}
|
|
||||||
'f' => {
|
|
||||||
Element::Fire
|
|
||||||
}
|
|
||||||
'a' => {
|
|
||||||
Element::Air
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
Element::Thunder
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
if debug_mode {
|
if debug_mode {
|
||||||
dbg!(powdertier);
|
dbg!(powdertier);
|
||||||
dbg!(eletype);
|
dbg!(eletype);
|
||||||
}
|
}
|
||||||
powdervec.push(Some((eletype,powdertier)));
|
powdervec.push(Some((eletype, powdertier)));
|
||||||
|
}
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if debug_mode {
|
if debug_mode {
|
||||||
dbg!(&powdervec);
|
dbg!(&powdervec);
|
||||||
|
@ -176,8 +208,6 @@ fn cook() -> Result<(), Errorfr> {
|
||||||
.encode(ver, &mut out)
|
.encode(ver, &mut out)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
match json_config.rerolls {
|
match json_config.rerolls {
|
||||||
Some(rerollcount) => {
|
Some(rerollcount) => {
|
||||||
if rerollcount != 0 {
|
if rerollcount != 0 {
|
||||||
|
@ -191,8 +221,6 @@ fn cook() -> Result<(), Errorfr> {
|
||||||
None => pass(),
|
None => pass(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let mut realshinykey: u8;
|
let mut realshinykey: u8;
|
||||||
if let Some(shiny) = json_config.shiny {
|
if let Some(shiny) = json_config.shiny {
|
||||||
if let ref _shinykey = shiny.key {
|
if let ref _shinykey = shiny.key {
|
||||||
|
@ -218,7 +246,6 @@ fn cook() -> Result<(), Errorfr> {
|
||||||
}
|
}
|
||||||
.encode(ver, &mut out)
|
.encode(ver, &mut out)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,7 +274,6 @@ fn cook() -> Result<(), Errorfr> {
|
||||||
|
|
||||||
// println!("{:#?}", out);
|
// println!("{:#?}", out);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fancypanic() {
|
fn fancypanic() {
|
||||||
|
|
|
@ -53,7 +53,41 @@ impl From<ItemTypeDeser> for ItemType {
|
||||||
ItemTypeDeser::Tome => ItemType::Tome,
|
ItemTypeDeser::Tome => ItemType::Tome,
|
||||||
ItemTypeDeser::Charm => ItemType::Charm,
|
ItemTypeDeser::Charm => ItemType::Charm,
|
||||||
ItemTypeDeser::CraftedConsu => ItemType::CraftedConsu,
|
ItemTypeDeser::CraftedConsu => ItemType::CraftedConsu,
|
||||||
ItemTypeDeser::CraftedGear => ItemType::CraftedGear
|
ItemTypeDeser::CraftedGear => ItemType::CraftedGear,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash, Debug, Deserialize)]
|
||||||
|
pub enum DownloadJsons {
|
||||||
|
none,
|
||||||
|
id_keys,
|
||||||
|
shiny_stats,
|
||||||
|
all,
|
||||||
|
}
|
||||||
|
impl From<String> for DownloadJsons {
|
||||||
|
fn from(value: String) -> Self {
|
||||||
|
match value.to_lowercase().as_str().trim() {
|
||||||
|
"none" => {
|
||||||
|
println!("download NONE");
|
||||||
|
DownloadJsons::none
|
||||||
|
}
|
||||||
|
"id_keys" | "idkeys" | "idkeys.json" | "id_keys.json" => {
|
||||||
|
println!("download ID_KEYS");
|
||||||
|
DownloadJsons::id_keys
|
||||||
|
}
|
||||||
|
"shiny_stats" | "shinystats" | "shiny_stats.json" | "shinystats.json" => {
|
||||||
|
println!("download SHINY_STATS");
|
||||||
|
DownloadJsons::shiny_stats
|
||||||
|
}
|
||||||
|
"all" | "everything" | "both" => {
|
||||||
|
println!("download BOTH");
|
||||||
|
DownloadJsons::all
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
println!("Could not understand what Jsons to download, sorry.");
|
||||||
|
DownloadJsons::none
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue