no need for scriptstate any more
This commit is contained in:
@@ -8,7 +8,7 @@ use std::time::Duration;
|
||||
fn move_command_relocates_the_source_object() {
|
||||
let board = open_board(5, 3, (0, 0), vec![scripted_object(2, 1, "m")]);
|
||||
let mut game =
|
||||
GameState::with_scripts(board, scripts_from(&[("m", "fn init(m,s) { move(East); }")]));
|
||||
GameState::with_scripts(board, scripts_from(&[("m", "fn init(m) { move(East); }")]));
|
||||
game.run_init();
|
||||
let b = game.board();
|
||||
// East increments x by one; the object started at (2, 1).
|
||||
@@ -20,7 +20,7 @@ fn move_into_a_wall_or_edge_is_a_noop() {
|
||||
// Object at the west edge moving west: out of bounds, ignored.
|
||||
let board = open_board(5, 3, (0, 0), vec![scripted_object(0, 1, "m")]);
|
||||
let mut game =
|
||||
GameState::with_scripts(board, scripts_from(&[("m", "fn init(m,s) { move(West); }")]));
|
||||
GameState::with_scripts(board, scripts_from(&[("m", "fn init(m) { move(West); }")]));
|
||||
game.run_init();
|
||||
assert_eq!(game.board().objects[&1].x, 0);
|
||||
}
|
||||
@@ -29,7 +29,7 @@ fn move_into_a_wall_or_edge_is_a_noop() {
|
||||
fn set_tile_command_changes_the_source_glyph() {
|
||||
let board = open_board(5, 3, (0, 0), vec![scripted_object(2, 1, "s")]);
|
||||
let mut game =
|
||||
GameState::with_scripts(board, scripts_from(&[("s", "fn init(m,s) { set_tile(7); }")]));
|
||||
GameState::with_scripts(board, scripts_from(&[("s", "fn init(m) { set_tile(7); }")]));
|
||||
game.run_init();
|
||||
assert_eq!(game.board().objects[&1].glyph.tile, 7);
|
||||
}
|
||||
@@ -40,7 +40,7 @@ fn object_pushes_crate_on_init() {
|
||||
let mut board = open_board(4, 1, (0, 0), vec![scripted_object(1, 0, "m")]);
|
||||
crate_at(&mut board, 2, 0);
|
||||
let mut game =
|
||||
GameState::with_scripts(board, scripts_from(&[("m", "fn init(m,s) { move(East); }")]));
|
||||
GameState::with_scripts(board, scripts_from(&[("m", "fn init(m) { move(East); }")]));
|
||||
game.run_init();
|
||||
let b = game.board();
|
||||
assert_eq!((b.objects[&1].x, b.objects[&1].y), (2, 0));
|
||||
@@ -53,7 +53,7 @@ fn object_push_into_player() {
|
||||
// A scripted object moving into the player pushes the player when there's room.
|
||||
let board = open_board(5, 1, (2, 0), vec![scripted_object(1, 0, "m")]);
|
||||
let mut game =
|
||||
GameState::with_scripts(board, scripts_from(&[("m", "fn init(m,s) { move(East); }")]));
|
||||
GameState::with_scripts(board, scripts_from(&[("m", "fn init(m) { move(East); }")]));
|
||||
game.run_init();
|
||||
{
|
||||
let b = game.board();
|
||||
@@ -65,7 +65,7 @@ fn object_push_into_player() {
|
||||
let mut board = open_board(4, 1, (2, 0), vec![scripted_object(1, 0, "m")]);
|
||||
wall_at(&mut board, 3, 0);
|
||||
let mut game =
|
||||
GameState::with_scripts(board, scripts_from(&[("m", "fn init(m,s) { move(East); }")]));
|
||||
GameState::with_scripts(board, scripts_from(&[("m", "fn init(m) { move(East); }")]));
|
||||
game.run_init();
|
||||
let b = game.board();
|
||||
assert_eq!((b.objects[&1].x, b.objects[&1].y), (1, 0));
|
||||
@@ -79,7 +79,7 @@ fn move_cost_rate_limits_repeated_moves() {
|
||||
let board = open_board(5, 1, (0, 0), vec![scripted_object(1, 0, "m")]);
|
||||
let mut game = GameState::with_scripts(
|
||||
board,
|
||||
scripts_from(&[("m", "fn init(m,s) { move(East); move(East); }")]),
|
||||
scripts_from(&[("m", "fn init(m) { move(East); move(East); }")]),
|
||||
);
|
||||
game.run_init();
|
||||
assert_eq!(game.board().objects[&1].x, 2); // first move applied (1 -> 2)
|
||||
@@ -102,7 +102,7 @@ fn inline_delay_paces_subsequent_moves() {
|
||||
wall_at(&mut board, 2, 1);
|
||||
let mut game = GameState::with_scripts(
|
||||
board,
|
||||
scripts_from(&[("m", "fn init(m,s) { move(East); move(South); }")]),
|
||||
scripts_from(&[("m", "fn init(m) { move(East); move(South); }")]),
|
||||
);
|
||||
game.run_init();
|
||||
// First (eastward) move is blocked by the wall: object hasn't moved.
|
||||
@@ -136,7 +136,7 @@ fn queue_length_reports_pending_actions() {
|
||||
board,
|
||||
scripts_from(&[(
|
||||
"q",
|
||||
"fn init(m,s) { set_tile(5); set_tile(6); log(`len=${m.queue.length}`); }",
|
||||
"fn init(m) { set_tile(5); set_tile(6); log(`len=${m.queue.length}`); }",
|
||||
)]),
|
||||
);
|
||||
game.run_init();
|
||||
@@ -166,7 +166,7 @@ fn blocked_reports_solid_and_clear() {
|
||||
board,
|
||||
scripts_from(&[(
|
||||
"b",
|
||||
"fn init(m, s) { if m.blocked(East) { set_tile(9); } else { set_tile(7); } }",
|
||||
"fn init(m) { if m.blocked(East) { set_tile(9); } else { set_tile(7); } }",
|
||||
)]),
|
||||
);
|
||||
game.run_init();
|
||||
@@ -178,7 +178,7 @@ fn blocked_reports_solid_and_clear() {
|
||||
board,
|
||||
scripts_from(&[(
|
||||
"b",
|
||||
"fn init(m, s) { if m.blocked(East) { set_tile(9); } else { set_tile(7); } }",
|
||||
"fn init(m) { if m.blocked(East) { set_tile(9); } else { set_tile(7); } }",
|
||||
)]),
|
||||
);
|
||||
game.run_init();
|
||||
|
||||
@@ -18,11 +18,11 @@ fn collision_priority_resolves_in_array_order_and_bumps() {
|
||||
scripts_from(&[
|
||||
(
|
||||
"e",
|
||||
"fn init(m,s) { move(East); } fn bump(m,s,id) { log(`o0 by ${id}`); }",
|
||||
"fn init(m) { move(East); } fn bump(m,id) { log(`o0 by ${id}`); }",
|
||||
),
|
||||
(
|
||||
"w",
|
||||
"fn init(m,s) { move(West); } fn bump(m,s,id) { log(`o1 by ${id}`); }",
|
||||
"fn init(m) { move(West); } fn bump(m,id) { log(`o1 by ${id}`); }",
|
||||
),
|
||||
]),
|
||||
);
|
||||
|
||||
@@ -8,7 +8,7 @@ use std::time::Duration;
|
||||
fn init_runs_only_on_run_init_not_at_construction() {
|
||||
let (board, scripts) = board_with_object(
|
||||
Some("greet"),
|
||||
&[("greet", r#"fn init(m,s) { log("hello"); }"#)],
|
||||
&[("greet", r#"fn init(m) { log("hello"); }"#)],
|
||||
);
|
||||
let mut game = GameState::with_scripts(board, scripts);
|
||||
// init must not fire during construction / deserialization.
|
||||
@@ -22,7 +22,7 @@ fn init_runs_only_on_run_init_not_at_construction() {
|
||||
fn tick_calls_script_tick_with_elapsed_seconds() {
|
||||
let (board, scripts) = board_with_object(
|
||||
Some("t"),
|
||||
&[("t", r#"fn tick(m,s,dt) { log(dt.to_string()); }"#)],
|
||||
&[("t", r#"fn tick(m,dt) { log(dt.to_string()); }"#)],
|
||||
);
|
||||
let mut game = GameState::with_scripts(board, scripts);
|
||||
game.run_init();
|
||||
@@ -69,7 +69,7 @@ fn script_reads_board_through_view() {
|
||||
let board = open_board(5, 3, (3, 1), vec![scripted_object(2, 1, "r")]);
|
||||
let mut game = GameState::with_scripts(
|
||||
board,
|
||||
scripts_from(&[("r", "fn init(m,s) { log(s.player.x.to_string()); }")]),
|
||||
scripts_from(&[("r", "fn init(m) { log(Player.x.to_string()); }")]),
|
||||
);
|
||||
game.run_init();
|
||||
assert_eq!(log_texts(&game), vec!["3"]);
|
||||
@@ -88,8 +88,8 @@ fn commands_are_routed_to_their_own_source_object() {
|
||||
let mut game = GameState::with_scripts(
|
||||
board,
|
||||
scripts_from(&[
|
||||
("e", "fn init(m,s) { move(East); }"),
|
||||
("w", "fn init(m,s) { move(West); }"),
|
||||
("e", "fn init(m) { move(East); }"),
|
||||
("w", "fn init(m) { move(West); }"),
|
||||
]),
|
||||
);
|
||||
game.run_init();
|
||||
@@ -127,7 +127,7 @@ fn set_tag_adds_and_removes_via_my_id() {
|
||||
// present on the object afterward.
|
||||
let (board, scripts) = board_with_object(
|
||||
Some("t"),
|
||||
&[("t", r#"fn init(m,s) { set_tag(m.id, "active", true); }"#)],
|
||||
&[("t", r#"fn init(m) { set_tag(m.id, "active", true); }"#)],
|
||||
);
|
||||
let mut game = GameState::with_scripts(board, scripts);
|
||||
game.run_init();
|
||||
@@ -136,7 +136,7 @@ fn set_tag_adds_and_removes_via_my_id() {
|
||||
// A script removes a pre-existing tag.
|
||||
let (mut board2, scripts2) = board_with_object(
|
||||
Some("t2"),
|
||||
&[("t2", r#"fn init(m,s) { set_tag(m.id, "active", false); }"#)],
|
||||
&[("t2", r#"fn init(m) { set_tag(m.id, "active", false); }"#)],
|
||||
);
|
||||
// Seed the tag before construction.
|
||||
board2
|
||||
@@ -158,8 +158,8 @@ fn has_tag_reads_own_tags() {
|
||||
Some("t"),
|
||||
&[(
|
||||
"t",
|
||||
r#"fn init(m,s) { set_tag(m.id, "active", true); }
|
||||
fn tick(m,s,dt) { log(m.has_tag("active").to_string()); }"#,
|
||||
r#"fn init(m) { set_tag(m.id, "active", true); }
|
||||
fn tick(m,dt) { log(m.has_tag("active").to_string()); }"#,
|
||||
)],
|
||||
);
|
||||
let mut game = GameState::with_scripts(board, scripts);
|
||||
@@ -182,8 +182,8 @@ fn objects_with_tag_returns_matching_ids() {
|
||||
scripts_from(&[
|
||||
(
|
||||
"q",
|
||||
r#"fn init(m,s) {
|
||||
let infos = s.board.tagged("enemy");
|
||||
r#"fn init(m) {
|
||||
let infos = Board.tagged("enemy");
|
||||
log(infos.len().to_string());
|
||||
log(infos[0].id.to_string());
|
||||
}"#,
|
||||
@@ -201,7 +201,7 @@ fn objects_with_tag_returns_matching_ids() {
|
||||
fn my_name_returns_name_or_empty_string() {
|
||||
// An object with a name set on its ObjectDef should see it via my_name().
|
||||
let (mut board, scripts) =
|
||||
board_with_object(Some("n"), &[("n", r#"fn init(m,s) { log(m.name); }"#)]);
|
||||
board_with_object(Some("n"), &[("n", r#"fn init(m) { log(m.name); }"#)]);
|
||||
board.objects.get_mut(&1).unwrap().name = Some("beacon".to_string());
|
||||
let mut game = GameState::with_scripts(board, scripts);
|
||||
game.run_init();
|
||||
@@ -209,7 +209,7 @@ fn my_name_returns_name_or_empty_string() {
|
||||
|
||||
// An unnamed object should get ().
|
||||
let (board2, scripts2) =
|
||||
board_with_object(Some("n"), &[("n", r#"fn init(m,s) { if m.name == () { log("null"); }}"#)]);
|
||||
board_with_object(Some("n"), &[("n", r#"fn init(m) { if m.name == () { log("null"); }}"#)]);
|
||||
let mut game2 = GameState::with_scripts(board2, scripts2);
|
||||
game2.run_init();
|
||||
assert_eq!(log_texts(&game2), vec!["null"]);
|
||||
@@ -228,9 +228,9 @@ fn object_id_for_name_finds_by_name() {
|
||||
scripts_from(&[
|
||||
(
|
||||
"q",
|
||||
r#"fn init(m,s) {
|
||||
log(s.board.named("target").id.to_string());
|
||||
let miss = s.board.named("missing");
|
||||
r#"fn init(m) {
|
||||
log(Board.named("target").id.to_string());
|
||||
let miss = Board.named("missing");
|
||||
log(if miss == () { "not_found" } else { miss.id.to_string() });
|
||||
}"#,
|
||||
),
|
||||
@@ -251,7 +251,7 @@ fn player_bump_fires_with_negative_one() {
|
||||
let board = open_board(3, 1, (0, 0), vec![scripted_object(1, 0, "b")]);
|
||||
let mut game = GameState::with_scripts(
|
||||
board,
|
||||
scripts_from(&[("b", "fn bump(m,s,id) { log(`bumped by ${id}`); }")]),
|
||||
scripts_from(&[("b", "fn bump(m,id) { log(`bumped by ${id}`); }")]),
|
||||
);
|
||||
game.run_init();
|
||||
game.try_move(Direction::East);
|
||||
@@ -271,7 +271,7 @@ fn scroll_opens_on_player_bump() {
|
||||
board,
|
||||
scripts_from(&[(
|
||||
"s",
|
||||
r#"fn bump(m,s,id) { scroll(["Hello world", ["eat", "Eat it"]]); }"#,
|
||||
r#"fn bump(m,id) { scroll(["Hello world", ["eat", "Eat it"]]); }"#,
|
||||
)]),
|
||||
);
|
||||
game.run_init();
|
||||
@@ -295,7 +295,7 @@ fn handle_scroll_without_choice_clears_it() {
|
||||
let board = open_board(3, 1, (0, 0), vec![scripted_object(1, 0, "s")]);
|
||||
let mut game = GameState::with_scripts(
|
||||
board,
|
||||
scripts_from(&[("s", r#"fn bump(m,s,id) { scroll(["Hello"]); }"#)]),
|
||||
scripts_from(&[("s", r#"fn bump(m,id) { scroll(["Hello"]); }"#)]),
|
||||
);
|
||||
game.run_init();
|
||||
game.try_move(Direction::East);
|
||||
@@ -317,7 +317,7 @@ fn handle_scroll_with_choice_dispatches_send_to_source() {
|
||||
scripts_from(&[(
|
||||
"s",
|
||||
r#"
|
||||
fn bump(m,s,id) { scroll(["Muffin?", ["eat", "Eat it"]]); }
|
||||
fn bump(m,id) { scroll(["Muffin?", ["eat", "Eat it"]]); }
|
||||
fn eat() { log("eaten"); }
|
||||
"#,
|
||||
)]),
|
||||
|
||||
Reference in New Issue
Block a user