From 56f0a1b385387b12c1f28ea3d3ae04f13a9a93e1 Mon Sep 17 00:00:00 2001 From: Ross Andrews Date: Tue, 11 Aug 2026 23:41:02 -0500 Subject: [PATCH] clippy --- kiln-core/src/action.rs | 5 ++--- kiln-core/src/api/board.rs | 2 +- kiln-core/src/api/object_info.rs | 5 ++--- kiln-core/src/board.rs | 11 ++++------- kiln-core/src/board_spec.rs | 5 ++--- kiln-core/src/game.rs | 3 +-- kiln-core/src/script.rs | 5 ++--- kiln-core/src/tile.rs | 19 +++++-------------- kiln-core/src/utils.rs | 16 ++++++++++------ kiln-core/src/world.rs | 2 +- 10 files changed, 30 insertions(+), 43 deletions(-) diff --git a/kiln-core/src/action.rs b/kiln-core/src/action.rs index 584f922..0c8ec84 100644 --- a/kiln-core/src/action.rs +++ b/kiln-core/src/action.rs @@ -170,11 +170,10 @@ pub fn apply_teleport(board: &mut Board, target: i64, x: i64, y: i64) -> Result< let (x, y) = (x as usize, y as usize); let from = if target == -1 { Some(board.player_pos()) - } else if let Some(obj) = board.get_hookable(target as ObjectId) { - Some(obj.location().into()) } else { - None + board.get_hookable(target as ObjectId).map(|o| o.location()) }; + if let Some(from) = from { // Check if we're blocked: if (from.ux() != x || from.uy() != y) && board.get((x, y)).is_none() { diff --git a/kiln-core/src/api/board.rs b/kiln-core/src/api/board.rs index cc599e5..72701bc 100644 --- a/kiln-core/src/api/board.rs +++ b/kiln-core/src/api/board.rs @@ -14,7 +14,7 @@ use std::cell::RefCell; use std::rc::Rc; use rhai::{Dynamic, Engine, ImmutableString}; -use crate::{Board, Direction}; +use crate::Board; use crate::api::object_info::ObjectInfo; use crate::api::registry::Registry; use crate::script::Registerable; diff --git a/kiln-core/src/api/object_info.rs b/kiln-core/src/api/object_info.rs index 5a98349..39c2187 100644 --- a/kiln-core/src/api/object_info.rs +++ b/kiln-core/src/api/object_info.rs @@ -25,11 +25,10 @@ use rhai::{Dynamic, Engine}; use crate::api::board::BoardRef; use crate::api::queue::ObjQueue; -use crate::{Board, Direction}; +use crate::Direction; use crate::action::BoardAction; -use crate::object_def::ObjectDef; use crate::script::Registerable; -use crate::tile::{Hookable, Optics, ScriptAttributes, ScriptKey, Tile}; +use crate::tile::{Hookable, ScriptKey}; use crate::utils::{LogSink, ObjectId, Point}; /// A snapshot of one board object, returned by `Board.tagged`, `Board.named`, diff --git a/kiln-core/src/board.rs b/kiln-core/src/board.rs index cf598b4..d34c631 100644 --- a/kiln-core/src/board.rs +++ b/kiln-core/src/board.rs @@ -1,7 +1,6 @@ use crate::floor::Floor; use crate::fov::{color_to_rgb, FovCaster, Lighting}; use crate::glyph::Glyph; -use crate::log::LogLine; use crate::utils::{Direction, Point}; use crate::utils::{ObjectId, RegistryValue}; use std::collections::{HashMap, HashSet}; @@ -147,9 +146,7 @@ impl Board { } // Otherwise the floor, or the canonical black empty cell. - self.floor - .glyph_at(p, self.width) - .unwrap_or_else(|| Glyph::transparent()) + self.floor.glyph_at(p, self.width).unwrap_or_else(Glyph::transparent) } /// Returns `true` if `(x, y)` is a valid cell coordinate on this board. @@ -306,7 +303,7 @@ impl Board { // Find which ones are blockers let mut immobile = HashSet::new(); for (curr_idx, curr) in solids.iter().enumerate() { - let pushable = curr.as_ref().map_or(true, |c| c.shiftable()); + let pushable = curr.as_ref().is_none_or(Tile::shiftable); if !pushable { immobile.insert(curr_idx); } @@ -438,7 +435,7 @@ impl Board { } // Sort by id - hookables.sort_by(|a, b| a.id().cmp(&b.id())); + hookables.sort_by_key(|a| a.id()); hookables } @@ -455,7 +452,7 @@ impl Board { } pub fn move_sensor(&mut self, id: ObjectId, dir: Direction) { - if let Some((sensor_idx, _)) = self.sensors.iter().enumerate().find(|(idx, s)| s.scripting.id == id) { + if let Some(sensor_idx) = self.sensors.iter().position(|s| s.scripting.id == id) { let new_loc = self.sensors[sensor_idx].location.in_dir(dir); if self.in_bounds(new_loc) { self.sensors[sensor_idx].location = new_loc diff --git a/kiln-core/src/board_spec.rs b/kiln-core/src/board_spec.rs index 346aa35..cea0b58 100644 --- a/kiln-core/src/board_spec.rs +++ b/kiln-core/src/board_spec.rs @@ -11,7 +11,6 @@ //! player) for the map loader to resolve. Cross-cell validation (one solid per //! cell, unique names, the player winning its cell) lives in [`crate::map_file`]. -use crate::log::LogLine; use serde::{Deserialize, Serialize}; use std::collections::{HashMap, HashSet}; use std::hash::Hash; @@ -116,7 +115,7 @@ impl BoardSpec { } /// Try to check for validity of the board, return a list of errors we find (if any) - pub fn validate(&self, grid: &Vec>, valid_script_names: &HashSet<&String>) -> Result<(), Vec> { + pub fn validate(&self, grid: &[Option], valid_script_names: &HashSet<&String>) -> Result<(), Vec> { let mut errors = vec![]; // Check for player being positioned exactly once @@ -188,7 +187,7 @@ impl BoardSpec { } // Check for objects using scripts that don't exist - let missing = obj_script_names.difference(&valid_script_names).collect::>(); + let missing = obj_script_names.difference(valid_script_names).collect::>(); if !missing.is_empty() { errors.push(format!("Missing scripts: {missing:?}")); } diff --git a/kiln-core/src/game.rs b/kiln-core/src/game.rs index 07f1a64..08dc188 100644 --- a/kiln-core/src/game.rs +++ b/kiln-core/src/game.rs @@ -5,7 +5,6 @@ use crate::script::ScriptHost; use crate::utils::{Direction, ObjectId, Point}; use crate::world::World; use std::cell::{Ref, RefMut}; -use std::hash::Hash; use std::time::Duration; /// How long a `say()` speech bubble stays on screen, in seconds. @@ -389,7 +388,7 @@ impl GameState { fn resolve_move>(&mut self, from: P, dir: Direction) -> bool { let from = from.into(); // Get the target coords, if they're out of bounds then the move fails. - let target: Point = dir.from_point(from).into(); + let target: Point = dir.from_point(from); if !self.board().in_bounds(target) { return false; } if self.board().is_empty(target) { diff --git a/kiln-core/src/script.rs b/kiln-core/src/script.rs index e88fd6c..1d91deb 100644 --- a/kiln-core/src/script.rs +++ b/kiln-core/src/script.rs @@ -34,7 +34,6 @@ use crate::action::{Action, BoardAction, ScrollLine, SendArg, MOVE_COST}; use crate::game::SAY_DURATION; use crate::log::LogLine; -use crate::object_def::ObjectDef; use crate::utils::{Direction, LogSink, Hook, ObjectId, Point}; use rhai::{ Array, CallFnOptions, Dynamic, Engine, ImmutableString, Module, NativeCallContext, @@ -133,7 +132,7 @@ impl ScriptHost { continue; } - match script_key.source(&script_sources) { + match script_key.source(script_sources) { Ok(None) => { continue } // This has no source... Err(e) => { // Couldn't find it failed.insert(script_key.clone()); @@ -279,7 +278,7 @@ impl ScriptHost { /// the same send, we could fail to terminate. The only way to cut that loop would be to drop /// a send action we've already seen this tick. pub(crate) fn run_send(&mut self, id: ObjectId, fn_name: &str, arg: SendArg) { - if let Some(mut info) = ObjectInfo::from_id(id, self.board.clone()) { + if let Some(info) = ObjectInfo::from_id(id, self.board.clone()) { if let Some(script) = self.scripts.get(&info.script_key) && let Some(scope) = self.scopes.get_mut(&id) { diff --git a/kiln-core/src/tile.rs b/kiln-core/src/tile.rs index a741631..2939935 100644 --- a/kiln-core/src/tile.rs +++ b/kiln-core/src/tile.rs @@ -18,7 +18,7 @@ use crate::utils::{ObjectId, Point}; pub enum DrawLayer { Above, Below } /// How a thing interacts with the lighting and visibility models -#[derive(Serialize, Deserialize, PartialEq, Copy, Clone, Debug)] +#[derive(Serialize, Deserialize, PartialEq, Copy, Clone, Debug, Default)] #[serde(rename = "lowercase")] pub struct Optics { /// Opaque things block field of view @@ -36,15 +36,6 @@ pub struct Optics { pub glow: u32, } -impl Default for Optics { - fn default() -> Self { - Self { - opaque: false, - glow: 0, - } - } -} - const fn default_as_true() -> bool { true } @@ -66,7 +57,7 @@ impl ScriptKey { match self { ScriptKey::None => "", ScriptKey::World(name) => name.as_str(), - ScriptKey::Builtin(name) => *name + ScriptKey::Builtin(name) => name } } @@ -87,7 +78,7 @@ impl ScriptKey { impl From> for ScriptKey { fn from(s: Option) -> Self { - s.map_or(Self::None, |s| Self::World(s)) + s.map_or(Self::None, Self::World) } } @@ -318,7 +309,7 @@ impl IntoTile for TileSpec { queue: ObjQueue::new(), } }; - *next_object_id = *next_object_id + 1; + *next_object_id += 1; Ok(Tile::Object(Box::new(def))) }, @@ -336,7 +327,7 @@ impl IntoTile for TileSpec { queue: ObjQueue::new(), } }; - *next_object_id = *next_object_id + 1; + *next_object_id += 1; Ok(Tile::Object(Box::new(def))) } else { Err(format!("Unknown builtin kind {}", kind)) diff --git a/kiln-core/src/utils.rs b/kiln-core/src/utils.rs index b67b404..b2e10a2 100644 --- a/kiln-core/src/utils.rs +++ b/kiln-core/src/utils.rs @@ -101,7 +101,7 @@ impl Registerable for Direction { fn register(engine: &mut Engine, _log_sink: LogSink) { engine.register_type_with_name::("Direction") .register_get("opposite", |dir: &mut Direction| dir.opposite()) - .register_fn("from_point", |dir: &mut Direction, x: i64, y: i64| Point::from(dir.from_point((x, y)))) + .register_fn("from_point", |dir: &mut Direction, x: i64, y: i64| dir.from_point((x, y))) // The Point overload, so a script can walk a coordinate along an axis // (`p = d.from_point(p)`) without unpacking it into two ints. .register_fn("from_point", |dir: &mut Direction, p: Point| dir.from_point(p)); @@ -126,12 +126,16 @@ impl From<(i32, i32)> for Point { fn from((x, y): (i32, i32)) -> Self { Self { x: x as i64, y: y as i64 } } } -impl Into<(i64, i64)> for Point { - fn into(self) -> (i64, i64) { (self.x, self.y) } +impl From for (i64, i64) { + fn from(p: Point) -> Self { (p.x, p.y) } } -impl Into<(usize, usize)> for Point { - fn into(self) -> (usize, usize) { (self.x as usize, self.y as usize) } +impl From for (usize, usize) { + fn from(p: Point) -> Self { (p.x as usize, p.y as usize) } +} + +impl From for (i32, i32) { + fn from(p: Point) -> Self { (p.x as i32, p.y as i32) } } impl Display for Point { @@ -144,7 +148,7 @@ impl Point { pub fn ux(&self) -> usize { self.x as usize } pub fn uy(&self) -> usize { self.y as usize } pub fn in_dir(self, dir: Direction) -> Self { - dir.from_point(self).into() + dir.from_point(self) } } diff --git a/kiln-core/src/world.rs b/kiln-core/src/world.rs index 8eecb6d..fba8a8a 100644 --- a/kiln-core/src/world.rs +++ b/kiln-core/src/world.rs @@ -144,7 +144,7 @@ mod tests { /// original board untouched (the property the editor's playtest relies on). #[test] fn deep_clone_isolates_boards() { - let mut board = open_board(3, 1, (0, 0)); + let board = open_board(3, 1, (0, 0)); let mut boards = HashMap::new(); boards.insert("start".to_string(), Rc::new(RefCell::new(board))); let world = World {