Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c16f648ce8 | ||
|
|
b0ce464a38 | ||
|
|
a8e59544ff | ||
|
|
b469c6decb | ||
|
|
e501dbccc6 |
@@ -10,7 +10,7 @@ Godot 4.2+ is required (verified with Godot 4.5). GUT **9.5.0** is vendored and
|
||||
"${GODOT_BIN:-$(command -v godot4 || command -v godot)}" --path .
|
||||
```
|
||||
|
||||
Use WASD / arrow keys (and QZC diagonals). The HUD help band uses the French labels `Déplacer : ZQSD / Flèches` and `Interagir : Espace ou E`; both **Space** and **E** are bound to `interact`. `Game.submit_test_action(Vector2i)` is the deterministic public E2E seam and follows the same action processor as keyboard input.
|
||||
Use WASD / arrow keys (and QZC diagonals). The HUD help band uses the French labels `Déplacer : ZQSD / Flèches` and `Interagir : Espace ou E`; both **Space** and **E** are bound to `interact`. `Game.submit_test_action(Vector2i)` and `Game.submit_test_interact()` are deterministic public E2E seams and follow the same processors as keyboard input. Interacting with an adjacent closed door opens it into floor space, logs the action, refreshes FOV, and gives living enemies exactly one normal response; interacting with no target only logs `nothing_to_interact` and does not consume an enemy turn. Interacting while standing on stairs logs `stairs_used`, sets the demonstration exit state, and gives living enemies exactly one normal response.
|
||||
|
||||
## Display, grid, and camera
|
||||
|
||||
@@ -60,7 +60,7 @@ GODOT_BIN=/snap/bin/godot4 ./scripts/run-visual-check.sh
|
||||
GODOT_BIN=/snap/bin/godot4 ./scripts/verify.sh
|
||||
```
|
||||
|
||||
`run-visual-check.sh` runs the actual project with `--capture`, waits for it to render, logs output to `artifacts/visual-check.log`, and requires the project-owned capture at `artifacts/visual-check.png` to be a valid **1280×720** PNG. It chooses `xvfb-run` with a 1280×720 screen when no display is available, enforces a timeout, and reports **unavailable** (rather than a false pass) when neither a display nor Xvfb exists. `verify.sh` runs unit tests and headless E2E before visual verification; unavailable visual verification is reported distinctly from a failed test or failed visual capture.
|
||||
`run-visual-check.sh` runs the actual project twice: `--capture` records the initial state at `artifacts/visual-check.png`, while `--capture-exit` records the reached-exit state at `artifacts/visual-check-exit.png`. Both must be valid **1280×720** PNGs, and output is logged to `artifacts/visual-check.log`. It chooses `xvfb-run` with a 1280×720 screen when no display is available, enforces a timeout, and reports **unavailable** (rather than a false pass) when neither a display nor Xvfb exists. `verify.sh` runs unit tests and headless E2E before visual verification; unavailable visual verification is reported distinctly from a failed test or failed visual capture.
|
||||
|
||||
For a direct headless startup check:
|
||||
|
||||
@@ -73,13 +73,32 @@ GODOT_BIN=/snap/bin/godot4 timeout 3s /snap/bin/godot4 --headless --path .
|
||||
- `GameState.visible_cells` render at full brightness; cells retained in `explored_cells` render dimly; unknown cells are black.
|
||||
- FOV is map-aware: walls and closed doors are visible but block cells behind them.
|
||||
- `HUD/PlayerHealthLabel`, `HUD/EnemyHealthLabel`, `HUD/CombatSummaryLabel`, and `HUD/EventLog` expose the current combat state. Their historical public paths are retained while viewport-anchored HUD panels separate stats, journal, contextual prompt, and help.
|
||||
- `HUD/ContextPromptLabel` mirrors `GameHud.get_context_prompt()`: a closed door adjacent to the player reads `Espace — Ouvrir la porte`; stairs under the player read `Espace — Descendre l’escalier`; a reached exit reads `Sortie atteinte — prochain étage bientôt disponible`; otherwise it is empty. S5.2 only presents these affordances—neither doors nor stairs are modified.
|
||||
- `HUD/ContextPromptLabel` mirrors `GameHud.get_context_prompt()`: a closed door adjacent to the player reads `Espace — Ouvrir la porte`; stairs under the player read `Espace — Descendre l’escalier`; a reached exit reads `Sortie atteinte — prochain étage bientôt disponible`; otherwise it is empty. Using stairs sets only `GameState.exit_reached`, logs `stairs_used`, and leaves the player and current map in place.
|
||||
- Every `melee` and `enemy_melee` result is routed to its actor view; the sprite's persistent red tint makes received damage visible.
|
||||
|
||||
## Exports
|
||||
|
||||
Install the matching Godot export templates, then configure/export the project in the Godot editor for **Linux/X11** or **Windows Desktop**. Linux builds may be tested on a Linux host with the resulting executable. Windows exports can be produced from Linux when the export templates are installed, but this project does **not** claim that a Windows export has been tested on Windows.
|
||||
Install the Godot 4.5 export templates matching the editor/runtime, then open `project.godot` in the Godot editor and use **Project → Export**.
|
||||
|
||||
### Linux/X11
|
||||
|
||||
1. Add or select a **Linux/X11** preset.
|
||||
2. Choose an output path such as `build/linux/DungeonCrawlerWorld.x86_64` and click **Export Project**.
|
||||
3. On Linux, make the binary executable if necessary, then launch it:
|
||||
|
||||
```bash
|
||||
chmod +x build/linux/DungeonCrawlerWorld.x86_64
|
||||
./build/linux/DungeonCrawlerWorld.x86_64
|
||||
```
|
||||
|
||||
### Windows Desktop
|
||||
|
||||
1. Add or select a **Windows Desktop** preset.
|
||||
2. Choose an output path such as `build/windows/DungeonCrawlerWorld.exe` and click **Export Project**.
|
||||
3. Distribute the exported `.exe` with its generated `.pck` file when Godot produces one.
|
||||
|
||||
Windows exports can be produced from Linux when the matching templates are installed, but this project does **not** claim that a Windows export has been tested on Windows.
|
||||
|
||||
## Limits
|
||||
|
||||
This compact prototype has one deterministic goblin, direct pursuit, no persistence or inventory UI, and persistent rather than animated damage tint. Audio remains intentionally nonblocking and uses no bundled assets.
|
||||
This compact prototype has one deterministic goblin, direct pursuit, no persistence or inventory UI, and persistent rather than animated damage tint. Audio remains intentionally nonblocking and uses no bundled assets. Reaching the stairs is a demonstration-only exit: it sets `exit_reached` and displays `Sortie atteinte — prochain étage bientôt disponible`; **no next level is generated or loaded**, and the current player and map remain unchanged.
|
||||
|
||||
@@ -2,6 +2,7 @@ class_name GameState
|
||||
extends RefCounted
|
||||
|
||||
const TurnResolverType = preload("res://scripts/domain/turn_resolver.gd")
|
||||
const InteractionResolverType = preload("res://scripts/domain/interaction_resolver.gd")
|
||||
|
||||
var player: ActorState
|
||||
var enemies: Dictionary[StringName, ActorState]
|
||||
@@ -31,6 +32,12 @@ func try_player_action(direction: Vector2i) -> Array[TurnResult]:
|
||||
update_exploration()
|
||||
return results
|
||||
|
||||
func try_interact() -> Array[TurnResult]:
|
||||
var results := InteractionResolverType.resolve(self)
|
||||
if results[0].kind != &"nothing_to_interact":
|
||||
update_exploration()
|
||||
return results
|
||||
|
||||
func compute_visible_cells(game_map: GridMapState, origin: Vector2i, radius: int) -> Dictionary[Vector2i, bool]:
|
||||
var visible: Dictionary[Vector2i, bool] = {}
|
||||
for y in range(origin.y - radius, origin.y + radius + 1):
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
class_name InteractionResolver
|
||||
extends RefCounted
|
||||
|
||||
const TurnResolverType = preload("res://scripts/domain/turn_resolver.gd")
|
||||
const TurnResultType = preload("res://scripts/domain/turn_result.gd")
|
||||
|
||||
const TARGET_OFFSETS: Array[Vector2i] = [
|
||||
Vector2i.ZERO,
|
||||
Vector2i.UP,
|
||||
Vector2i.RIGHT,
|
||||
Vector2i.DOWN,
|
||||
Vector2i.LEFT,
|
||||
Vector2i(1, -1),
|
||||
Vector2i(1, 1),
|
||||
Vector2i(-1, 1),
|
||||
Vector2i(-1, -1),
|
||||
]
|
||||
|
||||
static func resolve(state: GameState) -> Array[TurnResult]:
|
||||
var results: Array[TurnResult] = []
|
||||
if state.map.get_cell(state.player.cell) == GridMapState.CellKind.STAIRS and not state.exit_reached:
|
||||
state.exit_reached = true
|
||||
results.append(TurnResultType.new(state.player.id, &"stairs_used", state.player.cell, state.player.cell, &"", 0, "You descend the stairs."))
|
||||
TurnResolverType.append_enemy_response(state, results)
|
||||
return results
|
||||
|
||||
var door_cell := _find_closed_door(state)
|
||||
if door_cell.x >= 0:
|
||||
state.map.set_cell(door_cell, GridMapState.CellKind.FLOOR)
|
||||
results.append(TurnResultType.new(state.player.id, &"door_opened", state.player.cell, door_cell, &"", 0, "You open the door."))
|
||||
TurnResolverType.append_enemy_response(state, results)
|
||||
return results
|
||||
|
||||
results.append(TurnResultType.new(state.player.id, &"nothing_to_interact", state.player.cell, state.player.cell, &"", 0, "Nothing to interact with."))
|
||||
return results
|
||||
|
||||
static func _find_closed_door(state: GameState) -> Vector2i:
|
||||
for offset in TARGET_OFFSETS:
|
||||
var cell := state.player.cell + offset
|
||||
if state.map.get_cell(cell) == GridMapState.CellKind.CLOSED_DOOR:
|
||||
return cell
|
||||
return Vector2i(-1, -1)
|
||||
@@ -17,7 +17,7 @@ static func resolve_player_action(state: GameState, direction: Vector2i) -> Arra
|
||||
state.enemies.erase(enemy.id)
|
||||
results.append(TurnResultType.new(enemy.id, &"enemy_defeated", enemy.cell, enemy.cell, player.id, 0, "The goblin is defeated."))
|
||||
else:
|
||||
_append_enemy_response(state, results)
|
||||
append_enemy_response(state, results)
|
||||
return results
|
||||
if not state.map.is_walkable(destination):
|
||||
results.append(TurnResultType.new(player.id, &"blocked", player.cell, destination, &"", 0, "Your way is blocked."))
|
||||
@@ -25,7 +25,7 @@ static func resolve_player_action(state: GameState, direction: Vector2i) -> Arra
|
||||
var from: Vector2i = player.cell
|
||||
player.cell = destination
|
||||
results.append(TurnResultType.new(player.id, &"moved", from, destination, &"", 0, "You move to (%d, %d)." % [destination.x, destination.y]))
|
||||
_append_enemy_response(state, results)
|
||||
append_enemy_response(state, results)
|
||||
return results
|
||||
|
||||
static func _enemy_at(state: GameState, cell: Vector2i) -> ActorState:
|
||||
@@ -34,7 +34,7 @@ static func _enemy_at(state: GameState, cell: Vector2i) -> ActorState:
|
||||
return enemy
|
||||
return null
|
||||
|
||||
static func _append_enemy_response(state: GameState, results: Array[TurnResult]) -> void:
|
||||
static func append_enemy_response(state: GameState, results: Array[TurnResult]) -> void:
|
||||
for enemy: ActorState in state.enemies.values():
|
||||
var delta: Vector2i = state.player.cell - enemy.cell
|
||||
if abs(delta.x) + abs(delta.y) == 1:
|
||||
|
||||
+35
-5
@@ -25,19 +25,37 @@ func _ready() -> void:
|
||||
_sync_enemy_views()
|
||||
hud.refresh(game_state)
|
||||
audio_library.set_ambience_context("exploration")
|
||||
if "--capture" in OS.get_cmdline_user_args():
|
||||
_capture_visual_check()
|
||||
var capture_mode := _get_capture_mode()
|
||||
if not capture_mode.is_empty():
|
||||
_capture_visual_check(capture_mode)
|
||||
|
||||
func _capture_visual_check() -> void:
|
||||
func _get_capture_mode() -> String:
|
||||
var arguments := OS.get_cmdline_user_args()
|
||||
if "--capture-exit" in arguments:
|
||||
return "exit"
|
||||
if "--capture" in arguments:
|
||||
return "initial"
|
||||
return ""
|
||||
|
||||
func _capture_visual_check(capture_mode: String) -> void:
|
||||
if capture_mode == "exit":
|
||||
_prepare_exit_capture_state()
|
||||
await get_tree().process_frame
|
||||
await get_tree().process_frame
|
||||
await RenderingServer.frame_post_draw
|
||||
var capture_path := ProjectSettings.globalize_path("res://artifacts/visual-check.png")
|
||||
var filename := "visual-check-exit.png" if capture_mode == "exit" else "visual-check.png"
|
||||
var capture_path := ProjectSettings.globalize_path("res://artifacts/" + filename)
|
||||
DirAccess.make_dir_recursive_absolute(capture_path.get_base_dir())
|
||||
var image := get_viewport().get_texture().get_image()
|
||||
var result := image.save_png(capture_path)
|
||||
get_tree().quit(0 if result == OK else 1)
|
||||
|
||||
func _prepare_exit_capture_state() -> void:
|
||||
game_state.map.set_cell(Vector2i(2, 1), GridMapStateType.CellKind.FLOOR)
|
||||
game_state.player.cell = Vector2i(9, 7)
|
||||
_process_interact()
|
||||
_sync_camera_to_player()
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed(&"interact"):
|
||||
submit_test_interact()
|
||||
@@ -62,7 +80,7 @@ func submit_test_action(direction: Vector2i) -> Array[TurnResult]:
|
||||
return _process_action(direction)
|
||||
|
||||
func submit_test_interact() -> Array[TurnResult]:
|
||||
return _refresh_hud_for_context()
|
||||
return _process_interact()
|
||||
|
||||
func get_game_state() -> GameState:
|
||||
return game_state
|
||||
@@ -74,6 +92,18 @@ func get_actor_cell_rect(actor_id: StringName) -> Rect2:
|
||||
return enemy_views[actor_id].get_cell_rect()
|
||||
return Rect2()
|
||||
|
||||
func _process_interact() -> Array[TurnResult]:
|
||||
if game_state.get_context_target() == &"exit_reached":
|
||||
return _refresh_hud_for_context()
|
||||
var results := game_state.try_interact()
|
||||
_sync_map_renderer_visibility()
|
||||
player_view.refresh()
|
||||
_sync_enemy_views()
|
||||
_show_damage_feedback(results)
|
||||
_dispatch_audio(results)
|
||||
hud.refresh(game_state, results)
|
||||
return results
|
||||
|
||||
func _refresh_hud_for_context() -> Array[TurnResult]:
|
||||
hud.refresh(game_state)
|
||||
return []
|
||||
|
||||
+36
-21
@@ -14,8 +14,10 @@ fi
|
||||
|
||||
mkdir -p artifacts
|
||||
log_path="artifacts/visual-check.log"
|
||||
capture_path="artifacts/visual-check.png"
|
||||
rm -f "$capture_path"
|
||||
initial_capture_path="artifacts/visual-check.png"
|
||||
exit_capture_path="artifacts/visual-check-exit.png"
|
||||
rm -f "$initial_capture_path" "$exit_capture_path"
|
||||
: > "$log_path"
|
||||
|
||||
runner=()
|
||||
if [[ -z "${DISPLAY:-}" ]]; then
|
||||
@@ -27,23 +29,26 @@ if [[ -z "${DISPLAY:-}" ]]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
set +e
|
||||
timeout --foreground 20s "${runner[@]}" "$GODOT_BIN" --path . -- --capture >"$log_path" 2>&1
|
||||
status=$?
|
||||
set -e
|
||||
if (( status != 0 )); then
|
||||
echo "visual check failed: Godot exited with status $status; see $log_path" >&2
|
||||
exit "$status"
|
||||
fi
|
||||
if grep -Eq 'SCRIPT ERROR|Parse Error|^ERROR:' "$log_path"; then
|
||||
echo "visual check failed: Godot reported errors; see $log_path" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! -s "$capture_path" ]]; then
|
||||
echo "visual check failed: missing capture $capture_path" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! python3 - "$capture_path" <<'PY'
|
||||
run_capture() {
|
||||
local label="$1"
|
||||
local capture_argument="$2"
|
||||
set +e
|
||||
timeout --foreground 20s "${runner[@]}" "$GODOT_BIN" --path . -- --"$capture_argument" >>"$log_path" 2>&1
|
||||
local status=$?
|
||||
set -e
|
||||
if (( status != 0 )); then
|
||||
echo "visual check failed: $label capture Godot exited with status $status; see $log_path" >&2
|
||||
exit "$status"
|
||||
fi
|
||||
}
|
||||
|
||||
validate_capture() {
|
||||
local capture_path="$1"
|
||||
if [[ ! -s "$capture_path" ]]; then
|
||||
echo "visual check failed: missing capture $capture_path" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! python3 - "$capture_path" <<'PY'
|
||||
import struct
|
||||
import sys
|
||||
|
||||
@@ -60,7 +65,17 @@ if (width, height) != (1280, 720):
|
||||
raise SystemExit(f"expected 1280x720 PNG, got {width}x{height}")
|
||||
print(f"visual capture: {path} ({width}x{height})")
|
||||
PY
|
||||
then
|
||||
echo "visual check failed: capture is not a nonempty valid PNG" >&2
|
||||
then
|
||||
echo "visual check failed: capture is not a nonempty valid PNG" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
run_capture "initial" "capture"
|
||||
run_capture "exit" "capture-exit"
|
||||
if grep -Eq 'SCRIPT ERROR|Parse Error|^ERROR:' "$log_path"; then
|
||||
echo "visual check failed: Godot reported errors; see $log_path" >&2
|
||||
exit 1
|
||||
fi
|
||||
validate_capture "$initial_capture_path"
|
||||
validate_capture "$exit_capture_path"
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
extends GutTest
|
||||
|
||||
const GameScene = preload("res://scenes/Game.tscn")
|
||||
var game: Game
|
||||
|
||||
func before_each() -> void:
|
||||
game = GameScene.instantiate()
|
||||
add_child_autofree(game)
|
||||
await get_tree().process_frame
|
||||
|
||||
func test_input_map_binds_space_and_e_to_interact() -> void:
|
||||
assert_true(InputMap.action_has_event(&"interact", _key_event(KEY_SPACE)))
|
||||
assert_true(InputMap.action_has_event(&"interact", _key_event(KEY_E)))
|
||||
|
||||
func test_real_game_keyboard_space_and_test_seam_open_door_then_allow_walking_through_it() -> void:
|
||||
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
|
||||
var door_cell := Vector2i(2, 1)
|
||||
game._unhandled_input(_key_event(KEY_SPACE))
|
||||
|
||||
assert_eq(state.map.get_cell(door_cell), GridMapState.CellKind.FLOOR)
|
||||
assert_eq(hud.get_context_prompt(), "")
|
||||
assert_eq(prompt_label.text, "")
|
||||
assert_string_contains(event_log.get_parsed_text(), "You open the door.")
|
||||
|
||||
var move_results := game.submit_test_action(Vector2i.UP)
|
||||
assert_eq(move_results[0].kind, &"moved")
|
||||
assert_eq(state.player.cell, door_cell)
|
||||
|
||||
var submitted_game := GameScene.instantiate() as Game
|
||||
add_child_autofree(submitted_game)
|
||||
await get_tree().process_frame
|
||||
var submitted_results: Array[TurnResult] = submitted_game.submit_test_interact()
|
||||
assert_eq(submitted_results[0].kind, &"door_opened")
|
||||
assert_eq(submitted_game.get_game_state().map.get_cell(door_cell), GridMapState.CellKind.FLOOR)
|
||||
|
||||
var e_game := GameScene.instantiate() as Game
|
||||
add_child_autofree(e_game)
|
||||
await get_tree().process_frame
|
||||
e_game._unhandled_input(_key_event(KEY_E))
|
||||
assert_eq(e_game.get_game_state().map.get_cell(door_cell), GridMapState.CellKind.FLOOR)
|
||||
|
||||
func _key_event(keycode: Key) -> InputEventKey:
|
||||
var event := InputEventKey.new()
|
||||
event.keycode = keycode
|
||||
event.physical_keycode = keycode
|
||||
event.pressed = true
|
||||
return event
|
||||
@@ -0,0 +1,44 @@
|
||||
extends GutTest
|
||||
|
||||
const GameScene = preload("res://scenes/Game.tscn")
|
||||
var game: Game
|
||||
|
||||
func before_each() -> void:
|
||||
game = GameScene.instantiate()
|
||||
add_child_autofree(game)
|
||||
await get_tree().process_frame
|
||||
|
||||
func test_real_input_event_completes_door_to_stairs_exit_without_replacing_the_current_map() -> void:
|
||||
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
|
||||
var initial_map := state.map
|
||||
var initial_map_size := state.map.size
|
||||
|
||||
game._unhandled_input(_key_event(KEY_SPACE))
|
||||
assert_eq(state.map.get_cell(Vector2i(2, 1)), GridMapState.CellKind.FLOOR)
|
||||
|
||||
for keycode in [KEY_UP, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT]:
|
||||
game._unhandled_input(_key_event(keycode))
|
||||
|
||||
assert_eq(state.player.cell, Vector2i(9, 7))
|
||||
assert_eq(hud.get_context_prompt(), "Espace — Descendre l’escalier")
|
||||
game._unhandled_input(_key_event(KEY_E))
|
||||
|
||||
assert_true(state.exit_reached)
|
||||
assert_eq(hud.get_context_prompt(), "Sortie atteinte — prochain étage bientôt disponible")
|
||||
assert_eq(prompt_label.text, "Sortie atteinte — prochain étage bientôt disponible")
|
||||
assert_string_contains(event_log.get_parsed_text(), "You open the door.")
|
||||
assert_string_contains(event_log.get_parsed_text(), "You descend the stairs.")
|
||||
assert_same(state.map, initial_map)
|
||||
assert_eq(state.map.size, initial_map_size)
|
||||
assert_eq(state.map.get_cell(Vector2i(9, 7)), GridMapState.CellKind.STAIRS)
|
||||
assert_eq(state.player.cell, Vector2i(9, 7))
|
||||
|
||||
func _key_event(keycode: Key) -> InputEventKey:
|
||||
var event := InputEventKey.new()
|
||||
event.keycode = keycode
|
||||
event.physical_keycode = keycode
|
||||
event.pressed = true
|
||||
return event
|
||||
@@ -29,9 +29,13 @@ func test_real_game_exposes_door_and_stairs_prompts_with_help_and_event_log() ->
|
||||
|
||||
state.map.set_cell(Vector2i(2, 1), GridMapState.CellKind.FLOOR)
|
||||
state.player.cell = Vector2i(9, 7)
|
||||
game.submit_test_interact()
|
||||
hud.refresh(state)
|
||||
assert_eq(hud.get_context_prompt(), "Espace — Descendre l’escalier")
|
||||
assert_eq(prompt_label.text, "Espace — Descendre l’escalier")
|
||||
var stairs_results := game.submit_test_interact()
|
||||
assert_eq(stairs_results[0].kind, &"stairs_used")
|
||||
assert_eq(hud.get_context_prompt(), "Sortie atteinte — prochain étage bientôt disponible")
|
||||
assert_eq(prompt_label.text, "Sortie atteinte — prochain étage bientôt disponible")
|
||||
|
||||
var results := game.submit_test_action(Vector2i.LEFT)
|
||||
assert_eq(results[0].kind, &"moved")
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
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")
|
||||
|
||||
func make_state() -> GameState:
|
||||
var map := GridMapState.new(Vector2i(8, 6), GridMapState.CellKind.FLOOR)
|
||||
var player := ActorState.new(&"player", Vector2i(3, 3), 12, 3)
|
||||
var goblin := ActorState.new(&"goblin", Vector2i(6, 3), 6, 2)
|
||||
return GameState.new(map, player, {&"goblin": goblin})
|
||||
|
||||
func test_try_interact_opens_the_first_closed_door_in_contract_neighbour_order() -> void:
|
||||
var state := make_state()
|
||||
var north := state.player.cell + Vector2i.UP
|
||||
var east := state.player.cell + Vector2i.RIGHT
|
||||
state.map.set_cell(north, GridMapState.CellKind.CLOSED_DOOR)
|
||||
state.map.set_cell(east, GridMapState.CellKind.CLOSED_DOOR)
|
||||
|
||||
var results: Array[TurnResult] = state.try_interact()
|
||||
|
||||
assert_eq(results.size(), 2)
|
||||
assert_eq(results[0].kind, &"door_opened")
|
||||
assert_eq(results[0].from_cell, state.player.cell)
|
||||
assert_eq(results[0].to_cell, north)
|
||||
assert_eq(state.map.get_cell(north), GridMapState.CellKind.FLOOR)
|
||||
assert_eq(state.map.get_cell(east), GridMapState.CellKind.CLOSED_DOOR)
|
||||
assert_eq(state.player.cell, Vector2i(3, 3))
|
||||
|
||||
func test_try_interact_without_a_target_only_reports_nothing_and_does_not_take_a_turn() -> void:
|
||||
var state := make_state()
|
||||
state.enemies[&"goblin"].cell = Vector2i(4, 3)
|
||||
var player_cell := state.player.cell
|
||||
var player_hp := state.player.hit_points
|
||||
var enemy_cell := state.enemies[&"goblin"].cell
|
||||
|
||||
var results: Array[TurnResult] = state.try_interact()
|
||||
|
||||
assert_eq(results.size(), 1)
|
||||
assert_eq(results[0].kind, &"nothing_to_interact")
|
||||
assert_eq(state.player.cell, player_cell)
|
||||
assert_eq(state.player.hit_points, player_hp)
|
||||
assert_eq(state.enemies[&"goblin"].cell, enemy_cell)
|
||||
|
||||
func test_opening_a_door_recalculates_fov_and_triggers_exactly_one_enemy_response() -> void:
|
||||
var map := GridMapState.new(Vector2i(7, 5), GridMapState.CellKind.FLOOR)
|
||||
var door := Vector2i(2, 2)
|
||||
var revealed_cell := Vector2i(3, 2)
|
||||
map.set_cell(door, GridMapState.CellKind.CLOSED_DOOR)
|
||||
var player := ActorState.new(&"player", Vector2i(1, 2), 12, 3)
|
||||
var goblin := ActorState.new(&"goblin", Vector2i(5, 2), 6, 2)
|
||||
var state := GameState.new(map, player, {&"goblin": goblin})
|
||||
assert_false(state.visible_cells.has(revealed_cell))
|
||||
|
||||
var results: Array[TurnResult] = state.try_interact()
|
||||
var enemy_result_count := 0
|
||||
for result in results:
|
||||
if String(result.kind).begins_with("enemy_"):
|
||||
enemy_result_count += 1
|
||||
|
||||
assert_eq(results[0].kind, &"door_opened")
|
||||
assert_eq(state.map.get_cell(door), GridMapState.CellKind.FLOOR)
|
||||
assert_true(state.visible_cells.has(revealed_cell))
|
||||
assert_eq(enemy_result_count, 1)
|
||||
@@ -0,0 +1,68 @@
|
||||
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_refreshes_exact_exit_prompt_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(2, 1), GridMapState.CellKind.FLOOR)
|
||||
state.player.cell = Vector2i(9, 7)
|
||||
|
||||
var results := game.submit_test_interact()
|
||||
|
||||
assert_eq(results[0].kind, &"stairs_used")
|
||||
assert_true(state.exit_reached)
|
||||
assert_eq(hud.get_context_prompt(), "Sortie atteinte — prochain étage bientôt disponible")
|
||||
assert_eq(prompt_label.text, "Sortie atteinte — prochain étage bientôt disponible")
|
||||
assert_string_contains(event_log.get_parsed_text(), "You descend the stairs.")
|
||||
Reference in New Issue
Block a user