Files
DungeonCrawlerWorld/tests/e2e/test_secret_trap_shrine_e2e.gd

83 lines
4.0 KiB
GDScript

extends GutTest
const GameScene = preload("res://scenes/Game.tscn")
const GridMapState = preload("res://scripts/domain/grid_map_state.gd")
var game: Game
func before_each() -> void:
game = GameScene.instantiate()
add_child_autofree(game)
await get_tree().process_frame
func test_walking_on_an_undiscovered_trap_records_complete_structured_events() -> void:
var state := game.get_game_state()
state.enemies.clear()
state.player.perception = 0
var trap_cell := state.player.cell + Vector2i.RIGHT
state.floor_state.traps[trap_cell] = {"trap_id": &"trap_dart"}
game._unhandled_input(_key_event(KEY_RIGHT))
assert_eq(state.player.cell, trap_cell)
var trap_events := game.get_run_state().recent_events(8).filter(func(event: GameEvent) -> bool: return event.kind in [&"trap_triggered", &"trap_status_applied"])
# One structured trigger, one structured status, plus the legacy TurnResult
# compatibility event are all journaled with complete actor/cell metadata.
assert_eq(trap_events.size(), 3)
assert_eq(trap_events.filter(func(event: GameEvent) -> bool: return event.kind == &"trap_status_applied").size(), 1)
assert_true(trap_events.all(func(event: GameEvent) -> bool: return event.actor_id == state.player.id and event.cell == trap_cell))
assert_true(state.player.has_status(&"poison"))
func test_real_input_route_reveals_secret_discovers_and_disarms_trap_then_uses_shrine_and_reads_board() -> void:
var state := game.get_game_state()
state.enemies.clear()
var player_cell := state.player.cell
var secret_cell := player_cell + Vector2i.RIGHT
var trap_cell := player_cell + Vector2i(2, 0)
var shrine_cell := player_cell + Vector2i(1, 1)
var board_cell := player_cell + Vector2i(2, 1)
state.map.set_cell(secret_cell, GridMapState.CellKind.WALL)
state.floor_state.secrets[secret_cell] = {"reveal_dc": 1, "revealed_kind": GridMapState.CellKind.FLOOR}
state.floor_state.traps[trap_cell] = {"trap_id": &"trap_spikes"}
state.floor_state.shrines[shrine_cell] = {"shrine_id": &"shrine_renewal", "action_event": &"shrine_prayed", "message": "The shrine answers."}
state.floor_state.quest_boards[board_cell] = {"quest_ids": [&"quest_cartography"], "action_event": &"quest_board_read", "message": "The board lists work."}
state.player.perception = 12
state.player.trap_skill = 12
state.update_exploration()
game.get_node("HUD").refresh(state, game.get_run_state().recent_events(0), game.get_run_state())
game._unhandled_input(_key_event(KEY_RIGHT))
assert_eq(game.last_turn_results[0].kind, &"secret_revealed")
assert_eq(state.map.get_cell(secret_cell), GridMapState.CellKind.FLOOR)
assert_eq(state.player.cell, player_cell)
game._unhandled_input(_key_event(KEY_RIGHT))
assert_eq(game.last_turn_results[0].kind, &"trap_discovered")
assert_eq(state.player.cell, secret_cell)
assert_eq((game.get_node("HUD") as GameHud).get_context_prompt(), "Espace — Désamorcer le piège")
game._unhandled_input(_key_event(KEY_SPACE))
assert_eq(game.last_turn_results[0].kind, &"trap_disarmed")
assert_true(state.floor_state.traps[trap_cell].disarmed)
game._unhandled_input(_key_event(KEY_DOWN))
assert_eq(state.player.cell, shrine_cell)
assert_eq((game.get_node("HUD") as GameHud).get_context_prompt(), "Espace — Prier au sanctuaire")
game._unhandled_input(_key_event(KEY_SPACE))
assert_eq(game.last_turn_results[0].kind, &"shrine_prayed")
assert_string_contains((game.get_node("HUD/EventLog") as RichTextLabel).get_parsed_text(), "The shrine answers.")
game._unhandled_input(_key_event(KEY_RIGHT))
assert_eq(state.player.cell, board_cell)
assert_eq((game.get_node("HUD") as GameHud).get_context_prompt(), "Espace — Lire le tableau des quêtes")
game._unhandled_input(_key_event(KEY_SPACE))
assert_eq(game.last_turn_results[0].kind, &"quest_board_read")
assert_string_contains((game.get_node("HUD/EventLog") as RichTextLabel).get_parsed_text(), "The board lists work.")
func _key_event(keycode: Key) -> InputEventKey:
var event := InputEventKey.new()
event.keycode = keycode
event.physical_keycode = keycode
event.pressed = true
return event