ran rustfmt because people told me to

This commit is contained in:
endernon 2024-11-05 16:53:36 +00:00
parent 85fd671a65
commit 04ad18f538
2 changed files with 57 additions and 88 deletions

View file

@ -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,33 +37,26 @@ 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;
println!("Debug mode enabled"); println!("Debug mode enabled");
}; };
let mut configpath:String = String::from("config.json"); let mut configpath: String = String::from("config.json");
if let Some(configpathargs) = args.configpath { if let Some(configpathargs) = args.configpath {
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( .expect(ERROR[6]);
fs::File::open("shiny_stats.json").expect(ERROR[5]))
.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;
@ -85,11 +64,10 @@ fn main() {
TypeData(ItemType::Gear).encode(ver, &mut out).unwrap(); TypeData(ItemType::Gear).encode(ver, &mut out).unwrap();
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 {
@ -121,68 +99,61 @@ 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
match eachpowder.r#type { match eachpowder.r#type {
'E' | 'e' => { 'E' | 'e' => {
for _i in 0..powderamount { for _i in 0..powderamount {
powdervec.push((Powders::EARTH,powdertier)) powdervec.push((Powders::EARTH, powdertier))
} }
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))
} }
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))
} }
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))
} }
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))
} }
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))
} }
if debugMode { if debugMode {
println!("Powder type: Broken, fallback Thunder"); println!("Powder type: Broken, fallback Thunder");
@ -191,12 +162,12 @@ fn main() {
}; };
if debugMode { if debugMode {
println!("Powder tier: {}",powdertier); println!("Powder tier: {}", powdertier);
println!("Powder amount: {}",powderamount); println!("Powder amount: {}", powderamount);
} }
} }
if debugMode { if debugMode {
println!("Powders Vec: {:?}",powdervec); println!("Powders Vec: {:?}", powdervec);
} }
// old powder data encode kinda, takes data from new encode // old powder data encode kinda, takes data from new encode
@ -207,23 +178,22 @@ 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 {
RerollData(i).encode(ver, &mut out).unwrap(); RerollData(i).encode(ver, &mut out).unwrap();
if debugMode { if debugMode {
println!("Rerolls: {}",i) println!("Rerolls: {}", i)
} }
} }
}, }
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 {
if let shinyvalue = shiny.value{ if let shinyvalue = shiny.value {
realshinykey = 1; realshinykey = 1;
for i in json_shiny { for i in json_shiny {
if i.key == shiny.key { if i.key == shiny.key {
@ -239,9 +209,9 @@ fn main() {
} }
ShinyData { ShinyData {
id: realshinykey, id: realshinykey,
val: shinyvalue as i64, //- 0b0100_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000, val: shinyvalue as i64, //- 0b0100_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000,
// u16::MAX is the max value of unsigned 16bit value // u16::MAX is the max value of unsigned 16bit value
} }
.encode(ver, &mut out) .encode(ver, &mut out)
.unwrap(); .unwrap();
@ -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? ",

View file

@ -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,
} }