diff --git a/kiln-core/src/action.rs b/kiln-core/src/action.rs index 4238452..81d4ffb 100644 --- a/kiln-core/src/action.rs +++ b/kiln-core/src/action.rs @@ -50,9 +50,9 @@ impl From for SendArg { } } -impl Into for SendArg { - fn into(self) -> Dynamic { - match self { +impl From for Dynamic { + fn from(val: SendArg) -> Self { + match val { SendArg::None => Dynamic::UNIT, SendArg::Int(value) => Dynamic::from(value), SendArg::Float(value) => Dynamic::from(value), @@ -240,13 +240,13 @@ pub(crate) fn action_to_map(action: &Action) -> rhai::Map { } Action::Teleport { x, y } => { m.insert("type".into(), ds("Teleport")); - m.insert("x".into(), Dynamic::from(*x as i64)); - m.insert("y".into(), Dynamic::from(*y as i64)); + m.insert("x".into(), Dynamic::from(*x)); + m.insert("y".into(), Dynamic::from(*y)); } Action::Push { x, y, dir } => { m.insert("type".into(), ds("Push")); - m.insert("x".into(), Dynamic::from(*x as i64)); - m.insert("y".into(), Dynamic::from(*y as i64)); + m.insert("x".into(), Dynamic::from(*x)); + m.insert("y".into(), Dynamic::from(*y)); m.insert("dir".into(), ds(dir_to_str(*dir))); } // Shift cells are not inspectable via the queue map API; emit type only. diff --git a/kiln-core/src/api/board.rs b/kiln-core/src/api/board.rs index 3c6fb57..ca9f15c 100644 --- a/kiln-core/src/api/board.rs +++ b/kiln-core/src/api/board.rs @@ -80,9 +80,7 @@ impl Registerable for BoardRef { engine.register_fn("tagged", move |board_ref: &mut BoardRef, tag: ImmutableString| -> rhai::Array { let board = board_ref.borrow(); board - .objects - .iter() - .filter_map(|(_id, def)| { + .objects.values().filter_map(|def| { if def.tags.contains(tag.as_str()) { Some(Dynamic::from(ObjectInfo::from_def(def, board_ref.clone()))) } else { diff --git a/kiln-core/src/board.rs b/kiln-core/src/board.rs index c2fc600..402b6f7 100644 --- a/kiln-core/src/board.rs +++ b/kiln-core/src/board.rs @@ -103,11 +103,10 @@ impl Board { /// Replace the solid (if any) at `(x, y)` with `Empty` pub fn clear_solid(&mut self, x: usize, y: usize) { - if self.in_bounds((x as i64, y as i64)) { - if let Some(z) = self.solid_cell_layer(x, y) { + if self.in_bounds((x as i64, y as i64)) + && let Some(z) = self.solid_cell_layer(x, y) { *self.get_mut(z, x, y) = (Archetype::Empty.default_glyph(), Archetype::Empty) } - } } /// Returns the glyph to display at `(x, y)`, honoring layer draw order. diff --git a/kiln-core/src/game.rs b/kiln-core/src/game.rs index 364c0fd..6515074 100644 --- a/kiln-core/src/game.rs +++ b/kiln-core/src/game.rs @@ -163,7 +163,7 @@ impl GameState { /// the game is about to start — never during map deserialization, since a script /// may inspect the board. pub fn run_init(&mut self) { - self.scripts.run_init(ScriptState::from_game_state(&self)); + self.scripts.run_init(ScriptState::from_game_state(self)); self.resolve(); } @@ -177,7 +177,7 @@ impl GameState { // this runs exactly once per player interaction with a scroll. self.handle_scroll(); let secs = dt.as_secs_f64(); - self.scripts.run_tick(ScriptState::from_game_state(&self), secs); + self.scripts.run_tick(ScriptState::from_game_state(self), secs); // Expire speech bubbles before resolving new actions so a fresh say() // this frame isn't immediately culled. self.speech_bubbles.retain_mut(|b| { @@ -370,7 +370,7 @@ impl GameState { if let Some(scroll) = self.active_scroll.take() && let Some(choice) = scroll.choice { - self.scripts.run_send(ScriptState::from_game_state(&self), scroll.source, &choice, SendArg::None); + self.scripts.run_send(ScriptState::from_game_state(self), scroll.source, &choice, SendArg::None); self.drain_errors(); } } @@ -437,7 +437,7 @@ impl GameState { { let (dx, dy): (i64, i64) = dir.into(); let mut board = self.board_mut(); - let target = (board.player.x as i64 + dx, board.player.y as i64 + dy); + let target = (board.player.x + dx, board.player.y + dy); if !board.in_bounds(target) { return; } @@ -476,7 +476,7 @@ impl GameState { } // Fire the grab hook and resolve it immediately so the grabbed thing's // die()/add_gems() apply now — no player+object overlap survives this call. - let state = ScriptState::from_game_state(&self); + let state = ScriptState::from_game_state(self); if let Some(id) = grabbed { self.scripts.run_grab(state.clone(), id); self.resolve(); diff --git a/kiln-core/src/script.rs b/kiln-core/src/script.rs index 96050a6..6baf48b 100644 --- a/kiln-core/src/script.rs +++ b/kiln-core/src/script.rs @@ -247,7 +247,7 @@ impl ScriptHost { Dynamic::from(info.clone()), Dynamic::from(state.clone()) ]; - arg.map(|d| args.push(d)); + if let Some(d) = arg { args.push(d) } // Call this with opts tagging this call as our id. The write API will read // that to find what queue to emit events to diff --git a/kiln-core/src/utils.rs b/kiln-core/src/utils.rs index 40642ea..0fdc11e 100644 --- a/kiln-core/src/utils.rs +++ b/kiln-core/src/utils.rs @@ -434,7 +434,7 @@ pub enum Hook { } impl Hook { - pub fn to_str(&self) -> &'static str { + pub fn to_str(self) -> &'static str { match self { Hook::Init => "init", Hook::Bump => "bump",