ran rustfmt because people told me to
This commit is contained in:
parent
85fd671a65
commit
04ad18f538
2 changed files with 57 additions and 88 deletions
95
src/main.rs
95
src/main.rs
|
@ -1,35 +1,21 @@
|
||||||
use idmangler_lib::{
|
use idmangler_lib::{
|
||||||
|
encoding::encode_string,
|
||||||
EndData, IdentificationData, NameData,
|
|
||||||
PowderData, RerollData, ShinyData, StartData,
|
|
||||||
TypeData, DataEncoder,
|
|
||||||
|
|
||||||
encoding::{encode_string},
|
|
||||||
types::{
|
types::{
|
||||||
ItemType,
|
ItemType, Powders, TransformVersion, {RollType, Stat},
|
||||||
Powders,
|
|
||||||
{RollType, Stat},
|
|
||||||
TransformVersion,
|
|
||||||
},
|
},
|
||||||
|
DataEncoder, EndData, IdentificationData, NameData, PowderData, RerollData, ShinyData,
|
||||||
|
StartData, TypeData,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use serde_json;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::panic;
|
use std::panic;
|
||||||
use std::env;
|
|
||||||
use std::string::ToString;
|
use std::string::ToString;
|
||||||
use serde_json;
|
|
||||||
mod structures;
|
mod structures;
|
||||||
use crate::structures::*;
|
use crate::structures::*;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
|
@ -51,8 +37,6 @@ fn main() {
|
||||||
// fancypanic();
|
// fancypanic();
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let mut debugMode = false;
|
let mut debugMode = false;
|
||||||
if args.debugmode == true {
|
if args.debugmode == true {
|
||||||
debugMode = true;
|
debugMode = true;
|
||||||
|
@ -63,21 +47,16 @@ fn main() {
|
||||||
configpath = configpathargs;
|
configpath = configpathargs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// newest json reading code
|
// newest json reading code
|
||||||
let json_config: jsonconfig = serde_json::from_reader(
|
let json_config: jsonconfig =
|
||||||
fs::File::open(configpath).expect(ERROR[1]))
|
serde_json::from_reader(fs::File::open(configpath).expect(ERROR[1])).expect(ERROR[2]);
|
||||||
.expect(ERROR[2]);
|
let idsmap: HashMap<String, u8> =
|
||||||
let idsmap: HashMap<String, u8> = serde_json::from_reader(
|
serde_json::from_reader(fs::File::open("id_keys.json").expect(ERROR[3])).expect(ERROR[4]);
|
||||||
fs::File::open("id_keys.json").expect(ERROR[3]))
|
let json_shiny: Vec<shinystruct> =
|
||||||
.expect(ERROR[4]);
|
serde_json::from_reader(fs::File::open("shiny_stats.json").expect(ERROR[5]))
|
||||||
let json_shiny: Vec<shinystruct> = serde_json::from_reader(
|
|
||||||
fs::File::open("shiny_stats.json").expect(ERROR[5]))
|
|
||||||
.expect(ERROR[6]);
|
.expect(ERROR[6]);
|
||||||
// println!("{:?}",idsmap.get("airDamage"));
|
// println!("{:?}",idsmap.get("airDamage"));
|
||||||
|
|
||||||
|
|
||||||
let mut out = Vec::new();
|
let mut out = Vec::new();
|
||||||
let ver = TransformVersion::Version1;
|
let ver = TransformVersion::Version1;
|
||||||
|
|
||||||
|
@ -89,7 +68,6 @@ fn main() {
|
||||||
.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 {
|
||||||
|
@ -121,21 +99,14 @@ fn main() {
|
||||||
.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 {
|
||||||
let powdertier = eachpowder.tier; // get the powder tier
|
let powdertier = eachpowder.tier; // get the powder tier
|
||||||
let powderamount:u8 = match eachpowder.amount { // get amount of powder if exists, otherwise 1
|
let powderamount: u8 = match eachpowder.amount {
|
||||||
Some(amount) => {
|
// get amount of powder if exists, otherwise 1
|
||||||
amount
|
Some(amount) => amount, // good,
|
||||||
},// good,
|
None => 1, // bad,
|
||||||
None => {
|
|
||||||
1
|
|
||||||
}// bad,
|
|
||||||
};
|
};
|
||||||
// match for the powder type
|
// match for the powder type
|
||||||
// no need to return to variable or i'll need to rematch AGAIN
|
// no need to return to variable or i'll need to rematch AGAIN
|
||||||
|
@ -147,7 +118,7 @@ fn main() {
|
||||||
if debugMode {
|
if debugMode {
|
||||||
println!("Powder type: Earth");
|
println!("Powder type: Earth");
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
'T' | 't' => {
|
'T' | 't' => {
|
||||||
for _i in 0..powderamount {
|
for _i in 0..powderamount {
|
||||||
powdervec.push((Powders::THUNDER, powdertier))
|
powdervec.push((Powders::THUNDER, powdertier))
|
||||||
|
@ -155,7 +126,7 @@ fn main() {
|
||||||
if debugMode {
|
if debugMode {
|
||||||
println!("Powder type: Thunder");
|
println!("Powder type: Thunder");
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
'W' | 'w' => {
|
'W' | 'w' => {
|
||||||
for _i in 0..powderamount {
|
for _i in 0..powderamount {
|
||||||
powdervec.push((Powders::WATER, powdertier))
|
powdervec.push((Powders::WATER, powdertier))
|
||||||
|
@ -163,7 +134,7 @@ fn main() {
|
||||||
if debugMode {
|
if debugMode {
|
||||||
println!("Powder type: Water");
|
println!("Powder type: Water");
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
'F' | 'f' => {
|
'F' | 'f' => {
|
||||||
for _i in 0..powderamount {
|
for _i in 0..powderamount {
|
||||||
powdervec.push((Powders::FIRE, powdertier))
|
powdervec.push((Powders::FIRE, powdertier))
|
||||||
|
@ -171,7 +142,7 @@ fn main() {
|
||||||
if debugMode {
|
if debugMode {
|
||||||
println!("Powder type: Fire");
|
println!("Powder type: Fire");
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
'A' | 'a' => {
|
'A' | 'a' => {
|
||||||
for _i in 0..powderamount {
|
for _i in 0..powderamount {
|
||||||
powdervec.push((Powders::AIR, powdertier))
|
powdervec.push((Powders::AIR, powdertier))
|
||||||
|
@ -179,7 +150,7 @@ fn main() {
|
||||||
if debugMode {
|
if debugMode {
|
||||||
println!("Powder type: Air");
|
println!("Powder type: Air");
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
_ => {
|
_ => {
|
||||||
for _i in 0..powderamount {
|
for _i in 0..powderamount {
|
||||||
powdervec.push((Powders::THUNDER, powdertier))
|
powdervec.push((Powders::THUNDER, powdertier))
|
||||||
|
@ -207,7 +178,6 @@ fn main() {
|
||||||
.encode(ver, &mut out)
|
.encode(ver, &mut out)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
||||||
match json_config.rerolls {
|
match json_config.rerolls {
|
||||||
Some(i) => {
|
Some(i) => {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
|
@ -216,8 +186,8 @@ fn main() {
|
||||||
println!("Rerolls: {}", i)
|
println!("Rerolls: {}", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
None => pass()
|
None => pass(),
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut realshinykey: u8;
|
let mut realshinykey: u8;
|
||||||
|
@ -249,16 +219,11 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// prints (Water,6) 255 times
|
// prints (Water,6) 255 times
|
||||||
// println!("{:?}",vec![(Powders::WATER, 6); 255]);
|
// println!("{:?}",vec![(Powders::WATER, 6); 255]);
|
||||||
|
|
||||||
EndData.encode(ver, &mut out).unwrap();
|
EndData.encode(ver, &mut out).unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// final string print
|
// final string print
|
||||||
println!("{}", encode_string(&out));
|
println!("{}", encode_string(&out));
|
||||||
|
|
||||||
|
@ -278,17 +243,21 @@ fn main() {
|
||||||
// println!("{:#?}", out);
|
// println!("{:#?}", out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn fancypanic() {
|
fn fancypanic() {
|
||||||
panic::set_hook(Box::new(|panic_info| {
|
panic::set_hook(Box::new(|panic_info| {
|
||||||
let panic_msg = format!("{panic_info}");
|
let panic_msg = format!("{panic_info}");
|
||||||
println!("{}", panic_msg.lines().skip(1).next().unwrap_or("HOW DID YOU BREAK THE PANIC HANDLER???"));
|
println!(
|
||||||
|
"{}",
|
||||||
|
panic_msg
|
||||||
|
.lines()
|
||||||
|
.skip(1)
|
||||||
|
.next()
|
||||||
|
.unwrap_or("HOW DID YOU BREAK THE PANIC HANDLER???")
|
||||||
|
);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pass() {
|
fn pass() {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
const ERROR: [&'static str; 7] = [
|
const ERROR: [&'static str; 7] = [
|
||||||
"Error 0: what did you even do to get this? ",
|
"Error 0: what did you even do to get this? ",
|
||||||
|
|
|
@ -4,13 +4,13 @@ use serde::Deserialize;
|
||||||
pub struct Powder {
|
pub struct Powder {
|
||||||
pub r#type: char,
|
pub r#type: char,
|
||||||
pub tier: u8,
|
pub tier: u8,
|
||||||
pub amount: Option<u8>
|
pub amount: Option<u8>,
|
||||||
}
|
}
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct Identificationer {
|
pub struct Identificationer {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub base: i32,
|
pub base: i32,
|
||||||
pub roll: Option<u8>
|
pub roll: Option<u8>,
|
||||||
}
|
}
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct jsonconfig {
|
pub struct jsonconfig {
|
||||||
|
@ -20,16 +20,16 @@ pub struct jsonconfig {
|
||||||
pub ids: Vec<Identificationer>,
|
pub ids: Vec<Identificationer>,
|
||||||
pub powder_limit: u8,
|
pub powder_limit: u8,
|
||||||
pub powders: Vec<Powder>,
|
pub powders: Vec<Powder>,
|
||||||
pub rerolls:Option<u8>
|
pub rerolls: Option<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct shinystruct {
|
pub struct shinystruct {
|
||||||
pub id: u8,
|
pub id: u8,
|
||||||
pub key:String
|
pub key: String,
|
||||||
}
|
}
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct shinyjson {
|
pub struct shinyjson {
|
||||||
pub key: String,
|
pub key: String,
|
||||||
pub value: i64
|
pub value: i64,
|
||||||
}
|
}
|
Loading…
Reference in a new issue