Compare commits

...
32 changed files with 677 additions and 38 deletions
+12
View File
@@ -166,6 +166,18 @@ grow_vertical = 0
theme_override_colors/font_color = Color(1, 0.9, 0.5, 1)
theme_override_font_sizes/font_size = 16
[node name="DeadlineLabel" type="Label" parent="HUD"]
layout_mode = 1
anchors_preset = 0
offset_left = 26.0
offset_top = 94.0
offset_right = 360.0
offset_bottom = 114.0
grow_horizontal = 0
grow_vertical = 0
theme_override_colors/font_color = Color(1, 0.76, 0.4, 1)
theme_override_font_sizes/font_size = 14
[node name="EventLog" type="RichTextLabel" parent="HUD"]
layout_mode = 1
anchors_preset = 1
+8 -1
View File
@@ -25,16 +25,23 @@ func _init(new_map: GridMapState, new_player: ActorState, new_enemies: Dictionar
func bind_run_state(run_state: RunState) -> void:
run_state.set_floor_state(floor_state)
floor_state = run_state.current_floor_state()
set_floor_state(run_state.current_floor_state())
func set_floor_state(new_floor_state: FloorState) -> void:
floor_state = new_floor_state
map = floor_state.map
enemies = floor_state.enemies
explored_cells = floor_state.explored_cells
exit_reached = false
update_exploration()
func get_context_target() -> StringName:
if exit_reached:
return &"exit_reached"
if map.get_cell(player.cell) == GridMapState.CellKind.STAIRS:
return &"stairs"
if map.get_cell(player.cell) == GridMapState.CellKind.BED:
return &"bed"
for direction in InteractionResolverType.TARGET_OFFSETS:
if map.get_cell(player.cell + direction) == GridMapState.CellKind.CHEST:
return &"chest"
+2 -2
View File
@@ -2,7 +2,7 @@ class_name GridMapState
extends RefCounted
const TILE_SIZE := Vector2i(32, 32)
enum CellKind { FLOOR, WALL, CLOSED_DOOR, CHEST, STAIRS }
enum CellKind { FLOOR, WALL, CLOSED_DOOR, CHEST, STAIRS, BED }
var size: Vector2i
var _cells: Dictionary[Vector2i, CellKind] = {}
@@ -37,7 +37,7 @@ func is_inside(cell: Vector2i) -> bool:
func is_walkable(cell: Vector2i) -> bool:
var kind := get_cell(cell)
return kind == CellKind.FLOOR or kind == CellKind.STAIRS
return kind == CellKind.FLOOR or kind == CellKind.STAIRS or kind == CellKind.BED
func is_opaque(cell: Vector2i) -> bool:
var kind := get_cell(cell)
+4 -1
View File
@@ -20,13 +20,16 @@ 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."))
var stairs_message := "You ascend the stairs." if state.floor_state.floor_number > 0 and state.player.cell == state.floor_state.entrance else "You descend the stairs."
results.append(TurnResultType.new(state.player.id, &"stairs_used", state.player.cell, state.player.cell, &"", 0, stairs_message))
TurnResolverType.append_enemy_response(state, results)
return results
var chest_cell := _find_cell_of_kind(state, GridMapState.CellKind.CHEST)
if chest_cell.x >= 0:
state.map.set_cell(chest_cell, GridMapState.CellKind.FLOOR)
if state.floor_state.chests.has(chest_cell):
state.floor_state.chests[chest_cell]["opened"] = true
results.append(TurnResultType.new(state.player.id, &"chest_opened", state.player.cell, chest_cell, &"", 0, "You open the chest."))
TurnResolverType.append_enemy_response(state, results)
return results
+81
View File
@@ -0,0 +1,81 @@
class_name FloorDeadline
extends RefCounted
# ASCII parity: floor one starts at fifteen days, each later floor adds five.
# A Godot run also gives its authored surface the floor-one allowance, so its
# deliberately gated tutorial exit is testable through the same domain seam.
const TURNS_PER_DAY := 20
const BASE_DAYS := 15
const EXTRA_DAYS_PER_FLOOR := 5
const REAL_SECONDS_PER_DAY := 3600.0
const WARNING_DAYS := 1
const STAIRS_OPEN_DAYS_BEFORE_COLLAPSE := 2
const BED_REST_DAY_COST := 1
const COLLAPSE_DAMAGE_PER_TURN := 3
var floor_number: int
var turns_remaining: int
var collapsing := false
var warned := false
var real_seconds := 0.0
func _init(new_floor_number: int) -> void:
floor_number = new_floor_number
turns_remaining = deadline_days_for(new_floor_number) * TURNS_PER_DAY
static func deadline_days_for(new_floor_number: int) -> int:
return BASE_DAYS + EXTRA_DAYS_PER_FLOOR * (maxi(1, new_floor_number) - 1)
func remaining_days() -> int:
return ceili(float(turns_remaining) / float(TURNS_PER_DAY))
func can_descend() -> bool:
return collapsing or turns_remaining <= STAIRS_OPEN_DAYS_BEFORE_COLLAPSE * TURNS_PER_DAY
func days_until_stairs_open() -> int:
return maxi(0, remaining_days() - STAIRS_OPEN_DAYS_BEFORE_COLLAPSE)
# A return value is a deterministic semantic event list; the presentation
# layer owns localized wording and actor damage application.
func rest() -> Array[StringName]:
if turns_remaining > 0:
turns_remaining = maxi(0, turns_remaining - BED_REST_DAY_COST * TURNS_PER_DAY)
real_seconds = 0.0
return _state_events()
# This intentionally receives elapsed time rather than reading a wall clock:
# callers/tests can advance pressure deterministically.
func advance_real_seconds(elapsed_seconds: float) -> Array[StringName]:
if elapsed_seconds <= 0.0 or turns_remaining <= 0:
return _state_events()
real_seconds += elapsed_seconds
var events: Array[StringName] = []
while real_seconds >= REAL_SECONDS_PER_DAY and turns_remaining > 0:
real_seconds -= REAL_SECONDS_PER_DAY
turns_remaining = maxi(0, turns_remaining - TURNS_PER_DAY)
events.append(&"deadline_day_elapsed")
events.append_array(_state_events())
return events
# The collapse starts once, then each later deterministic gameplay tick deals
# the fixed ASCII collapse damage. This makes the dangerous state explicit.
func tick() -> StringName:
var events := _state_events()
if events.has(&"floor_collapsed"):
return &"floor_collapsed"
if collapsing:
return &"collapse_damage"
return &""
func collapse_damage_for(hit_points: int) -> int:
return mini(COLLAPSE_DAMAGE_PER_TURN, maxi(0, hit_points))
func _state_events() -> Array[StringName]:
var events: Array[StringName] = []
if not warned and turns_remaining <= WARNING_DAYS * TURNS_PER_DAY:
warned = true
events.append(&"deadline_warning")
if turns_remaining <= 0 and not collapsing:
collapsing = true
events.append(&"floor_collapsed")
return events
+1
View File
@@ -0,0 +1 @@
uid://d1e5kjdwbkgyp
+55
View File
@@ -0,0 +1,55 @@
class_name FloorTransition
extends RefCounted
const GridMapStateType = preload("res://scripts/domain/grid_map_state.gd")
const SurfaceGeneratorType = preload("res://scripts/domain/world/surface_generator.gd")
const FloorGeneratorType = preload("res://scripts/domain/world/floor_generator.gd")
var catalog: ContentCatalog
func _init(new_catalog: ContentCatalog) -> void:
catalog = new_catalog
func initial_floor(run: RunState) -> FloorState:
if not run.floors.has(0):
run.set_floor_state(SurfaceGeneratorType.generate(run.seed))
run.current_floor = 0
run.ensure_floor_deadline(0)
return run.current_floor_state()
# Returns the cached/generated destination and the stairs cell on which the
# player arrives. Floor 0's sole stairs descends, while every procedural floor
# has an up stair at entrance and down stair at exit.
func transition(run: RunState, source: FloorState, stairs_cell: Vector2i) -> Dictionary:
var destination_number := _destination_floor_number(source, stairs_cell)
var destination := _floor_for(run, destination_number)
var arrival := destination.entrance if destination_number > source.floor_number else destination.exit
run.current_floor = destination_number
run.ensure_floor_deadline(destination_number)
return {"floor": destination, "arrival": arrival}
func _destination_floor_number(source: FloorState, stairs_cell: Vector2i) -> int:
if source.floor_number == 0:
return 1
if stairs_cell == source.entrance:
return source.floor_number - 1
return source.floor_number + 1
func _floor_for(run: RunState, floor_number: int) -> FloorState:
if run.floors.has(floor_number):
return run.floors[floor_number]
if floor_number == 0:
return initial_floor(run)
var floor := FloorGeneratorType.generate(run.seed, floor_number, catalog)
# B3 only marked the down stair. B5 makes the entry stair explicit so a
# return route is visible and interaction direction is unambiguous.
floor.map.set_cell(floor.entrance, GridMapStateType.CellKind.STAIRS)
_materialize_unopened_chests(floor)
floor.metadata["hand_authored"] = false
run.set_floor_state(floor)
return floor
func _materialize_unopened_chests(floor: FloorState) -> void:
for cell in floor.chests:
if not bool(floor.chests[cell].get("opened", false)):
floor.map.set_cell(cell, GridMapStateType.CellKind.CHEST)
@@ -0,0 +1 @@
uid://dld2hudsse86m
+14
View File
@@ -7,6 +7,9 @@ var player_name := "Sans-Nom"
var base_archetype: StringName = &"vanguard"
var current_floor := 0
var floors: Dictionary[int, FloorState] = {}
# Deadline records are intentionally independent from generated FloorState so
# revisiting/cache operations can never reset a collapsing floor's countdown.
var floor_deadlines: Dictionary[int, FloorDeadline] = {}
var current_turn := 0
var log: Array[GameEvent] = []
@@ -20,6 +23,17 @@ func set_floor_state(floor: FloorState) -> void:
func current_floor_state() -> FloorState:
return floors.get(current_floor)
func ensure_floor_deadline(floor_number: int) -> FloorDeadline:
if not floor_deadlines.has(floor_number):
floor_deadlines[floor_number] = FloorDeadline.new(floor_number)
return floor_deadlines[floor_number]
func deadline_for(floor_number: int) -> FloorDeadline:
return ensure_floor_deadline(floor_number)
func current_floor_deadline() -> FloorDeadline:
return ensure_floor_deadline(current_floor)
func next_turn() -> int:
current_turn += 1
return current_turn
+15
View File
@@ -64,9 +64,24 @@ static func generate(seed: String, floor_number: int, catalog: ContentCatalog) -
floor.map.set_cell(floor.exit, GridMapStateType.CellKind.STAIRS)
floor.metadata["room_graph"] = graph.to_dict()
floor.metadata["tree_door_cells"] = tree_door_cells
_materialize_safe_room_beds(floor)
FloorPopulatorType.populate(floor, catalog, seed)
return floor
# Beds must be installed before population so the occupancy-aware population
# pass cannot place an NPC on a safe room's resting tile.
static func _materialize_safe_room_beds(floor: FloorState) -> void:
var bed_cells: Array[Vector2i] = []
for room in floor.rooms:
if room.kind not in [&"sanctuary", &"refuge"]:
continue
var bed_cell := _room_center(room.bounds)
if bed_cell == floor.entrance or bed_cell == floor.exit:
continue
floor.map.set_cell(bed_cell, GridMapStateType.CellKind.BED)
bed_cells.append(bed_cell)
floor.metadata["bed_cells"] = bed_cells
static func _place_rooms(rng: DeterministicRng) -> Array[RoomState]:
var rooms: Array[RoomState] = []
for room_index in range(ROOM_COUNT):
+2
View File
@@ -13,6 +13,8 @@ static func populate(floor: FloorState, catalog: ContentCatalog, population_seed
floor.entrance: true,
floor.exit: true,
}
for bed_cell: Vector2i in floor.metadata.get("bed_cells", []):
occupied[bed_cell] = true
var serial := 0
for room in floor.rooms:
if room.kind == &"entrance":
+2 -2
View File
@@ -49,7 +49,7 @@ func tree_distances(start_index: int) -> Dictionary[int, int]:
var distances: Dictionary[int, int] = {start_index: 0}
var frontier: Array[int] = [start_index]
while not frontier.is_empty():
var current := frontier.pop_front()
var current: int = frontier.pop_front()
for neighbor in adjacency.get(current, []):
if not distances.has(neighbor):
distances[neighbor] = distances[current] + 1
@@ -61,7 +61,7 @@ func farthest_tree_room(start_index: int) -> int:
var farthest_index := start_index
var farthest_distance := -1
for room_index in range(distances.size()):
var distance := distances.get(room_index, -1)
var distance: int = distances.get(room_index, -1)
if distance > farthest_distance:
farthest_index = room_index
farthest_distance = distance
+2 -2
View File
@@ -25,7 +25,7 @@ static func events(catalog: ContentCatalog) -> Array[Dictionary]:
return _definitions(catalog, &"event")
static func npc_for_role(catalog: ContentCatalog, role: StringName) -> Dictionary:
var preferred_id := {
var preferred_id: StringName = {
&"shop": &"npc_wandering_merchant",
&"guild": &"npc_guild_keeper",
&"sanctuary": &"npc_shelter_survivor",
@@ -39,7 +39,7 @@ static func npc_for_role(catalog: ContentCatalog, role: StringName) -> Dictionar
return available[0] if not available.is_empty() else {}
static func event_for_role(catalog: ContentCatalog, role: StringName) -> Dictionary:
var preferred_id := {
var preferred_id: StringName = {
&"narrative": &"event_narrative_note",
&"mystery": &"event_vending_machine",
&"puzzle": &"event_puzzle_pressure_plates",
+43
View File
@@ -0,0 +1,43 @@
class_name SurfaceGenerator
extends RefCounted
const GridMapStateType = preload("res://scripts/domain/grid_map_state.gd")
const FloorStateType = preload("res://scripts/domain/world/floor_state.gd")
const ActorStateType = preload("res://scripts/domain/actor_state.gd")
# Floor zero deliberately remains an authored tutorial surface. Its geometry is
# not derived from the run seed; RunState supplies persistence by caching it.
static func generate(_seed: String = "") -> FloorState:
var map := GridMapStateType.new(Vector2i(30, 20), GridMapStateType.CellKind.WALL)
_carve_room(map, Rect2i(2, 12, 6, 5))
_carve_room(map, Rect2i(2, 4, 7, 7))
_carve_room(map, Rect2i(10, 2, 10, 6))
_carve_room(map, Rect2i(21, 5, 7, 8))
_carve_vertical_corridor(map, 4, 10, 12)
_carve_horizontal_corridor(map, 8, 10, 6)
_carve_horizontal_corridor(map, 18, 21, 6)
_carve_vertical_corridor(map, 18, 4, 6)
map.set_cell(Vector2i(4, 11), GridMapStateType.CellKind.CLOSED_DOOR)
map.set_cell(Vector2i(4, 7), GridMapStateType.CellKind.CHEST)
map.set_cell(Vector2i(18, 4), GridMapStateType.CellKind.STAIRS)
var floor := FloorStateType.new(map, 0, 0)
floor.entrance = Vector2i(4, 12)
floor.exit = Vector2i(18, 4)
floor.enemies[&"goblin"] = ActorStateType.new(&"goblin", Vector2i(24, 8), 6, 2)
floor.chests[Vector2i(4, 7)] = {"opened": false}
floor.metadata = {"hand_authored": true, "theme": "surface"}
return floor
static func _carve_room(map: GridMapState, room: Rect2i) -> void:
for y in range(room.position.y, room.end.y):
for x in range(room.position.x, room.end.x):
map.set_cell(Vector2i(x, y), GridMapStateType.CellKind.FLOOR)
static func _carve_horizontal_corridor(map: GridMapState, from_x: int, to_x: int, y: int) -> void:
for x in range(from_x, to_x + 1):
map.set_cell(Vector2i(x, y), GridMapStateType.CellKind.FLOOR)
static func _carve_vertical_corridor(map: GridMapState, x: int, from_y: int, to_y: int) -> void:
for y in range(from_y, to_y + 1):
map.set_cell(Vector2i(x, y), GridMapStateType.CellKind.FLOOR)
@@ -0,0 +1 @@
uid://cieqsjogiiein
+93 -11
View File
@@ -14,6 +14,8 @@ const GameEventType = preload("res://scripts/domain/run/game_event.gd")
const PlayerActionType = preload("res://scripts/domain/run/player_action.gd")
const ActionRouterType = preload("res://scripts/game/action_router.gd")
const ActorViewType = preload("res://scripts/presentation/actor_view.gd")
const ContentCatalogType = preload("res://scripts/domain/content/content_catalog.gd")
const FloorTransitionType = preload("res://scripts/domain/run/floor_transition.gd")
@onready var event_presenter: EventPresenter = $EventPresenter
@onready var map_renderer: MapRenderer = $World/MapRenderer
@onready var player_view: ActorView = $World/Player
@@ -29,6 +31,7 @@ var action_router: ActionRouter
var pending_run_settings: RunSettings
var pending_player_name := "Sans-Nom"
var pending_base_archetype: StringName = &"vanguard"
var floor_transition: FloorTransition
func configure_new_run(settings: RunSettings, player_name: String, base_archetype: StringName) -> void:
pending_run_settings = settings
@@ -46,7 +49,7 @@ func _ready() -> void:
player_view.set_actor(game_state.player)
_configure_camera()
_sync_enemy_views()
hud.refresh(game_state)
hud.refresh(game_state, [], run_state)
audio_library.set_ambience_context("exploration")
var capture_mode := _get_capture_mode()
if not capture_mode.is_empty():
@@ -64,7 +67,10 @@ func _initialize_run_state() -> void:
run_state = RunStateType.new(settings.seed, settings)
run_state.player_name = pending_player_name
run_state.base_archetype = pending_base_archetype
game_state.bind_run_state(run_state)
floor_transition = FloorTransitionType.new(ContentCatalogType.load_from_directory("res://data/ascii"))
var initial_floor := floor_transition.initial_floor(run_state)
game_state.set_floor_state(initial_floor)
game_state.player.cell = initial_floor.entrance
if pending_run_settings != null:
var game_started := GameEventType.new(
run_state.next_turn(),
@@ -110,6 +116,9 @@ func _prepare_exit_capture_state() -> void:
game_state.map.set_cell(Vector2i(4, 10), GridMapStateType.CellKind.FLOOR)
game_state.map.set_cell(Vector2i(4, 7), GridMapStateType.CellKind.FLOOR)
game_state.player.cell = Vector2i(18, 4)
# The exit capture represents a reached stair route; make the B6 gate
# eligible so the visual fixture remains valid without weakening gameplay.
run_state.current_floor_deadline().turns_remaining = FloorDeadline.STAIRS_OPEN_DAYS_BEFORE_COLLAPSE * FloorDeadline.TURNS_PER_DAY
_process_interact()
_sync_camera_to_player()
@@ -134,6 +143,9 @@ func submit_player_action(action: PlayerAction) -> Array[GameEvent]:
&"interact":
last_turn_results = _process_interact()
return run_state.recent_events(last_turn_results.size())
&"rest":
last_turn_results = _process_rest()
return run_state.recent_events(last_turn_results.size())
_:
last_turn_results = []
return _record_unavailable_action(action)
@@ -153,7 +165,7 @@ func _record_unavailable_action(action: PlayerAction) -> Array[GameEvent]:
run_state.append_events(events)
event_presenter.enqueue(events)
event_presenter.present_next()
hud.refresh(game_state, run_state.recent_events(run_state.log.size()))
hud.refresh(game_state, run_state.recent_events(run_state.log.size()), run_state)
return events
func get_game_state() -> GameState:
@@ -170,16 +182,86 @@ func get_actor_cell_rect(actor_id: StringName) -> Rect2:
return Rect2()
func _process_interact() -> Array[TurnResult]:
if game_state.get_context_target() == &"exit_reached":
return _refresh_hud_for_context()
return _resolve_player_action(game_state.try_interact(), false)
if _is_down_stairs() and not run_state.current_floor_deadline().can_descend():
var deadline := run_state.current_floor_deadline()
var blocked := _deadline_result(
&"stairs_refused",
"Les escaliers refusent de s’activer : encore %d jour(s) avant leur ouverture." % deadline.days_until_stairs_open()
)
_resolve_player_action([blocked], false)
return [blocked]
if _is_bed():
return _process_rest()
var results := game_state.try_interact()
_resolve_player_action(results, false)
if not results.is_empty() and results[0].kind == &"stairs_used":
_transition_floor(results[0].from_cell)
return results
func _refresh_hud_for_context() -> Array[TurnResult]:
hud.refresh(game_state, run_state.recent_events(run_state.log.size()))
return []
func _process_rest() -> Array[TurnResult]:
if not _is_bed():
var refused := _deadline_result(&"rest_refused", "Il faut un lit pour se reposer. Cherchez-en un dans une salle sécurisée.")
_resolve_player_action([refused], false)
return [refused]
var deadline := run_state.current_floor_deadline()
var deadline_events := deadline.rest()
var message := "Vous vous reposez. -1 jour avant l’effondrement de l’étage."
if deadline_events.has(&"floor_collapsed"):
message += " L’étage commence à s’effondrer !"
elif deadline_events.has(&"deadline_warning"):
message += " Compte à rebours critique."
var result := _deadline_result(&"rested", message)
_resolve_player_action([result], false)
return [result]
func advance_floor_deadline(seconds: float) -> Array[TurnResult]:
var deadline := run_state.current_floor_deadline()
var deadline_events := deadline.advance_real_seconds(seconds)
var results: Array[TurnResult] = []
if deadline_events.has(&"deadline_day_elapsed"):
results.append(_deadline_result(&"deadline_day_elapsed", "Une heure de jeu s’est écoulée : un jour de moins avant l’effondrement."))
if deadline_events.has(&"deadline_warning"):
results.append(_deadline_result(&"deadline_warning", "Compte à rebours critique : cet étage va bientôt s’effondrer."))
if deadline_events.has(&"floor_collapsed"):
results.append(_deadline_result(&"floor_collapsed", "Le compte à rebours est écoulé. L’étage commence à s’effondrer !"))
if not results.is_empty():
_resolve_player_action(results, false)
return results
func _is_down_stairs() -> bool:
return game_state.map.get_cell(game_state.player.cell) == GridMapStateType.CellKind.STAIRS and not (game_state.floor_state.floor_number > 0 and game_state.player.cell == game_state.floor_state.entrance)
func _is_bed() -> bool:
return game_state.map.get_cell(game_state.player.cell) == GridMapStateType.CellKind.BED
func _deadline_result(kind: StringName, message: String) -> TurnResult:
return TurnResult.new(game_state.player.id, kind, game_state.player.cell, game_state.player.cell, &"", 0, message)
func _transition_floor(stairs_cell: Vector2i) -> void:
var transition := floor_transition.transition(run_state, game_state.floor_state, stairs_cell)
var destination: FloorState = transition["floor"]
game_state.set_floor_state(destination)
game_state.player.cell = transition["arrival"]
game_state.update_exploration()
map_renderer.set_map(game_state.map)
_sync_map_renderer_visibility()
player_view.set_actor(game_state.player)
_sync_camera_to_player()
_sync_enemy_views()
hud.refresh(game_state, run_state.recent_events(run_state.log.size()), run_state)
func _process_action(direction: Vector2i) -> Array[TurnResult]:
return _resolve_player_action(game_state.try_player_action(direction), true)
var results := game_state.try_player_action(direction)
_append_collapse_damage(results)
return _resolve_player_action(results, true)
func _append_collapse_damage(results: Array[TurnResult]) -> void:
var deadline := run_state.current_floor_deadline()
if deadline.tick() != &"collapse_damage":
return
var damage := mini(FloorDeadline.COLLAPSE_DAMAGE_PER_TURN, game_state.player.hit_points)
game_state.player.hit_points = maxi(0, game_state.player.hit_points - damage)
results.append(TurnResult.new(game_state.player.id, &"collapse_damage", game_state.player.cell, game_state.player.cell, &"", damage, "L’étage s’effondre autour de vous ! -%d PV." % damage))
# TurnResult remains the public prototype seam. RunState is the authoritative
# journal: results from one resolved player action are converted and appended once,
@@ -193,7 +275,7 @@ func _resolve_player_action(results: Array[TurnResult], sync_camera: bool) -> Ar
var events := _record_events(results)
event_presenter.enqueue(events)
event_presenter.present_next()
hud.refresh(game_state, run_state.recent_events(run_state.log.size()))
hud.refresh(game_state, run_state.recent_events(run_state.log.size()), run_state)
return results
func _record_events(results: Array[TurnResult]) -> Array[GameEvent]:
@@ -53,7 +53,7 @@ static func _load_file(path: String, relative_path: String, result: Dictionary)
if file == null:
result.diagnostics.append("Unable to read content file: %s" % relative_path)
return
var parsed := JSON.parse_string(file.get_as_text())
var parsed: Variant = JSON.parse_string(file.get_as_text())
if parsed == null:
result.diagnostics.append("Invalid JSON content file: %s" % relative_path)
return
+27 -1
View File
@@ -4,18 +4,24 @@ extends CanvasLayer
const DOOR_PROMPT := "Espace — Ouvrir la porte"
const CHEST_PROMPT := "Espace — Ouvrir le coffre"
const STAIRS_PROMPT := "Espace — Descendre l’escalier"
const STAIRS_UP_PROMPT := "Espace — Monter l’escalier"
const BED_PROMPT := "H — Se reposer (coûte 1 jour)"
const EXIT_REACHED_PROMPT := "Sortie atteinte — prochain étage bientôt disponible"
@onready var player_health_label: Label = $PlayerHealthLabel
@onready var deadline_label: Label = $DeadlineLabel
@onready var enemy_health_label: Label = $EnemyHealthLabel
@onready var combat_summary_label: Label = $CombatSummaryLabel
@onready var event_log: RichTextLabel = $EventLog
@onready var context_prompt_label: Label = $ContextPromptLabel
var combat_summary := ""
var _state: GameState
var _run_state: RunState
func refresh(state: GameState, events: Array[GameEvent] = []) -> void:
func refresh(state: GameState, events: Array[GameEvent] = [], run_state: RunState = null) -> void:
_state = state
if run_state != null:
_run_state = run_state
player_health_label.text = "Player HP: %d/%d" % [state.player.hit_points, state.player.max_hit_points]
if state.enemies.has(&"goblin"):
var goblin: ActorState = state.enemies[&"goblin"]
@@ -25,6 +31,7 @@ func refresh(state: GameState, events: Array[GameEvent] = []) -> void:
enemy_health_label.text = "No active target"
combat_summary = "No active target"
combat_summary_label.text = combat_summary
deadline_label.text = _deadline_status()
context_prompt_label.text = get_context_prompt()
# The supplied RunState journal events are the only source for journal text.
event_log.clear()
@@ -40,8 +47,27 @@ func get_context_prompt() -> String:
&"closed_door":
return DOOR_PROMPT
&"stairs":
if _state.floor_state.floor_number > 0 and _state.player.cell == _state.floor_state.entrance:
return STAIRS_UP_PROMPT
if _run_state != null:
var deadline := _run_state.current_floor_deadline()
if not deadline.can_descend():
return "Escaliers verrouillés — encore %d jour(s) avant l’ouverture" % deadline.days_until_stairs_open()
return STAIRS_PROMPT
&"bed":
return BED_PROMPT
&"exit_reached":
return EXIT_REACHED_PROMPT
_:
return ""
func _deadline_status() -> String:
if _run_state == null:
return ""
var deadline := _run_state.current_floor_deadline()
var status := "Étage %d — %d jour(s) avant l’effondrement" % [_run_state.current_floor, deadline.remaining_days()]
if deadline.collapsing:
return status + " — EFFONDREMENT"
if deadline.can_descend():
return status + " — escaliers ouverts"
return status + " — escaliers dans %d jour(s)" % deadline.days_until_stairs_open()
+2
View File
@@ -14,6 +14,8 @@ const TEXTURES := {
GridMapStateType.CellKind.CLOSED_DOOR: preload("res://assets/dcss/closed_door.png"),
GridMapStateType.CellKind.CHEST: preload("res://assets/dcss/chest.png"),
GridMapStateType.CellKind.STAIRS: preload("res://assets/dcss/stairs.png"),
# B6 has no distinct bed sprite yet; a bed remains visibly traversable.
GridMapStateType.CellKind.BED: preload("res://assets/dcss/floor.png"),
}
var map: GridMapState
+4 -1
View File
@@ -41,9 +41,12 @@ func test_real_input_opens_door_then_chest_and_preserves_stairs_route() -> void:
for keycode in [KEY_UP, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_UP, KEY_UP]:
game._unhandled_input(_key_event(keycode))
assert_eq(state.player.cell, Vector2i(18, 4))
game.get_run_state().current_floor_deadline().turns_remaining = 2 * FloorDeadline.TURNS_PER_DAY
hud.refresh(state, [], game.get_run_state())
assert_eq(prompt_label.text, "Espace — Descendre l’escalier")
game._unhandled_input(_key_event(KEY_SPACE))
assert_true(state.exit_reached)
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_string_contains(event_log.get_parsed_text(), "You descend the stairs.")
func _key_event(keycode: Key) -> InputEventKey:
+10 -8
View File
@@ -8,7 +8,7 @@ func before_each() -> void:
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:
func test_real_input_event_completes_door_to_stairs_descent_and_arrives_on_floor_one() -> 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
@@ -27,18 +27,20 @@ func test_real_input_event_completes_door_to_stairs_exit_without_replacing_the_c
game._unhandled_input(_key_event(keycode))
assert_eq(state.player.cell, Vector2i(18, 4))
game.get_run_state().current_floor_deadline().turns_remaining = 2 * FloorDeadline.TURNS_PER_DAY
hud.refresh(state, [], game.get_run_state())
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_eq(game.get_run_state().current_floor, 1)
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 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(18, 4)), GridMapState.CellKind.STAIRS)
assert_eq(state.player.cell, Vector2i(18, 4))
assert_ne(state.map, initial_map)
assert_ne(state.map.size, initial_map_size)
assert_eq(initial_map.get_cell(Vector2i(18, 4)), GridMapState.CellKind.STAIRS)
assert_eq(state.player.cell, state.floor_state.entrance)
func _key_event(keycode: Key) -> InputEventKey:
var event := InputEventKey.new()
+5 -3
View File
@@ -31,13 +31,15 @@ func test_real_game_exposes_door_and_stairs_prompts_with_help_and_event_log() ->
state.map.set_cell(Vector2i(4, 11), GridMapState.CellKind.FLOOR)
state.player.cell = Vector2i(18, 4)
hud.refresh(state)
game.get_run_state().current_floor_deadline().turns_remaining = 2 * FloorDeadline.TURNS_PER_DAY
hud.refresh(state, [], game.get_run_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")
assert_eq(game.get_run_state().current_floor, 1)
assert_eq(hud.get_context_prompt(), "Espace — Monter l’escalier")
assert_eq(prompt_label.text, "Espace — Monter l’escalier")
var results := game.submit_test_action(Vector2i.LEFT)
assert_eq(results[0].kind, &"moved")
+68
View File
@@ -0,0 +1,68 @@
extends GutTest
const MainMenuScene = preload("res://scenes/menu/MainMenu.tscn")
var menu: MainMenu
func before_each() -> void:
menu = MainMenuScene.instantiate()
add_child_autofree(menu)
await get_tree().process_frame
await get_tree().process_frame
func test_actual_menu_new_run_descends_to_generated_floor_one_and_returns_to_surface() -> void:
await _click_button(menu.get_node("Menu/Layout/NewRunButton") as Button)
var creation := menu.get_node("CharacterCreation") as CharacterCreation
(creation.get_node("Panel/Layout/Fields/SeedEdit") as LineEdit).text = "B5-MENU-E2E"
await _click_button(creation.get_node("Panel/Layout/Actions/StartRunButton") as Button)
await get_tree().process_frame
var game := menu.get_node("Game") as Game
assert_not_null(game)
assert_eq(game.get_run_state().current_floor, 0)
var surface := game.get_game_state().floor_state
assert_true(surface.metadata.get("hand_authored", false))
game.get_game_state().player.cell = surface.exit
game.get_run_state().current_floor_deadline().turns_remaining = 2 * FloorDeadline.TURNS_PER_DAY
game.submit_test_interact()
await get_tree().process_frame
var first_floor := game.get_game_state().floor_state
assert_eq(game.get_run_state().current_floor, 1)
assert_false(first_floor.metadata.get("hand_authored", false))
assert_eq(game.get_game_state().player.cell, first_floor.entrance)
assert_eq(first_floor.map.get_cell(first_floor.entrance), GridMapState.CellKind.STAIRS)
assert_eq((game.get_node("HUD") as GameHud).get_context_prompt(), "Espace — Monter l’escalier")
game.get_game_state().player.cell = first_floor.entrance
game.submit_test_interact()
await get_tree().process_frame
assert_string_contains((game.get_node("HUD/EventLog") as RichTextLabel).get_parsed_text(), "You ascend the stairs.")
assert_eq(game.get_run_state().current_floor, 0)
assert_same(game.get_game_state().floor_state, surface)
assert_eq(game.get_game_state().player.cell, surface.exit)
func _click_button(button: Button) -> void:
assert_not_null(button)
assert_true(button.visible)
var click_position := button.get_global_rect().get_center()
get_tree().root.push_input(_mouse_motion_event(click_position), true)
await get_tree().process_frame
get_tree().root.push_input(_mouse_button_event(click_position, true), true)
await get_tree().process_frame
get_tree().root.push_input(_mouse_button_event(click_position, false), true)
await get_tree().process_frame
func _mouse_motion_event(position: Vector2) -> InputEventMouseMotion:
var event := InputEventMouseMotion.new()
event.position = position
event.global_position = position
return event
func _mouse_button_event(position: Vector2, pressed: bool) -> InputEventMouseButton:
var event := InputEventMouseButton.new()
event.position = position
event.global_position = position
event.button_index = MOUSE_BUTTON_LEFT
event.button_mask = MOUSE_BUTTON_MASK_LEFT if pressed else 0
event.pressed = pressed
return event
@@ -0,0 +1 @@
uid://ctrkpp7a6m58j
+40
View File
@@ -0,0 +1,40 @@
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_game_early_down_stairs_are_blocked_then_rest_makes_descent_eligible() -> 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 log := game.get_node("HUD/EventLog") as RichTextLabel
state.enemies.clear()
state.player.cell = state.floor_state.exit
assert_string_contains(hud.get_context_prompt(), "encore 13 jour")
game._unhandled_input(_key_event(KEY_E))
assert_eq(game.get_run_state().current_floor, 0)
assert_eq(prompt_label.text, hud.get_context_prompt())
assert_string_contains(log.get_parsed_text(), "Les escaliers refusent")
assert_string_contains(log.get_parsed_text(), "13 jour")
game.advance_floor_deadline(13 * FloorDeadline.REAL_SECONDS_PER_DAY)
assert_eq(game.get_run_state().deadline_for(0).remaining_days(), 2)
assert_eq(hud.get_context_prompt(), "Espace — Descendre l’escalier")
game._unhandled_input(_key_event(KEY_E))
assert_eq(game.get_run_state().current_floor, 1)
assert_eq(state.player.cell, state.floor_state.entrance)
assert_eq(hud.get_context_prompt(), "Espace — Monter l’escalier")
func _key_event(keycode: Key) -> InputEventKey:
var event := InputEventKey.new()
event.keycode = keycode
event.physical_keycode = keycode
event.pressed = true
return event
+1
View File
@@ -0,0 +1 @@
uid://br1b1ews1owee
+106
View File
@@ -0,0 +1,106 @@
extends GutTest
const RunSettingsType = preload("res://scripts/domain/run/run_settings.gd")
const RunStateType = preload("res://scripts/domain/run/run_state.gd")
const FloorDeadlinePath := "res://scripts/domain/run/floor_deadline.gd"
func test_ascii_deadline_days_increase_by_five_for_each_dungeon_floor() -> void:
var deadline_script := load(FloorDeadlinePath)
assert_not_null(deadline_script, "B6 must provide the per-floor deadline domain model")
if deadline_script == null:
return
var first_floor = deadline_script.new(1)
var second_floor = deadline_script.new(2)
assert_eq(first_floor.turns_remaining, 15 * first_floor.TURNS_PER_DAY)
assert_eq(second_floor.turns_remaining, 20 * second_floor.TURNS_PER_DAY)
assert_eq(first_floor.remaining_days(), 15)
func test_rest_costs_one_day_warns_once_and_deadline_then_collapses() -> void:
var deadline_script := load(FloorDeadlinePath)
assert_not_null(deadline_script, "B6 must provide rest/deadline rules")
if deadline_script == null:
return
var deadline = deadline_script.new(1)
deadline.turns_remaining = 2 * deadline.TURNS_PER_DAY
var rest_events: Array[StringName] = deadline.rest()
assert_eq(deadline.turns_remaining, deadline.TURNS_PER_DAY)
assert_has(rest_events, &"deadline_warning")
assert_false(deadline.collapsing)
var collapse_events: Array[StringName] = deadline.rest()
assert_eq(deadline.turns_remaining, 0)
assert_true(deadline.collapsing)
assert_has(collapse_events, &"floor_collapsed")
assert_eq(deadline.tick(), &"collapse_damage")
func test_explicit_real_time_seam_consumes_only_full_days_and_opens_stairs_at_two_days() -> void:
var deadline_script := load(FloorDeadlinePath)
assert_not_null(deadline_script, "B6 must provide a deterministic real-time seam")
if deadline_script == null:
return
var deadline = deadline_script.new(1)
deadline.advance_real_seconds(deadline.REAL_SECONDS_PER_DAY * 12 + deadline.REAL_SECONDS_PER_DAY - 1)
assert_eq(deadline.remaining_days(), 3)
assert_false(deadline.can_descend())
deadline.advance_real_seconds(1)
assert_eq(deadline.remaining_days(), 2)
assert_true(deadline.can_descend())
func test_rest_requires_a_bed_and_bed_interaction_consumes_one_day() -> void:
var game_scene := preload("res://scenes/Game.tscn")
var game := game_scene.instantiate() as Game
add_child_autofree(game)
await get_tree().process_frame
var state := game.get_game_state()
var deadline := game.get_run_state().current_floor_deadline()
var before := deadline.turns_remaining
game._unhandled_input(_key_event(KEY_H))
assert_eq(deadline.turns_remaining, before)
assert_string_contains((game.get_node("HUD/EventLog") as RichTextLabel).get_parsed_text(), "Il faut un lit")
state.map.set_cell(state.player.cell, GridMapState.CellKind.BED)
game._unhandled_input(_key_event(KEY_E))
assert_eq(deadline.turns_remaining, before - FloorDeadline.BED_REST_DAY_COST * FloorDeadline.TURNS_PER_DAY)
assert_string_contains((game.get_node("HUD/EventLog") as RichTextLabel).get_parsed_text(), "Vous vous reposez")
func test_collapse_damages_the_player_on_the_next_gameplay_action() -> void:
var game_scene := preload("res://scenes/Game.tscn")
var game := game_scene.instantiate() as Game
add_child_autofree(game)
await get_tree().process_frame
var state := game.get_game_state()
state.enemies.clear()
var deadline := game.get_run_state().current_floor_deadline()
deadline.turns_remaining = 0
deadline.collapsing = true
var before := state.player.hit_points
game.submit_test_action(Vector2i.RIGHT)
assert_eq(state.player.hit_points, before - FloorDeadline.COLLAPSE_DAMAGE_PER_TURN)
assert_string_contains((game.get_node("HUD/EventLog") as RichTextLabel).get_parsed_text(), "L’étage s’effondre")
func test_run_state_keeps_independent_deadline_state_for_each_floor() -> void:
var deadline_script := load(FloorDeadlinePath)
assert_not_null(deadline_script, "B6 must persist deadline state in RunState by floor")
if deadline_script == null:
return
var run := RunStateType.new("B6-persistence", RunSettingsType.new("B6-persistence"))
var first = run.ensure_floor_deadline(1)
first.rest()
var second = run.ensure_floor_deadline(2)
assert_same(run.deadline_for(1), first)
assert_eq(run.deadline_for(1).remaining_days(), 14)
assert_eq(second.remaining_days(), 20)
func _key_event(keycode: Key) -> InputEventKey:
var event := InputEventKey.new()
event.keycode = keycode
event.physical_keycode = keycode
event.pressed = true
return event
+1
View File
@@ -0,0 +1 @@
uid://bv747te1tt53k
+2 -1
View File
@@ -22,7 +22,8 @@ func test_context_prompt_describes_stairs_under_player_and_nothing_else() -> voi
state.map.set_cell(Vector2i(4, 11), GridMapState.CellKind.FLOOR)
state.player.cell = Vector2i(18, 4)
hud.refresh(state)
game.get_run_state().current_floor_deadline().turns_remaining = 2 * FloorDeadline.TURNS_PER_DAY
hud.refresh(state, [], game.get_run_state())
assert_eq(hud.get_context_prompt(), "Espace — Descendre l’escalier")
state.map.set_cell(state.player.cell, GridMapState.CellKind.FLOOR)
+6 -4
View File
@@ -48,7 +48,7 @@ func test_stairs_usage_triggers_exactly_one_enemy_response_without_transitioning
assert_eq(state.player.cell, stairs)
assert_same(state.map, map)
func test_stairs_usage_refreshes_exact_exit_prompt_and_writes_the_journal() -> void:
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
@@ -58,11 +58,13 @@ func test_stairs_usage_refreshes_exact_exit_prompt_and_writes_the_journal() -> v
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_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_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.")
@@ -0,0 +1,66 @@
extends GutTest
const ContentCatalogType = preload("res://scripts/domain/content/content_catalog.gd")
const SurfaceGeneratorType = preload("res://scripts/domain/world/surface_generator.gd")
const FloorTransitionType = preload("res://scripts/domain/run/floor_transition.gd")
const RunStateType = preload("res://scripts/domain/run/run_state.gd")
const GridMapStateType = preload("res://scripts/domain/grid_map_state.gd")
const ASCII_CATALOG_PATH := "res://data/ascii"
func test_floor_zero_is_hand_authored_and_floor_one_is_seed_floor_one_procedural() -> void:
var catalog := ContentCatalogType.load_from_directory(ASCII_CATALOG_PATH)
var run := RunStateType.new("B5-surface-contract")
var transitions := FloorTransitionType.new(catalog)
var surface := transitions.initial_floor(run)
var descend := transitions.transition(run, surface, surface.exit)
var first_floor: FloorState = descend["floor"]
assert_eq(surface.floor_number, 0)
assert_true(surface.metadata.get("hand_authored", false))
assert_eq(surface.map.size, Vector2i(30, 20))
assert_eq(surface.entrance, Vector2i(4, 12))
assert_eq(surface.exit, Vector2i(18, 4))
assert_eq(surface.map.get_cell(surface.exit), GridMapStateType.CellKind.STAIRS)
assert_eq(first_floor.floor_number, 1)
assert_false(first_floor.metadata.get("hand_authored", false))
assert_eq(first_floor.seed, _seed_value("B5-surface-contract", 1))
assert_eq(first_floor.map.get_cell(first_floor.entrance), GridMapStateType.CellKind.STAIRS)
assert_eq(first_floor.map.get_cell(first_floor.exit), GridMapStateType.CellKind.STAIRS)
assert_eq(descend["arrival"], first_floor.entrance)
var independently_authored := SurfaceGeneratorType.generate("another-seed")
assert_eq(independently_authored.to_dict(), surface.to_dict(), "floor zero is authored rather than seed-generated")
func test_transition_cache_keeps_mutated_floor_state_and_arrival_cells_across_return_trip() -> void:
var catalog := ContentCatalogType.load_from_directory(ASCII_CATALOG_PATH)
var run := RunStateType.new("B5-cache-contract")
var transitions := FloorTransitionType.new(catalog)
var surface := transitions.initial_floor(run)
var first_descent := transitions.transition(run, surface, surface.exit)
var first_floor: FloorState = first_descent["floor"]
first_floor.chests[Vector2i(3, 3)] = {"opened": true}
first_floor.enemies.clear()
first_floor.events.append({"id": "first-floor-event", "resolved": true})
var ascent := transitions.transition(run, first_floor, first_floor.entrance)
var returned_surface: FloorState = ascent["floor"]
returned_surface.map.set_cell(Vector2i(4, 7), GridMapStateType.CellKind.FLOOR)
var second_descent := transitions.transition(run, returned_surface, returned_surface.exit)
var cached_first_floor: FloorState = second_descent["floor"]
assert_same(returned_surface, surface)
assert_eq(ascent["arrival"], surface.exit)
assert_same(cached_first_floor, first_floor)
assert_eq(second_descent["arrival"], first_floor.entrance)
assert_eq(cached_first_floor.chests[Vector2i(3, 3)], {"opened": true})
assert_eq(cached_first_floor.enemies.size(), 0)
assert_true(cached_first_floor.events.has({"id": "first-floor-event", "resolved": true}))
assert_eq(surface.map.get_cell(Vector2i(4, 7)), GridMapStateType.CellKind.FLOOR)
func _seed_value(seed: String, floor_number: int) -> int:
var value := 0
for index in range(seed.length()):
value = (value * 31 + seed.unicode_at(index)) % 2147483647
return value + floor_number
@@ -0,0 +1 @@
uid://20vpsc7klakm