Skip to content

Commit

Permalink
Apply clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
iMilchshake committed Apr 26, 2024
1 parent 8ec09a3 commit c78e004
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 45 deletions.
18 changes: 9 additions & 9 deletions src/bin/ddnet_bridge.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::Parser;
use core::net::{IpAddr, Ipv4Addr, SocketAddr};
use gores_mapgen_rust::random::{Random, Seed};
use gores_mapgen_rust::random::Seed;
use gores_mapgen_rust::{config::GenerationConfig, generator::Generator};
use std::collections::HashMap;

Expand Down Expand Up @@ -45,7 +45,7 @@ struct BridgeArgs {

#[derive(Debug)]
struct Vote {
player_name: String,
_player_name: String,
vote_name: String,
vote_reason: String,
}
Expand Down Expand Up @@ -96,7 +96,7 @@ impl Econ {
if vote.vote_name.starts_with("generate") {
let seed = if vote.vote_reason == "No reason given" {
Seed::random()
} else if let Some(seed_u64) = vote.vote_reason.parse::<u64>().ok() {
} else if let Ok(seed_u64) = vote.vote_reason.parse::<u64>() {
Seed::from_u64(seed_u64)
} else {
Seed::from_string(&vote.vote_reason)
Expand All @@ -107,7 +107,7 @@ impl Econ {
let vote_type = vote_parts.next().expect("should have exactly two parts");
assert_eq!(vote_type, "generate");
let vote_preset = vote_parts.next().expect("should have exactly two parts");
assert!(vote_parts.next() == None, "should have exactly two parts");
assert!(vote_parts.next().is_none(), "should have exactly two parts");

// get config based on preset name
let config = configs.get(vote_preset).expect("preset does not exist!");
Expand All @@ -126,7 +126,7 @@ fn generate_and_change_map(
println!("[GEN] Starting Map Generation!");
econ.send_rcon_cmd(format!("say [GEN] Generating Map, seed={:?}", &seed));
let map_path = args.maps.canonicalize().unwrap().join("random_map.map");
match Generator::generate_map(30_000, &seed, config) {
match Generator::generate_map(30_000, seed, config) {
Ok(map) => {
println!("[GEN] Finished Map Generation!");
map.export(&map_path);
Expand All @@ -138,7 +138,7 @@ fn generate_and_change_map(
Err(err) => {
println!("[GEN] Generation Error: {:?}", err);
econ.send_rcon_cmd(format!("say [GEN] Failed due to: {:}", err));
econ.send_rcon_cmd(format!("say just try again :)"));
econ.send_rcon_cmd("say just try again :)".to_string());
}
}
}
Expand All @@ -165,7 +165,7 @@ fn start_bridge(args: &BridgeArgs) {
println!("[GEN] Generating initial map");
auth = true;
generate_and_change_map(
&args,
args,
&Seed::from_u64(42),
&GenerationConfig::default(),
&mut econ,
Expand All @@ -185,7 +185,7 @@ fn start_bridge(args: &BridgeArgs) {
match message {
"Vote passed" => {
println!("[VOTE]: Success");
econ.handle_vote(pending_vote.as_ref().unwrap(), &args, &configs);
econ.handle_vote(pending_vote.as_ref().unwrap(), args, &configs);
}
"Vote failed" => {
pending_vote = None;
Expand All @@ -203,7 +203,7 @@ fn start_bridge(args: &BridgeArgs) {
);

pending_vote = Some(Vote {
player_name,
_player_name: player_name,
vote_name,
vote_reason,
});
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl GenerationConfig {
for file_name in GenerationConfigStorage::iter() {
let file = GenerationConfigStorage::get(&file_name).unwrap();
let data = std::str::from_utf8(&file.data).unwrap();
let config: GenerationConfig = serde_json::from_str(&data).unwrap();
let config: GenerationConfig = serde_json::from_str(data).unwrap();
configs.insert(config.name.clone(), config);
}

Expand Down
4 changes: 2 additions & 2 deletions src/editor.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::collections::HashMap;
use std::{env, isize};

use egui::{ComboBox, InnerResponse, RichText};
use egui::{InnerResponse, RichText};
use tinyfiledialogs;

const STEPS_PER_FRAME: usize = 50;

use crate::random::Seed;
use crate::{
config::GenerationConfig, generator::Generator, map::Map, position::Position, random::Random,
config::GenerationConfig, generator::Generator, map::Map, position::Position,
};
use egui::{epaint::Shadow, CollapsingHeader, Color32, Frame, Label, Margin, Ui};

Expand Down
10 changes: 5 additions & 5 deletions src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::{
walker::CuteWalker,
};

use dt::{dt, dt_bool, dt_int};
use ndarray::{arr2, s, Array, Array2, Ix2, IxDyn};
use dt::{dt_bool};
use ndarray::{Array2, Ix2};

pub struct Generator {
pub walker: CuteWalker,
Expand Down Expand Up @@ -37,7 +37,7 @@ impl Generator {

if !self.walker.finished {
// randomly mutate kernel
self.walker.mutate_kernel(&config, &mut self.rnd);
self.walker.mutate_kernel(config, &mut self.rnd);

// perform one step
self.walker
Expand Down Expand Up @@ -137,13 +137,13 @@ impl Generator {
seed: &Seed,
config: &GenerationConfig,
) -> Result<Map, &'static str> {
let mut gen = Generator::new(&config, seed.clone());
let mut gen = Generator::new(config, seed.clone());

for _ in 0..max_steps {
if gen.walker.finished {
break;
}
gen.step(&config)?;
gen.step(config)?;
}

gen.post_processing(config);
Expand Down
4 changes: 2 additions & 2 deletions src/grid_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn draw_chunked_grid(
for x in x_start..x_end {
for y in y_start..y_end {
let value = &grid[[x, y]];
draw_rectangle(x as f32, y as f32, 1.0, 1.0, blocktype_to_color(&value));
draw_rectangle(x as f32, y as f32, 1.0, 1.0, blocktype_to_color(value));
}
}
} else {
Expand Down Expand Up @@ -118,7 +118,7 @@ pub fn draw_walker_kernel(walker: &CuteWalker, kernel_type: KernelType) {
}
}

pub fn draw_waypoints(waypoints: &Vec<Position>) {
pub fn draw_waypoints(waypoints: &[Position]) {
for pos in waypoints.iter() {
draw_circle(pos.x as f32 + 0.5, pos.y as f32 + 0.5, 1.0, colors::RED)
}
Expand Down
19 changes: 8 additions & 11 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ impl BlockType {
}

pub fn is_hookable(&self) -> bool {
match self {
BlockType::Hookable | BlockType::Platform => true,
_ => false,
}
matches!(self, BlockType::Hookable | BlockType::Platform)
}
}

Expand Down Expand Up @@ -196,7 +193,7 @@ impl Map {
}

pub fn export(&self, path: &PathBuf) {
TwExport::export(&self, &path)
TwExport::export(self, path)
}

pub fn pos_in_bounds(&self, pos: &Position) -> bool {
Expand All @@ -210,7 +207,7 @@ impl Map {
bot_right: &Position,
value: &BlockType,
) -> Result<bool, &'static str> {
if !self.pos_in_bounds(&top_left) || !self.pos_in_bounds(&bot_right) {
if !self.pos_in_bounds(top_left) || !self.pos_in_bounds(bot_right) {
return Err("checking area out of bounds");
}

Expand All @@ -227,7 +224,7 @@ impl Map {
bot_right: &Position,
value: &BlockType,
) -> Result<bool, &'static str> {
if !self.pos_in_bounds(&top_left) || !self.pos_in_bounds(&bot_right) {
if !self.pos_in_bounds(top_left) || !self.pos_in_bounds(bot_right) {
return Err("checking area out of bounds");
}
let area = self
Expand Down Expand Up @@ -279,9 +276,9 @@ impl Map {
let top_right = Position::new(bot_right.x, top_left.y);
let bot_left = Position::new(top_left.x, bot_right.y);

self.set_area(&top_left, &top_right, value, overide);
self.set_area(&top_right, &bot_right, value, overide);
self.set_area(&top_left, &bot_left, value, overide);
self.set_area(&bot_left, &bot_right, value, overide);
self.set_area(top_left, &top_right, value, overide);
self.set_area(&top_right, bot_right, value, overide);
self.set_area(top_left, &bot_left, value, overide);
self.set_area(&bot_left, bot_right, value, overide);
}
}
3 changes: 1 addition & 2 deletions src/position.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use rand_distr::num_traits::CheckedSub;
use serde::{Deserialize, Serialize};

use crate::map::Map;
Expand Down Expand Up @@ -57,7 +56,7 @@ impl Position {
shift: &ShiftDirection,
map: &Map,
) -> Result<(), &'static str> {
if !self.is_shift_valid(&shift, map) {
if !self.is_shift_valid(shift, map) {
return Err("invalid shift");
}

Expand Down
4 changes: 2 additions & 2 deletions src/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Seed {

pub fn from_string(seed_str: &String) -> Seed {
Seed {
seed_u64: Seed::str_to_u64(&seed_str),
seed_u64: Seed::str_to_u64(seed_str),
seed_str: seed_str.to_owned(),
}
}
Expand Down Expand Up @@ -112,7 +112,7 @@ impl Random {
self.gen.next_u64();
}

pub fn pick_element<'a, T>(&'a mut self, values: &'a Vec<T>) -> &T {
pub fn pick_element<'a, T>(&'a mut self, values: &'a [T]) -> &T {
&values[self.in_range_exclusive(0, values.len())]
}

Expand Down
14 changes: 7 additions & 7 deletions src/twmap_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl AutoMapperConfigs {
.expect("automapper rule config not found");
let data = std::str::from_utf8(&file.data).unwrap();

Automapper::parse(name, &data).expect("failed to parse .rules file")
Automapper::parse(name, data).expect("failed to parse .rules file")
}
}

Expand Down Expand Up @@ -51,13 +51,13 @@ impl TwExport {
assert_eq!(layer.name, layer_name);

let image_name = tw_map.images[layer.image.unwrap() as usize].name();
let automapper_config = TwExport::get_automapper_config(image_name.clone(), &layer);
let automapper_config = TwExport::get_automapper_config(image_name.clone(), layer);

let tiles = layer.tiles_mut().unwrap_mut();
*tiles = Array2::<Tile>::default((map.width, map.height));

for ((x, y), value) in map.grid.indexed_iter() {
if block_type_in_layer(&value) {
if block_type_in_layer(value) {
tiles[[y, x]] = Tile::new(1, TileFlags::empty())
}
}
Expand All @@ -72,10 +72,10 @@ impl TwExport {
let mut tw_map = TwMap::parse_file("automap_test.map").expect("parsing failed");
tw_map.load().expect("loading failed");

TwExport::process_layer(&mut tw_map, &map, &0, "Freeze", |t| {
(*t == BlockType::Freeze) || BlockType::is_hookable(&t)
TwExport::process_layer(&mut tw_map, map, &0, "Freeze", |t| {
(*t == BlockType::Freeze) || BlockType::is_hookable(t)
});
TwExport::process_layer(&mut tw_map, &map, &1, "Hookable", BlockType::is_hookable);
TwExport::process_layer(&mut tw_map, map, &1, "Hookable", BlockType::is_hookable);

// get game layer
let game_layer = tw_map
Expand All @@ -96,6 +96,6 @@ impl TwExport {

// save map
println!("exporting map to {:?}", &path);
tw_map.save_file(&path).expect("failed to write map file");
tw_map.save_file(path).expect("failed to write map file");
}
}
8 changes: 4 additions & 4 deletions src/walker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl CuteWalker {
let mut sampled_shift = &rnd.sample_move(&shifts);

// with a certain probabiliy re-use last direction instead
if rnd.with_probability(config.momentum_prob) && !self.last_direction.is_none() {
if rnd.with_probability(config.momentum_prob) && self.last_direction.is_some() {
sampled_shift = self.last_direction.as_ref().unwrap();
}

Expand Down Expand Up @@ -167,15 +167,15 @@ impl CuteWalker {
}

if rnd.with_probability(config.inner_rad_mut_prob) {
inner_circ = *rnd.pick_element(&vec![0.0, 0.1, 0.2, 0.6, 0.8]); // TODO: also, this is
// terrible
inner_circ = *rnd.pick_element(&[0.0, 0.1, 0.2, 0.6, 0.8]); // TODO: also, this is
// terrible
modified = true;
} else {
rnd.skip();
}

if rnd.with_probability(config.outer_rad_mut_prob) {
outer_circ = *rnd.pick_element(&vec![0.0, 0.1, 0.2, 0.6, 0.8]);
outer_circ = *rnd.pick_element(&[0.0, 0.1, 0.2, 0.6, 0.8]);
modified = true;
} else {
rnd.skip();
Expand Down

0 comments on commit c78e004

Please sign in to comment.