This commit is contained in:
2026-06-28 00:17:08 -05:00
parent 9de31d933b
commit 83409a5c25
6 changed files with 17 additions and 20 deletions
+7 -7
View File
@@ -50,9 +50,9 @@ impl From<Dynamic> for SendArg {
} }
} }
impl Into<Dynamic> for SendArg { impl From<SendArg> for Dynamic {
fn into(self) -> Dynamic { fn from(val: SendArg) -> Self {
match self { match val {
SendArg::None => Dynamic::UNIT, SendArg::None => Dynamic::UNIT,
SendArg::Int(value) => Dynamic::from(value), SendArg::Int(value) => Dynamic::from(value),
SendArg::Float(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 } => { Action::Teleport { x, y } => {
m.insert("type".into(), ds("Teleport")); m.insert("type".into(), ds("Teleport"));
m.insert("x".into(), Dynamic::from(*x as i64)); m.insert("x".into(), Dynamic::from(*x));
m.insert("y".into(), Dynamic::from(*y as i64)); m.insert("y".into(), Dynamic::from(*y));
} }
Action::Push { x, y, dir } => { Action::Push { x, y, dir } => {
m.insert("type".into(), ds("Push")); m.insert("type".into(), ds("Push"));
m.insert("x".into(), Dynamic::from(*x as i64)); m.insert("x".into(), Dynamic::from(*x));
m.insert("y".into(), Dynamic::from(*y as i64)); m.insert("y".into(), Dynamic::from(*y));
m.insert("dir".into(), ds(dir_to_str(*dir))); m.insert("dir".into(), ds(dir_to_str(*dir)));
} }
// Shift cells are not inspectable via the queue map API; emit type only. // Shift cells are not inspectable via the queue map API; emit type only.
+1 -3
View File
@@ -80,9 +80,7 @@ impl Registerable for BoardRef {
engine.register_fn("tagged", move |board_ref: &mut BoardRef, tag: ImmutableString| -> rhai::Array { engine.register_fn("tagged", move |board_ref: &mut BoardRef, tag: ImmutableString| -> rhai::Array {
let board = board_ref.borrow(); let board = board_ref.borrow();
board board
.objects .objects.values().filter_map(|def| {
.iter()
.filter_map(|(_id, def)| {
if def.tags.contains(tag.as_str()) { if def.tags.contains(tag.as_str()) {
Some(Dynamic::from(ObjectInfo::from_def(def, board_ref.clone()))) Some(Dynamic::from(ObjectInfo::from_def(def, board_ref.clone())))
} else { } else {
+2 -3
View File
@@ -103,11 +103,10 @@ impl Board {
/// Replace the solid (if any) at `(x, y)` with `Empty` /// Replace the solid (if any) at `(x, y)` with `Empty`
pub fn clear_solid(&mut self, x: usize, y: usize) { pub fn clear_solid(&mut self, x: usize, y: usize) {
if self.in_bounds((x as i64, y as i64)) { if self.in_bounds((x as i64, y as i64))
if let Some(z) = self.solid_cell_layer(x, y) { && let Some(z) = self.solid_cell_layer(x, y) {
*self.get_mut(z, x, y) = (Archetype::Empty.default_glyph(), Archetype::Empty) *self.get_mut(z, x, y) = (Archetype::Empty.default_glyph(), Archetype::Empty)
} }
}
} }
/// Returns the glyph to display at `(x, y)`, honoring layer draw order. /// Returns the glyph to display at `(x, y)`, honoring layer draw order.
+5 -5
View File
@@ -163,7 +163,7 @@ impl GameState {
/// the game is about to start — never during map deserialization, since a script /// the game is about to start — never during map deserialization, since a script
/// may inspect the board. /// may inspect the board.
pub fn run_init(&mut self) { 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(); self.resolve();
} }
@@ -177,7 +177,7 @@ impl GameState {
// this runs exactly once per player interaction with a scroll. // this runs exactly once per player interaction with a scroll.
self.handle_scroll(); self.handle_scroll();
let secs = dt.as_secs_f64(); 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() // Expire speech bubbles before resolving new actions so a fresh say()
// this frame isn't immediately culled. // this frame isn't immediately culled.
self.speech_bubbles.retain_mut(|b| { self.speech_bubbles.retain_mut(|b| {
@@ -370,7 +370,7 @@ impl GameState {
if let Some(scroll) = self.active_scroll.take() if let Some(scroll) = self.active_scroll.take()
&& let Some(choice) = scroll.choice && 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(); self.drain_errors();
} }
} }
@@ -437,7 +437,7 @@ impl GameState {
{ {
let (dx, dy): (i64, i64) = dir.into(); let (dx, dy): (i64, i64) = dir.into();
let mut board = self.board_mut(); 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) { if !board.in_bounds(target) {
return; return;
} }
@@ -476,7 +476,7 @@ impl GameState {
} }
// Fire the grab hook and resolve it immediately so the grabbed thing's // 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. // 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 { if let Some(id) = grabbed {
self.scripts.run_grab(state.clone(), id); self.scripts.run_grab(state.clone(), id);
self.resolve(); self.resolve();
+1 -1
View File
@@ -247,7 +247,7 @@ impl ScriptHost {
Dynamic::from(info.clone()), Dynamic::from(info.clone()),
Dynamic::from(state.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 // Call this with opts tagging this call as our id. The write API will read
// that to find what queue to emit events to // that to find what queue to emit events to
+1 -1
View File
@@ -434,7 +434,7 @@ pub enum Hook {
} }
impl Hook { impl Hook {
pub fn to_str(&self) -> &'static str { pub fn to_str(self) -> &'static str {
match self { match self {
Hook::Init => "init", Hook::Init => "init",
Hook::Bump => "bump", Hook::Bump => "bump",