fixed every linter warning

This commit is contained in:
endernon 2024-12-25 00:30:38 +00:00
parent e2868aed8c
commit 5dd7966761
8 changed files with 98 additions and 71 deletions

2
.gitignore vendored
View file

@ -22,4 +22,4 @@ product/
releases releases
id_keys.json id_keys.json
shiny_stats.json ShinyStats.json

View file

@ -4,6 +4,6 @@ Copyright (c) 2024 endernon
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. The above copyright notice and this permission notice shall be included in All copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -17,7 +17,7 @@ run `cargo install idmangler-cli`.
## Usage ## Usage
- Move the program to some folder along with config.json . Download these three files and place them next to the program: - Move the program to some folder along with config.json . Download these three files and place them next to the program:
- https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/id_keys.json - https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/id_keys.json
- https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Data-Storage/shiny_stats.json - https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Data-Storage/ShinyStats.json
- Open a terminal (Windows: use cmd or Powershell , Linux: use your preferred Terminal Emulator) - Open a terminal (Windows: use cmd or Powershell , Linux: use your preferred Terminal Emulator)
- Use the command "cd DIRECTORY" (where DIRECTORY is where the program is stored) - Use the command "cd DIRECTORY" (where DIRECTORY is where the program is stored)

View file

@ -3,7 +3,7 @@
**Name** is stored as a String. It must be a valid Wynncraft item for it to display as intended. **Name** is stored as a String. It must be a valid Wynncraft item for it to display as intended.
## Shiny ID ## Shiny ID
Inside the Shiny{} list, there will be two elements: "key" and "value". Inside the Shiny{} list, there will be two elements: "key" and "value".
The potential keys for any shiny value are listed here: https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Data-Storage/shiny_stats.json The potential keys for any shiny value are listed here: https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Data-Storage/ShinyStats.json
The value is the shown amount. The value is the shown amount.
## Powders ## Powders
@ -23,7 +23,7 @@ Potential value range: 1<->255.
#### Other things about powder format: #### Other things about powder format:
Each value in the array must have a comma at the end except the last. Each value in the array must have a comma at the end except the last.
The use of spaces is optional, as well as letter case for the $TYPE value. The use of spaces is optional, as well as letter case for the $TYPE value.
The keys ("type" "tier" "amount") must all be lowercase. The keys ("type" "tier" "amount") must All be lowercase.
If type is invalid, it will default back to being Thunder powder. If type is invalid, it will default back to being Thunder powder.
#### Powders Example (yes, this looks wacky to show that this is allowed) #### Powders Example (yes, this looks wacky to show that this is allowed)
```json ```json

50
shiny_stats.json Normal file
View file

@ -0,0 +1,50 @@
[
{
"id": 1,
"key": "mobsKilled",
"displayName": "Mobs Killed",
"statUnit": "raw"
},
{
"id": 2,
"key": "raidsWon",
"displayName": "Raids Won",
"statUnit": "raw"
},
{
"id": 3,
"key": "chestsOpened",
"displayName": "Chests Opened",
"statUnit": "raw"
},
{
"id": 4,
"key": "warsWon",
"displayName": "Wars Won",
"statUnit": "raw"
},
{
"id": 5,
"key": "playersKilled",
"displayName": "Players Killed",
"statUnit": "raw"
},
{
"id": 6,
"key": "dungeonsWon",
"displayName": "Dungeons Won",
"statUnit": "raw"
},
{
"id": 7,
"key": "deaths",
"displayName": "Deaths",
"statUnit": "raw"
},
{
"id": 8,
"key": "lootrunsCompleted",
"displayName": "Lootruns Completed",
"statUnit": "raw"
}
]

View file

