Fix clippy warnings: needless_range_loop, collapsible_if, borrowed_box, type_complexity, dead code cleanup

This commit is contained in:
loki5512344 2026-06-15 19:52:21 +02:00
parent fa05187f1c
commit 3d3798136d
22 changed files with 579 additions and 428 deletions

View file

@ -1,8 +1,8 @@
use std::collections::VecDeque;
use terrafier_core::World;
use terrafier_core::model::terrain::Terrain;
use terrafier_core::ops::operations::Operation;
use terrafier_core::World;
#[derive(Clone, Copy, PartialEq)]
pub enum ToolMode {
@ -41,8 +41,6 @@ pub struct TerrafierApp {
pub brush_local_x: Option<u32>,
pub brush_local_z: Option<u32>,
pub show_heightmap: bool,
pub zoom: f32,
pub view_offset: (f32, f32),
pub show_new_world: bool,
pub show_export: bool,
pub status_message: String,
@ -67,8 +65,6 @@ impl TerrafierApp {
brush_local_x: None,
brush_local_z: None,
show_heightmap: false,
zoom: 1.0,
view_offset: (0.0, 0.0),
show_new_world: false,
show_export: false,
status_message: "Ready".to_string(),
@ -129,19 +125,19 @@ impl eframe::App for TerrafierApp {
if ui.button("New World").clicked() {
self.show_new_world = true;
}
if ui.button("Open").clicked() {
if let Some(path) = rfd::FileDialog::new().pick_folder() {
match terrafier_core::io::import::import(&path) {
Ok(world) => {
self.world = Some(world);
self.selected_tile = None;
self.undo_stack.clear();
self.redo_stack.clear();
self.status_message = format!("Opened world from {}", path.display());
}
Err(e) => {
self.status_message = format!("Open error: {}", e);
}
if ui.button("Open").clicked()
&& let Some(path) = rfd::FileDialog::new().pick_folder()
{
match terrafier_core::io::import::import(&path) {
Ok(world) => {
self.world = Some(world);
self.selected_tile = None;
self.undo_stack.clear();
self.redo_stack.clear();
self.status_message = format!("Opened world from {}", path.display());
}
Err(e) => {
self.status_message = format!("Open error: {}", e);
}
}
}

View file

@ -1,12 +1,12 @@
use std::sync::Arc;
use terrafier_core::Terrain;
use terrafier_core::model::brush::SymmetricBrush;
use terrafier_core::model::tile::TILE_SIZE;
use terrafier_core::ops::operations::{
FlattenOperation, HeightOperation, MultiTileOperation, Operation, PaintOperation,
SmoothOperation,
};
use terrafier_core::Terrain;
use crate::app::{TerrafierApp, ToolMode};
@ -103,8 +103,10 @@ fn apply_tool(app: &mut TerrafierApp) {
for otx in min_tx..=max_tx {
for otz in min_tz..=max_tz {
let local_cx = (global_cx - otx * TILE_SIZE as i32).clamp(0, TILE_SIZE as i32 - 1) as u32;
let local_cz = (global_cz - otz * TILE_SIZE as i32).clamp(0, TILE_SIZE as i32 - 1) as u32;
let local_cx =
(global_cx - otx * TILE_SIZE as i32).clamp(0, TILE_SIZE as i32 - 1) as u32;
let local_cz =
(global_cz - otz * TILE_SIZE as i32).clamp(0, TILE_SIZE as i32 - 1) as u32;
if dim.tiles.contains_key(&(otx, otz)) {
let brush = Arc::new(SymmetricBrush::new(app.brush_radius as f64));

View file

@ -107,27 +107,34 @@ pub fn show_viewport(ui: &mut egui::Ui, app: &mut crate::app::TerrafierApp) {
);
// Draw selection border
if let Some((sel_tx, sel_tz)) = app.selected_tile {
if sel_tx >= min_tx && sel_tx <= max_tx && sel_tz >= min_tz && sel_tz <= max_tz {
let bx = rect.min.x + (sel_tx - min_tx) as f32 * display_size as f32;
let bz = rect.min.y + (sel_tz - min_tz) as f32 * display_size as f32;
let border_rect =
egui::Rect::from_min_size(egui::pos2(bx, bz), Vec2::splat(display_size as f32));
painter.rect_stroke(
border_rect,
0.0,
egui::Stroke::new(3.0, Color32::WHITE),
egui::StrokeKind::Middle,
);
}
if let Some((sel_tx, sel_tz)) = app.selected_tile
&& sel_tx >= min_tx
&& sel_tx <= max_tx
&& sel_tz >= min_tz
&& sel_tz <= max_tz
{
let bx = rect.min.x + (sel_tx - min_tx) as f32 * display_size as f32;
let bz = rect.min.y + (sel_tz - min_tz) as f32 * display_size as f32;
let border_rect =
egui::Rect::from_min_size(egui::pos2(bx, bz), Vec2::splat(display_size as f32));
painter.rect_stroke(
border_rect,
0.0,
egui::Stroke::new(3.0, Color32::WHITE),
egui::StrokeKind::Middle,
);
}
// Draw brush position marker
if let (Some((sel_tx, sel_tz)), Some(bx), Some(bz)) = (app.selected_tile, app.brush_local_x, app.brush_local_z) {
if let (Some((sel_tx, sel_tz)), Some(bx), Some(bz)) =
(app.selected_tile, app.brush_local_x, app.brush_local_z)
{
let tile_x_in_pixels = (sel_tx - min_tx) as f32 * display_size as f32;
let tile_z_in_pixels = (sel_tz - min_tz) as f32 * display_size as f32;
let brush_x = rect.min.x + tile_x_in_pixels + (bx as f32 * display_size as f32 / TILE_SIZE as f32);
let brush_z = rect.min.y + tile_z_in_pixels + (bz as f32 * display_size as f32 / TILE_SIZE as f32);
let brush_x =
rect.min.x + tile_x_in_pixels + (bx as f32 * display_size as f32 / TILE_SIZE as f32);
let brush_z =
rect.min.y + tile_z_in_pixels + (bz as f32 * display_size as f32 / TILE_SIZE as f32);
let brush_radius_px = app.brush_radius as f32 * display_size as f32 / TILE_SIZE as f32;
painter.circle_stroke(
egui::pos2(brush_x, brush_z),
@ -137,21 +144,26 @@ pub fn show_viewport(ui: &mut egui::Ui, app: &mut crate::app::TerrafierApp) {
}
// Handle click to select tile
if response.clicked() {
if let Some(pos) = response.interact_pointer_pos() {
let lx = pos.x - rect.min.x;
let lz = pos.y - rect.min.y;
if lx >= 0.0 && lz >= 0.0 {
let tx = (lx / display_size as f32).floor() as i32 + min_tx;
let tz = (lz / display_size as f32).floor() as i32 + min_tz;
if dim.tiles.contains_key(&(tx, tz)) {
app.selected_tile = Some((tx, tz));
let local_x = ((lx as u32 % display_size) * TILE_SIZE as u32 / display_size).min(127);
let local_z = ((lz as u32 % display_size) * TILE_SIZE as u32 / display_size).min(127);
app.brush_local_x = Some(local_x);
app.brush_local_z = Some(local_z);
app.status_message = format!("Selected tile ({}, {}) at local ({}, {})", tx, tz, local_x, local_z);
}
if response.clicked()
&& let Some(pos) = response.interact_pointer_pos()
{
let lx = pos.x - rect.min.x;
let lz = pos.y - rect.min.y;
if lx >= 0.0 && lz >= 0.0 {
let tx = (lx / display_size as f32).floor() as i32 + min_tx;
let tz = (lz / display_size as f32).floor() as i32 + min_tz;
if dim.tiles.contains_key(&(tx, tz)) {
app.selected_tile = Some((tx, tz));
let local_x =
((lx as u32 % display_size) * TILE_SIZE as u32 / display_size).min(127);
let local_z =
((lz as u32 % display_size) * TILE_SIZE as u32 / display_size).min(127);
app.brush_local_x = Some(local_x);
app.brush_local_z = Some(local_z);
app.status_message = format!(
"Selected tile ({}, {}) at local ({}, {})",
tx, tz, local_x, local_z
);
}
}
}