Skip to content

Commit

Permalink
refact: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Grizelj committed Aug 29, 2024
1 parent 336b1b6 commit dec2883
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 115 deletions.
11 changes: 4 additions & 7 deletions src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn app() -> Element {

let read_state = state.read();

let file_name = (*read_state).path.clone();
let file_name = read_state.path.clone();

let file_name_cl: String = match &file_name {
Some(file) => String::from(file.file_name().unwrap().to_str().unwrap()),
Expand All @@ -64,14 +64,11 @@ fn app() -> Element {

let shuffles = preset_state.read().randomizer.shuffles;

let seed = match read_state.seed {
Some(s) => s,
None => 64,
};
let seed = read_state.seed.unwrap_or(64);

let output_file = match &(*read_state).output {
let output_file = match &read_state.output {
Some(x) => x.clone(),
None => String::from(format!("{}", seed)),
None => format!("{}", seed),
};

rsx! {
Expand Down
1 change: 0 additions & 1 deletion src/gui/preset/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::io::Write;
use crate::json::Preset;
use dioxus::prelude::*;

use serde_json;

#[component]
pub fn export() -> Element {
Expand Down
6 changes: 1 addition & 5 deletions src/gui/preset/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::{

use dioxus::prelude::*;

use serde_json;
use std::fs;

#[component]
Expand All @@ -28,10 +27,7 @@ pub fn import() -> Element {

let json: Preset = serde_json::from_str(json_str.as_str()).unwrap();

global_state.write().shop_limit_enabled = match json.randomizer.shops.limit_shop_items {
Some(_) => true,
None => false
};
global_state.write().shop_limit_enabled = json.randomizer.shops.limit_shop_items.is_some();

state.set(json);
},
Expand Down
13 changes: 5 additions & 8 deletions src/gui/randomize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use crate::{cli::Arguments, json::Preset, mkpsxiso, patch};
use dioxus::prelude::*;

#[derive(Clone, Copy, PartialEq)]
#[derive(Default)]
enum Steps {
#[default]
Input,
Extracting,
Randomizing,
Expand All @@ -28,15 +30,10 @@ impl Steps {
}
}

impl Default for Steps {
fn default() -> Self {
Steps::Input
}
}

#[component]
pub fn randomize() -> Element {
let mut state = use_signal::<Steps>(|| Steps::default());
let mut state = use_signal::<Steps>(Steps::default);
let args_state = use_context::<Signal<Arguments>>();
let mut preset_state = use_context::<Signal<Preset>>();

Expand All @@ -61,7 +58,7 @@ pub fn randomize() -> Element {
r#type: "button",
id: "randomize",
onclick: move |_| {
let current_state = state.read().clone();
let current_state = *state.read();

if !current_state.randomizing() {
state.set(Steps::Extracting);
Expand All @@ -79,7 +76,7 @@ pub fn randomize() -> Element {
None => format!("{}", preset_state.read().randomizer.seed)
};

if !mkpsxiso::extract(&path).await {
if !mkpsxiso::extract(path).await {
panic!("Error extracting");
}

Expand Down
3 changes: 1 addition & 2 deletions src/gui/scaling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::gui::{number_field, number_field_float, slider};
use crate::{gui::checkbox, json::Preset};

use dioxus::prelude::*;
use dmw3_consts;

#[component]
pub fn scaling() -> Element {
Expand Down Expand Up @@ -52,7 +51,7 @@ pub fn scaling() -> Element {
oninput: move |x: Event<FormData>| {
let new_offset: i64 = match x.data.value().parse::<i64>() {
Ok(offset) => {
if dmw3_consts::MIN_STAT_RANGE <= offset && offset <= dmw3_consts::MAX_STAT_RANGE {
if (dmw3_consts::MIN_STAT_RANGE..=dmw3_consts::MAX_STAT_RANGE).contains(&offset) {
offset
} else {
scaling_offset
Expand Down
6 changes: 1 addition & 5 deletions src/gui/shops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use dioxus::prelude::*;

use crate::gui::{number_field, GlobalState};
use crate::json::{Preset, ShopItems};
use dmw3_consts;

use crate::gui::checkbox;

Expand All @@ -19,10 +18,7 @@ pub fn shops() -> Element {
let enabled = read_preset_state.randomizer.shops.enabled;
let selected = read_preset_state.randomizer.shops.items_only.clone();

let limit = match read_preset_state.randomizer.shops.limit_shop_items {
Some(lm) => lm,
None => 64,
};
let limit = read_preset_state.randomizer.shops.limit_shop_items.unwrap_or(64);

let sell_price = read_preset_state.randomizer.shops.sell_price;
let min_sell_price = read_preset_state.randomizer.shops.min_sell_price;
Expand Down
14 changes: 4 additions & 10 deletions src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,11 @@ fn default_max_starting_mp() -> u8 {

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
#[serde(rename_all = "lowercase")]
#[derive(Default)]
pub enum TNTStrategy {
Shuffle,
Keep,
#[default]
Swap,
}

Expand All @@ -318,16 +320,13 @@ impl From<u8> for TNTStrategy {
}
}

impl Default for TNTStrategy {
fn default() -> Self {
TNTStrategy::Swap
}
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
#[serde(rename_all = "lowercase")]
#[derive(Default)]
pub enum ShopItems {
Buyable,
#[default]
Sellable,
}

Expand All @@ -340,11 +339,6 @@ impl From<u8> for ShopItems {
}
}

impl Default for ShopItems {
fn default() -> Self {
ShopItems::Sellable
}
}

pub fn load_preset(path: &Option<std::path::PathBuf>) -> Box<Preset> {
match path {
Expand Down
12 changes: 6 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ fn main() {
rt.block_on(async {
if let Some(path) = &args.path {
if args.dump {
if !mkpsxiso::extract(&path).await {
if !mkpsxiso::extract(path).await {
panic!("Error extracting");
}

dump::dump(&path).await;
dump::dump(path).await;

return ();

}
}
});
Expand All @@ -44,14 +44,14 @@ fn main() {

let file_name = match args.output {
Some(name) => name,
None => String::from(format!("{}", preset.randomizer.seed)),
None => format!("{}", preset.randomizer.seed),
};

if !mkpsxiso::extract(&path).await {
if !mkpsxiso::extract(path).await {
panic!("Error extracting");
}

patch(&path, &preset).await;
patch(path, &preset).await;

if !mkpsxiso::build(&file_name).await {
panic!("Error repacking")
Expand Down
5 changes: 2 additions & 3 deletions src/mkpsxiso.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use async_std::fs;
use quick_xml;
use quick_xml::de::from_str;
use serde::Deserialize;
use tokio::process::Command;
Expand All @@ -24,7 +23,7 @@ impl IsoProject {
}
}

return result;
result
}
}

Expand Down Expand Up @@ -122,7 +121,7 @@ pub async fn extract(path: &std::path::PathBuf) -> bool {
.arg("-s")
.arg("extract/out.xml")
.arg("-pt")
.arg(&path)
.arg(path)
.output()
.await
.unwrap()
Expand Down
12 changes: 6 additions & 6 deletions src/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ impl From<Vec<u8>> for Packed {
}
}

impl Into<Vec<u8>> for Packed {
fn into(self) -> Vec<u8> {
impl From<Packed> for Vec<u8> {
fn from(val: Packed) -> Self {
let mut result = Vec::new();
let mut i: u32 = (self.files.len() * 4) as u32 + 4;
let mut i: u32 = (val.files.len() * 4) as u32 + 4;

(self.files.len() as u32).write(&mut result).unwrap();
(val.files.len() as u32).write(&mut result).unwrap();

for file in &self.files {
for file in &val.files {
i.write(&mut result).unwrap();
i += file.len() as u32;
}

for file in self.files {
for file in val.files {
result.extend(file);
}

Expand Down
Loading

0 comments on commit dec2883

Please sign in to comment.