Files
DungeonCrawlerWorld/tests/unit/test_stairs_interaction.gd
T

71 lines
3.0 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
extends GutTest
const GridMapState = preload("res://scripts/domain/grid_map_state.gd")
const ActorState = preload("res://scripts/domain/actor_state.gd")
const GameState = preload("res://scripts/domain/game_state.gd")
const GameScene = preload("res://scenes/Game.tscn")
func test_interacting_on_stairs_reaches_the_exit_emits_stairs_used_and_keeps_the_map_and_player() -> void:
var map := GridMapState.new(Vector2i(8, 6), GridMapState.CellKind.FLOOR)
var stairs := Vector2i(3, 3)
map.set_cell(stairs, GridMapState.CellKind.STAIRS)
var player := ActorState.new(&"player", stairs, 12, 3)
var goblin := ActorState.new(&"goblin", Vector2i(6, 3), 6, 2)
var state := GameState.new(map, player, {&"goblin": goblin})
var player_cell := state.player.cell
var map_size := state.map.size
var results: Array[TurnResult] = state.try_interact()
assert_true(state.exit_reached)
assert_eq(results[0].kind, &"stairs_used")
assert_eq(results[0].from_cell, stairs)
assert_eq(results[0].to_cell, stairs)
assert_eq(results[0].message, "You descend the stairs.")
assert_eq(state.player.cell, player_cell)
assert_same(state.map, map)
assert_eq(state.map.size, map_size)
assert_eq(state.map.get_cell(stairs), GridMapState.CellKind.STAIRS)
func test_stairs_usage_triggers_exactly_one_enemy_response_without_transitioning_the_level() -> void:
var map := GridMapState.new(Vector2i(8, 6), GridMapState.CellKind.FLOOR)
var stairs := Vector2i(3, 3)
map.set_cell(stairs, GridMapState.CellKind.STAIRS)
var player := ActorState.new(&"player", stairs, 12, 3)
var goblin := ActorState.new(&"goblin", Vector2i(6, 3), 6, 2)
var state := GameState.new(map, player, {&"goblin": goblin})
var enemy_response_count := 0
var results: Array[TurnResult] = state.try_interact()
for result in results:
if String(result.kind).begins_with("enemy_"):
enemy_response_count += 1
assert_eq(results.size(), 2)
assert_eq(results[0].kind, &"stairs_used")
assert_eq(enemy_response_count, 1)
assert_true(state.exit_reached)
assert_eq(state.player.cell, stairs)
assert_same(state.map, map)
func test_stairs_usage_transitions_to_floor_one_and_writes_the_journal() -> void:
var game := GameScene.instantiate() as Game
add_child_autofree(game)
await get_tree().process_frame
var state := game.get_game_state()
var hud := game.get_node("HUD") as GameHud
var prompt_label := game.get_node("HUD/ContextPromptLabel") as Label
var event_log := game.get_node("HUD/EventLog") as RichTextLabel
state.map.set_cell(Vector2i(4, 11), GridMapState.CellKind.FLOOR)
state.player.cell = Vector2i(18, 4)
game.get_run_state().current_floor_deadline().turns_remaining = 2 * FloorDeadline.TURNS_PER_DAY
var results := game.submit_test_interact()
assert_eq(results[0].kind, &"stairs_used")
assert_eq(game.get_run_state().current_floor, 1)
assert_eq(game.get_game_state().player.cell, game.get_game_state().floor_state.entrance)
assert_eq(hud.get_context_prompt(), "Espace — Monter l’escalier")
assert_eq(prompt_label.text, "Espace — Monter l’escalier")
assert_string_contains(event_log.get_parsed_text(), "You descend the stairs.")