wip 3 hvcrate

This commit is contained in:
2026-08-11 01:13:04 -05:00
parent 38c58a2c5f
commit 1872db340c
4 changed files with 29 additions and 9 deletions
+4 -6
View File
@@ -640,8 +640,7 @@ pub(crate) mod tests {
/// (or must share a cell) has to live off-grid in [`Board::sensors`].
pub(crate) fn sensor_at(board: &mut Board, x: usize, y: usize, script: &str) -> ObjectId {
let sensor = SensorSpec {
x,
y,
location: (x, y).into(),
script: Some(script.to_string()),
glyph: Glyph::transparent(),
optics: Optics::default(),
@@ -662,8 +661,7 @@ pub(crate) mod tests {
pub(crate) fn lamp_at(board: &mut Board, x: usize, y: usize) {
let lamp = Sensor {
x,
y,
location: (x, y).into(),
draw_layer: DrawLayer::Above,
scripting: ScriptAttributes {
id: board.next_object_id,
@@ -798,7 +796,7 @@ pub(crate) mod tests {
// apply_shift validates all cells upfront; any out-of-bounds cell causes immediate failure.
let mut board = open_board(3, 1, (2, 0));
crate_at(&mut board, 0, 0);
let errs = board.apply_shift(&[(0, 0), (9, 0)]);
let errs = board.apply_shift(&[(0, 0).into(), (9, 0).into()]);
assert!(errs.is_err());
assert!(is_builtin(&board, 0, 0, "crate")); // unchanged
}
@@ -822,7 +820,7 @@ pub(crate) mod tests {
// blocked = {2}; Crate at (0,0) is NOT blocked
// Result: Crate(0,0)→(1,0), empty→no-op, Wall stays at (2,0),
// Crate(3,0)→(4,0), Crate(4,0)→(0,0) wrap
let _errs = board.apply_shift(&[(0, 0), (1, 0), (2, 0), (3, 0), (4, 0)]);
let _errs = board.apply_shift(&[(0, 0), (1, 0), (2, 0), (3, 0), (4, 0)].map(Into::into));
assert!(is_builtin(&board, 0, 0, "crate")); // wrapped from (4,0)
assert!(is_builtin(&board, 1, 0, "crate")); // moved from (0,0)
+5 -3
View File
@@ -177,17 +177,17 @@ builtins! {
//enter: EnterResponse::Push(Pushable::Any),
enter: EnterResponse::Block,
optics: Optics { opaque: true, glow: 0 },
script: ScriptKey::Builtin("crate"),
script: ScriptKey::Builtin("crate")
},
HCrate => ["hcrate" => g('↔', 0xaa, 0xaa, 0xaa)] { // CP437 ↔ (left-right arrow) — pushable east/west
enter: EnterResponse::Push(Pushable::Horizontal),
optics: Optics { opaque: true, glow: 0 },
script: ScriptKey::None
script: ScriptKey::Builtin("hcrate")
},
VCrate => ["vcrate" => g('↕', 0xaa, 0xaa, 0xaa)] { // CP437 ↕ (up-down arrow) — pushable north/south
enter: EnterResponse::Push(Pushable::Vertical),
optics: Optics { opaque: true, glow: 0 },
script: ScriptKey::None
script: ScriptKey::Builtin("vcrate")
},
}
@@ -201,6 +201,8 @@ lazy_static! {
m.insert(ScriptKey::Builtin("transporter"), include_str!("scripts/transporter.rhai"));
m.insert(ScriptKey::Builtin("key"), include_str!("scripts/key.rhai"));
m.insert(ScriptKey::Builtin("crate"), include_str!("scripts/crate.rhai"));
m.insert(ScriptKey::Builtin("hcrate"), include_str!("scripts/hcrate.rhai"));
m.insert(ScriptKey::Builtin("vcrate"), include_str!("scripts/vcrate.rhai"));
m
};
}
+10
View File
@@ -0,0 +1,10 @@
fn bump(me, dir) {
if dir == North || dir == South {
return;
}
push(me.x, me.y, dir.opposite); // Try to clear our target cell
let tgt = dir.opposite.from_point(me.x, me.y);
// This will silently-nop if tgt is occupied, and it will evaluate that after the push
// (queue both right now, evaluate in that order after)
teleport(me.id, tgt.x, tgt.y);
}
+10
View File
@@ -0,0 +1,10 @@
fn bump(me, dir) {
if dir == East || dir == West {
return;
}
push(me.x, me.y, dir.opposite); // Try to clear our target cell
let tgt = dir.opposite.from_point(me.x, me.y);
// This will silently-nop if tgt is occupied, and it will evaluate that after the push
// (queue both right now, evaluate in that order after)
teleport(me.id, tgt.x, tgt.y);
}