@ -12,19 +12,19 @@ pub enum Errorfr {
ItemJsonCorrupt(serde_json::Error), ItemJsonCorrupt(serde_json::Error),
/// idmap is missing /// idmap is missing
#[error("Error 1.3: id_keys.json is missing. \nYou should run \"--download id_keys\" or \"--download all\".")] #[error("Error 1.3: id_keys.json is missing. \nYou should run \"--download id_keys\" or \"--download All\".")]
IDMapJsonMissing, IDMapJsonMissing,
/// idmap is corrupt /// idmap is corrupt
#[error("Error 2.1: id_keys.json is corrupt. \nYou should run \"--download id_keys\" or \"--download all\".")] #[error("Error 2.1: id_keys.json is corrupt. \nYou should run \"--download id_keys\" or \"--download All\".")]
IDMapJsonCorrupt, IDMapJsonCorrupt,
/// shiny data json is missing /// shiny data json is missing
#[error("Error 2.2: shiny_stats.json is missing. \nYou should run \"--download shiny_stats\" or \"--download all\".")] #[error("Error 2.2: ShinyStats.json is missing. \nYou should run \"--download ShinyStats\" or \"--download All\".")]
ShinyJsonMissing, ShinyJsonMissing,
/// shiny data json is corrupt /// shiny data json is corrupt
#[error("Error 2.3: shiny_stats.json is corrupt. \nYou should run \"--download shiny_stats\" or \"--download all\".")] #[error("Error 2.3: ShinyStats.json is corrupt. \nYou should run \"--download ShinyStats\" or \"--download All\".")]
ShinyJsonCorrupt, ShinyJsonCorrupt,
/// could not download the file /// could not download the file

View file

@ -7,7 +7,6 @@ use idmangler_lib::{
StartData, TypeData, StartData, TypeData,
}; };
use std::ops::Deref;
use std::{collections::HashMap, env, fs, io, panic, path::PathBuf}; use std::{collections::HashMap, env, fs, io, panic, path::PathBuf};
mod structures; mod structures;
@ -37,14 +36,11 @@ struct Args {
fn dl_json( fn dl_json(
url: Url, url: Url,
savename: String, savename: String,
args: Args,
executablePath: &str,
debug_mode: bool,
) -> Result<(), Errorfr> { ) -> Result<(), Errorfr> {
let resp = reqwest::blocking::get(url).map_err(|_| Errorfr::JsonDlReqFail)?; let resp = reqwest::blocking::get(url).map_err(|_| Errorfr::JsonDlReqFail)?;
let body = resp.text().map_err(|_| Errorfr::JsonDlReqBodyInvalid)?; let body = resp.text().map_err(|_| Errorfr::JsonDlReqBodyInvalid)?;
let savepath = format!("{}",savename); let savepath = format!("{}",savename);
println!("Downloading to {savepath}"); println!("Downloading file to {savepath}");
let mut out = fs::File::create(savepath) let mut out = fs::File::create(savepath)
.map_err(|_| Errorfr::JsonDlReqFileCreateFail)?; .map_err(|_| Errorfr::JsonDlReqFileCreateFail)?;
io::copy(&mut body.as_bytes(), &mut out).map_err(|_| Errorfr::JsonDlReqFileWriteFail)?; io::copy(&mut body.as_bytes(), &mut out).map_err(|_| Errorfr::JsonDlReqFileWriteFail)?;
@ -53,9 +49,9 @@ fn dl_json(
fn main() { fn main() {
let args = Args::parse(); let args = Args::parse();
let mut executablePath = env::current_exe().unwrap(); let mut executable_path = env::current_exe().unwrap();
PathBuf::pop(&mut executablePath); PathBuf::pop(&mut executable_path);
let executable_path = executablePath.to_str().unwrap(); let executable_path = executable_path.to_str().unwrap();
let mut debug_mode = false; let mut debug_mode = false;
if args.debug == true { if args.debug == true {
@ -66,24 +62,18 @@ fn main() {
// download jsons if necessary // download jsons if necessary
if let Some(dlvalue) = &args.download { if let Some(dlvalue) = &args.download {
let jsons = DownloadJsons::from(dlvalue.clone()); let jsons = DownloadJsons::from(dlvalue.clone());
if jsons == DownloadJsons::all || jsons == DownloadJsons::shiny_stats { if jsons == DownloadJsons::All || jsons == DownloadJsons::ShinyStats {
if let Err(e) = dl_json( if let Err(e) = dl_json(
"https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Data-Storage/shiny_stats.json".parse().unwrap(), "https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Data-Storage/shiny_stats.json".parse().unwrap(),
format!("{}{}", executable_path, "shiny_stats.json"), format!("{}{}", executable_path, "shiny_stats.json"),
args.clone(),
executable_path,
debug_mode
) { // error handling below ) { // error handling below
println!("{} Filename: {}",e,dlvalue) println!("{} Filename: {}",e,dlvalue)
} }
} }
if jsons == DownloadJsons::all || jsons == DownloadJsons::id_keys { if jsons == DownloadJsons::All || jsons == DownloadJsons::IdKeys {
if let Err(e) = dl_json( if let Err(e) = dl_json(
"https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/id_keys.json".parse().unwrap(), "https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/id_keys.json".parse().unwrap(),
format!("{}{}", executable_path, "id_keys.json"), format!("{}{}", executable_path, "id_keys.json"),
args.clone(),
executable_path,
debug_mode
) { // error handling below ) { // error handling below
println!("{} Filename: {}",e,dlvalue) println!("{} Filename: {}",e,dlvalue)
} }
@ -96,8 +86,7 @@ fn main() {
} }
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 mut config: String = String::from(executable_path.to_owned() + "/config.json"); let config = args.config;
config = args.config;
// load configs // load configs
@ -110,7 +99,7 @@ fn cook(args: Args, executable_path: &str, mut debug_mode: bool) -> Result<(), E
) )
.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() + "/shiny_stats.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)?;
@ -220,31 +209,29 @@ 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) = json_config.shiny {
if let ref _shinykey = shiny.key { let ref _shinykey = shiny.key;
if let shinyvalue = shiny.value { 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 {
realshinykey = i.id; realshinykey = i.id;
if debug_mode {
dbg!(&shiny.key);
}
}
}
if debug_mode { if debug_mode {
dbg!(&realshinykey); dbg!(&shiny.key);
dbg!(&shinyvalue);
} }
// ENCODE: ShinyData (if applicable)
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
}
.encode(ver, &mut out)
.unwrap();
} }
} }
if debug_mode {
dbg!(&realshinykey);
dbg!(&shinyvalue);
}
// ENCODE: ShinyData (if applicable)
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
}
.encode(ver, &mut out)
.unwrap();
} }
// prints (Water,6) 255 times // prints (Water,6) 255 times
@ -273,14 +260,4 @@ fn cook(args: Args, executable_path: &str, mut debug_mode: bool) -> Result<(), E
Ok(()) Ok(())
} }
fn pass() {} fn pass() {}
const ERROR: [&'static str; 7] = [
"Error 0: what did you even do to get this? ",
"Error 1: json config json is missing, obtain it from https://git.frfrnocap.men/endernon/idmangler-cli/raw/branch/main/config.json and move it to this directory. ",
"Error 2: json config json is corrupt. Reread config.md or reobtain it from https://git.frfrnocap.men/endernon/idmangler-cli/raw/branch/main/config.json and move it to this diirectory. ",
"Error 3: Identifications hashmap is missing. Get it from https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/id_keys.json and move it to this directory. ",
"Error 4: Identifications hashmap is corrupt. Reobtain it from https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/id_keys.json and move it to this directory. ",
"Error 5: Shiny data json is missing. Get it from https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Data-Storage/shiny_stats.json and move it to this directory. ",
"Error 6: Shiny data json is corrupt. Get it from https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Data-Storage/shiny_stats.json and move it to this directory. "
];

View file

@ -60,33 +60,33 @@ impl From<ItemTypeDeser> for ItemType {
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash, Debug, Deserialize)] #[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash, Debug, Deserialize)]
pub enum DownloadJsons { pub enum DownloadJsons {
none, None,
id_keys, IdKeys,
shiny_stats, ShinyStats,
all, All,
} }
impl From<String> for DownloadJsons { impl From<String> for DownloadJsons {
fn from(value: String) -> Self { fn from(value: String) -> Self {
match value.to_lowercase().as_str().trim() { match value.to_lowercase().as_str().trim() {
"none" => { "none" => {
println!("download NONE"); println!("download NONE");
DownloadJsons::none DownloadJsons::None
} }
"id_keys" | "idkeys" | "idkeys.json" | "id_keys.json" => { "id_keys" | "idkeys" | "idkeys.json" | "id_keys.json" => {
println!("download ID_KEYS"); println!("download ID_KEYS");
DownloadJsons::id_keys DownloadJsons::IdKeys
} }
"shiny_stats" | "shinystats" | "shiny_stats.json" | "shinystats.json" => { "ShinyStats" | "shinystats" | "ShinyStats.json" | "shinystats.json" => {
println!("download SHINY_STATS"); println!("download SHINY_STATS");
DownloadJsons::shiny_stats DownloadJsons::ShinyStats
} }
"all" | "everything" | "both" => { "All" | "everything" | "both" => {
println!("download BOTH"); println!("download BOTH");
DownloadJsons::all DownloadJsons::All
} }
_ => { _ => {
println!("Could not understand what Jsons to download, sorry."); println!("Could not understand what Jsons to download, sorry.");
DownloadJsons::none DownloadJsons::None
} }
} }
} }