wip 3 hvcrate
This commit is contained in:
@@ -640,8 +640,7 @@ pub(crate) mod tests {
|
|||||||
/// (or must share a cell) has to live off-grid in [`Board::sensors`].
|
/// (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 {
|
pub(crate) fn sensor_at(board: &mut Board, x: usize, y: usize, script: &str) -> ObjectId {
|
||||||
let sensor = SensorSpec {
|
let sensor = SensorSpec {
|
||||||
x,
|
location: (x, y).into(),
|
||||||
y,
|
|
||||||
script: Some(script.to_string()),
|
script: Some(script.to_string()),
|
||||||
glyph: Glyph::transparent(),
|
glyph: Glyph::transparent(),
|
||||||
optics: Optics::default(),
|
optics: Optics::default(),
|
||||||
@@ -662,8 +661,7 @@ pub(crate) mod tests {
|
|||||||
|
|
||||||
pub(crate) fn lamp_at(board: &mut Board, x: usize, y: usize) {
|
pub(crate) fn lamp_at(board: &mut Board, x: usize, y: usize) {
|
||||||
let lamp = Sensor {
|
let lamp = Sensor {
|
||||||
x,
|
location: (x, y).into(),
|
||||||
y,
|
|
||||||
draw_layer: DrawLayer::Above,
|
draw_layer: DrawLayer::Above,
|
||||||
scripting: ScriptAttributes {
|
scripting: ScriptAttributes {
|
||||||
id: board.next_object_id,
|
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.
|
// apply_shift validates all cells upfront; any out-of-bounds cell causes immediate failure.
|
||||||
let mut board = open_board(3, 1, (2, 0));
|
let mut board = open_board(3, 1, (2, 0));
|
||||||
crate_at(&mut board, 0, 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!(errs.is_err());
|
||||||
assert!(is_builtin(&board, 0, 0, "crate")); // unchanged
|
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
|
// blocked = {2}; Crate at (0,0) is NOT blocked
|
||||||
// Result: Crate(0,0)→(1,0), empty→no-op, Wall stays at (2,0),
|
// 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
|
// 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, 0, 0, "crate")); // wrapped from (4,0)
|
||||||
assert!(is_builtin(&board, 1, 0, "crate")); // moved from (0,0)
|
assert!(is_builtin(&board, 1, 0, "crate")); // moved from (0,0)
|
||||||
|
|||||||
@@ -177,17 +177,17 @@ builtins! {
|
|||||||
//enter: EnterResponse::Push(Pushable::Any),
|
//enter: EnterResponse::Push(Pushable::Any),
|
||||||
enter: EnterResponse::Block,
|
enter: EnterResponse::Block,
|
||||||
optics: Optics { opaque: true, glow: 0 },
|
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
|
HCrate => ["hcrate" => g('↔', 0xaa, 0xaa, 0xaa)] { // CP437 ↔ (left-right arrow) — pushable east/west
|
||||||
enter: EnterResponse::Push(Pushable::Horizontal),
|
enter: EnterResponse::Push(Pushable::Horizontal),
|
||||||
optics: Optics { opaque: true, glow: 0 },
|
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
|
VCrate => ["vcrate" => g('↕', 0xaa, 0xaa, 0xaa)] { // CP437 ↕ (up-down arrow) — pushable north/south
|
||||||
enter: EnterResponse::Push(Pushable::Vertical),
|
enter: EnterResponse::Push(Pushable::Vertical),
|
||||||
optics: Optics { opaque: true, glow: 0 },
|
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("transporter"), include_str!("scripts/transporter.rhai"));
|
||||||
m.insert(ScriptKey::Builtin("key"), include_str!("scripts/key.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("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
|
m
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user