From 04ad18f5381cdcf293941b494a0ee5b4daadab82 Mon Sep 17 00:00:00 2001 From: endernon Date: Tue, 5 Nov 2024 16:53:36 +0000 Subject: [PATCH] ran rustfmt because people told me to --- src/main.rs | 131 ++++++++++++++++-------------------------- src/structures/mod.rs | 14 ++--- 2 files changed, 57 insertions(+), 88 deletions(-) diff --git a/src/main.rs b/src/main.rs index fe67595..b6c841e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,35 +1,21 @@ use idmangler_lib::{ - - EndData, IdentificationData, NameData, - PowderData, RerollData, ShinyData, StartData, - TypeData, DataEncoder, - - encoding::{encode_string}, + encoding::encode_string, types::{ - ItemType, - Powders, - {RollType, Stat}, - TransformVersion, + ItemType, Powders, TransformVersion, {RollType, Stat}, }, + DataEncoder, EndData, IdentificationData, NameData, PowderData, RerollData, ShinyData, + StartData, TypeData, }; +use serde_json; use std::collections::HashMap; +use std::env; use std::fs; use std::panic; -use std::env; use std::string::ToString; -use serde_json; mod structures; use crate::structures::*; - - - - - - - - use clap::Parser; #[derive(Parser, Debug)] @@ -51,33 +37,26 @@ fn main() { // fancypanic(); let args = Args::parse(); - - let mut debugMode = false; if args.debugmode == true { debugMode = true; 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 { configpath = configpathargs; } - - // newest json reading code - let json_config: jsonconfig = serde_json::from_reader( - fs::File::open(configpath).expect(ERROR[1])) - .expect(ERROR[2]); - let idsmap: HashMap = serde_json::from_reader( - fs::File::open("id_keys.json").expect(ERROR[3])) - .expect(ERROR[4]); - let json_shiny: Vec = serde_json::from_reader( - fs::File::open("shiny_stats.json").expect(ERROR[5])) - .expect(ERROR[6]); + let json_config: jsonconfig = + serde_json::from_reader(fs::File::open(configpath).expect(ERROR[1])).expect(ERROR[2]); + let idsmap: HashMap = + serde_json::from_reader(fs::File::open("id_keys.json").expect(ERROR[3])).expect(ERROR[4]); + let json_shiny: Vec = + serde_json::from_reader(fs::File::open("shiny_stats.json").expect(ERROR[5])) + .expect(ERROR[6]); // println!("{:?}",idsmap.get("airDamage")); - let mut out = Vec::new(); let ver = TransformVersion::Version1; @@ -85,11 +64,10 @@ fn main() { 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) .unwrap(); - // json identification data handling let mut idvec = Vec::new(); for eachid in json_config.ids { @@ -121,68 +99,61 @@ fn main() { .encode(ver, &mut out) .unwrap(); - - - - // json powder data handling let mut powdervec = Vec::new(); for eachpowder in json_config.powders { let powdertier = eachpowder.tier; // get the powder tier - let powderamount:u8 = match eachpowder.amount { // get amount of powder if exists, otherwise 1 - Some(amount) => { - amount - },// good, - None => { - 1 - }// bad, + let powderamount: u8 = match eachpowder.amount { + // get amount of powder if exists, otherwise 1 + Some(amount) => amount, // good, + None => 1, // bad, }; // match for the powder type // no need to return to variable or i'll need to rematch AGAIN match eachpowder.r#type { 'E' | 'e' => { for _i in 0..powderamount { - powdervec.push((Powders::EARTH,powdertier)) + powdervec.push((Powders::EARTH, powdertier)) } if debugMode { println!("Powder type: Earth"); } - }, + } 'T' | 't' => { for _i in 0..powderamount { - powdervec.push((Powders::THUNDER,powdertier)) + powdervec.push((Powders::THUNDER, powdertier)) } if debugMode { println!("Powder type: Thunder"); } - }, + } 'W' | 'w' => { for _i in 0..powderamount { - powdervec.push((Powders::WATER,powdertier)) + powdervec.push((Powders::WATER, powdertier)) } if debugMode { println!("Powder type: Water"); } - }, + } 'F' | 'f' => { for _i in 0..powderamount { - powdervec.push((Powders::FIRE,powdertier)) + powdervec.push((Powders::FIRE, powdertier)) } if debugMode { println!("Powder type: Fire"); } - }, + } 'A' | 'a' => { for _i in 0..powderamount { - powdervec.push((Powders::AIR,powdertier)) + powdervec.push((Powders::AIR, powdertier)) } if debugMode { println!("Powder type: Air"); } - }, + } _ => { for _i in 0..powderamount { - powdervec.push((Powders::THUNDER,powdertier)) + powdervec.push((Powders::THUNDER, powdertier)) } if debugMode { println!("Powder type: Broken, fallback Thunder"); @@ -191,12 +162,12 @@ fn main() { }; if debugMode { - println!("Powder tier: {}",powdertier); - println!("Powder amount: {}",powderamount); + println!("Powder tier: {}", powdertier); + println!("Powder amount: {}", powderamount); } } if debugMode { - println!("Powders Vec: {:?}",powdervec); + println!("Powders Vec: {:?}", powdervec); } // old powder data encode kinda, takes data from new encode @@ -207,23 +178,22 @@ fn main() { .encode(ver, &mut out) .unwrap(); - match json_config.rerolls { Some(i) => { if i != 0 { RerollData(i).encode(ver, &mut out).unwrap(); 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 ref shinykey = shiny.key { - if let shinyvalue = shiny.value{ + if let shinyvalue = shiny.value { realshinykey = 1; for i in json_shiny { if i.key == shiny.key { @@ -239,9 +209,9 @@ fn main() { } ShinyData { - id: realshinykey, - 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 + id: realshinykey, + 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 } .encode(ver, &mut out) .unwrap(); @@ -249,16 +219,11 @@ fn main() { } } - - - // prints (Water,6) 255 times // println!("{:?}",vec![(Powders::WATER, 6); 255]); EndData.encode(ver, &mut out).unwrap(); - - // final string print println!("{}", encode_string(&out)); @@ -278,17 +243,21 @@ fn main() { // println!("{:#?}", out); } - fn fancypanic() { panic::set_hook(Box::new(|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] = [ "Error 0: what did you even do to get this? ", diff --git a/src/structures/mod.rs b/src/structures/mod.rs index bfac50f..c48e9e4 100644 --- a/src/structures/mod.rs +++ b/src/structures/mod.rs @@ -4,13 +4,13 @@ use serde::Deserialize; pub struct Powder { pub r#type: char, pub tier: u8, - pub amount: Option + pub amount: Option, } #[derive(Deserialize)] pub struct Identificationer { pub id: String, pub base: i32, - pub roll: Option + pub roll: Option, } #[derive(Deserialize)] pub struct jsonconfig { @@ -20,16 +20,16 @@ pub struct jsonconfig { pub ids: Vec, pub powder_limit: u8, pub powders: Vec, - pub rerolls:Option + pub rerolls: Option, } #[derive(Deserialize)] -pub struct shinystruct{ +pub struct shinystruct { pub id: u8, - pub key:String + pub key: String, } #[derive(Deserialize)] pub struct shinyjson { pub key: String, - pub value: i64 -} \ No newline at end of file + pub value: i64, +}