feat: complete graphical feedback pass

This commit is contained in:
goose
2026-10-04 00:17:33 -04:00
parent 408dc82f4e
commit ad10e99de9
12 changed files with 315 additions and 2 deletions
+9 -1
View File
@@ -1,4 +1,4 @@
[gd_scene load_steps=17 format=3]
[gd_scene load_steps=19 format=3]
[ext_resource type="Script" path="res://scripts/game/game.gd" id="1_game"]
[ext_resource type="Script" path="res://scripts/presentation/map_renderer.gd" id="2_map"]
@@ -8,6 +8,8 @@
[ext_resource type="Script" path="res://scripts/infrastructure/audio_library.gd" id="6_audio"]
[ext_resource type="Script" path="res://scripts/presentation/event_presenter.gd" id="7_presenter"]
[ext_resource type="PackedScene" path="res://scenes/overlays/CombatFeedback.tscn" id="8_feedback"]
[ext_resource type="Script" path="res://scripts/presentation/door_chest_feedback.gd" id="31_door_chest_feedback"]
[ext_resource type="Script" path="res://scripts/presentation/loot_feedback.gd" id="32_loot_feedback"]
[ext_resource type="PackedScene" path="res://scenes/overlays/TargetingOverlay.tscn" id="9_targeting"]
[ext_resource type="PackedScene" path="res://scenes/overlays/SpellTargetingOverlay.tscn" id="10_spell_targeting"]
[ext_resource type="PackedScene" path="res://scenes/ui/LootPanel.tscn" id="11_loot"]
@@ -70,6 +72,12 @@ script = ExtResource("7_presenter")
[node name="CombatFeedback" parent="EventPresenter" instance=ExtResource("8_feedback")]
[node name="DoorChestFeedback" type="Node2D" parent="EventPresenter"]
script = ExtResource("31_door_chest_feedback")
[node name="LootFeedback" type="Node" parent="EventPresenter"]
script = ExtResource("32_loot_feedback")
[node name="World" type="Node2D" parent="."]
position = Vector2(32, 48)
@@ -0,0 +1,43 @@
class_name DoorChestFeedback
extends Node2D
const EFFECT_DURATION_MS := 160
const EFFECT_DURATION := float(EFFECT_DURATION_MS) / 1000.0
const DOOR_COLOR := Color(0.48, 0.8, 1.0, 1.0)
const CHEST_COLOR := Color(1.0, 0.8, 0.3, 1.0)
var _test_mode := false
var _last_feedback_state := {}
func _enter_tree() -> void:
_test_mode = "--test-mode" in OS.get_cmdline_user_args() and not Engine.is_editor_hint()
func set_test_mode_for_testing(enabled: bool) -> void:
_test_mode = enabled
func get_last_feedback_state() -> Dictionary:
return _last_feedback_state.duplicate()
func begin(event: GameEvent, presentation_kind: StringName) -> void:
var color := DOOR_COLOR if presentation_kind == &"door" else CHEST_COLOR
_last_feedback_state = {
"kind": presentation_kind,
"duration_ms": EFFECT_DURATION_MS,
"color": color,
}
if _test_mode:
return
var marker := Polygon2D.new()
marker.polygon = PackedVector2Array([Vector2(0, -10), Vector2(10, 0), Vector2(0, 10), Vector2(-10, 0)])
marker.color = color
marker.position = Vector2(event.cell) * Vector2(32, 32) + Vector2(16, 16)
if get_viewport() != null:
marker.position += get_viewport().get_visible_rect().size * 0.5
marker.z_index = 11
add_child(marker)
var tween := create_tween()
tween.set_parallel(true)
tween.tween_property(marker, "scale", Vector2(1.8, 1.8), EFFECT_DURATION)
tween.tween_property(marker, "modulate:a", 0.0, EFFECT_DURATION)
tween.chain().tween_callback(marker.queue_free)
await tween.finished
@@ -0,0 +1 @@
uid://dd8w2d6h57ult
+75 -1
View File
@@ -2,19 +2,37 @@ class_name EventPresenter
extends Node
signal event_presented(event: GameEvent)
signal presentation_started(presentation: PresentationEvent)
const CombatFeedbackType = preload("res://scripts/presentation/combat_feedback.gd")
const DoorChestFeedbackType = preload("res://scripts/presentation/door_chest_feedback.gd")
const LootFeedbackType = preload("res://scripts/presentation/loot_feedback.gd")
const PresentationEventType = preload("res://scripts/presentation/presentation_event.gd")
const COMBAT_COLOR := Color(1.0, 0.45, 0.45, 1.0)
const SPELL_COLOR := Color(0.72, 0.58, 1.0, 1.0)
const DEATH_COLOR := Color(1.0, 0.38, 0.34, 1.0)
var _queue: Array[GameEvent] = []
var _presenting := false
var _actor_lookup: Callable
@onready var _combat_feedback: CombatFeedback = get_node_or_null("CombatFeedback") as CombatFeedback
@onready var _door_chest_feedback: DoorChestFeedback = get_node_or_null("DoorChestFeedback") as DoorChestFeedback
@onready var _loot_feedback: LootFeedback = get_node_or_null("LootFeedback") as LootFeedback
func _ready() -> void:
if _combat_feedback == null:
_combat_feedback = CombatFeedbackType.new()
_combat_feedback.name = "CombatFeedback"
add_child(_combat_feedback)
if _door_chest_feedback == null:
_door_chest_feedback = DoorChestFeedbackType.new()
_door_chest_feedback.name = "DoorChestFeedback"
add_child(_door_chest_feedback)
if _loot_feedback == null:
_loot_feedback = LootFeedbackType.new()
_loot_feedback.name = "LootFeedback"
add_child(_loot_feedback)
func set_actor_lookup(actor_lookup: Callable) -> void:
_actor_lookup = actor_lookup
@@ -29,12 +47,38 @@ func pending_count() -> int:
func is_test_mode() -> bool:
return _combat_feedback != null and _combat_feedback.is_test_mode()
## Maps a semantic domain event to exactly one presentation event, or null when
## no visual feedback is appropriate. The source event stays immutable.
func map_event(event: GameEvent) -> PresentationEvent:
match event.kind:
&"melee", &"enemy_melee", &"damage_dealt", &"spell_damage_dealt", &"attack_started", &"attack_hit":
return PresentationEventType.new(event, &"combat", event.message, COMBAT_COLOR)
&"door_opened":
return PresentationEventType.new(event, &"door", event.message, DoorChestFeedback.DOOR_COLOR)
&"chest_opened":
return PresentationEventType.new(event, &"chest", event.message, DoorChestFeedback.CHEST_COLOR)
&"loot_dropped", &"loot_taken", &"item_picked_up":
return PresentationEventType.new(event, &"loot", event.message, LootFeedback.LOOT_COLOR)
&"trap_triggered", &"trap_discovered", &"trap_disarmed", &"trap_disarm_failed", &"trap_status_applied":
return PresentationEventType.new(event, &"trap", event.message, LootFeedback.TRAP_COLOR)
&"projectile_fired", &"spell_cast_started", &"spell_effect_applied":
return PresentationEventType.new(event, &"spell", event.message, SPELL_COLOR)
&"quest_started", &"quest_updated", &"quest_completed", &"quest_abandoned", &"quest_board_read":
return PresentationEventType.new(event, &"quest", event.message, LootFeedback.QUEST_COLOR)
&"enemy_defeated", &"actor_died", &"companion_died", &"run_ended", &"permadeath_run_retired":
return PresentationEventType.new(event, &"death", event.message, DEATH_COLOR)
_:
return null
func present_next() -> void:
if _presenting or _queue.is_empty():
return
_presenting = true
var event: GameEvent = _queue.pop_front()
if is_test_mode():
var test_presentation := map_event(event)
if test_presentation != null:
presentation_started.emit(test_presentation)
event_presented.emit(event)
_presenting = false
present_next()
@@ -42,7 +86,37 @@ func present_next() -> void:
_begin_feedback.call_deferred(event)
func _begin_feedback(event: GameEvent) -> void:
await _combat_feedback.begin(event, _actor_lookup)
var presentation := map_event(event)
if presentation != null:
presentation_started.emit(presentation)
await _present(presentation)
event_presented.emit(event)
_presenting = false
present_next()
func _present(presentation: PresentationEvent) -> void:
match presentation.kind:
&"combat", &"death":
await _combat_feedback.begin(presentation.source_event, _actor_lookup)
&"spell":
await _present_spell(presentation.source_event)
&"door", &"chest":
await _door_chest_feedback.begin(presentation.source_event, presentation.kind)
&"loot", &"trap", &"quest":
await _loot_feedback.begin(presentation.source_event, presentation.kind)
func _present_spell(event: GameEvent) -> void:
# A cast has no projectile until a target has been confirmed. This gives each
# spell event a brief, non-blocking cast flash instead of silently doing nothing.
if event.kind == &"spell_cast_started" or event.target_id.is_empty():
await get_tree().create_timer(0.12).timeout
return
await _combat_feedback.begin(event, _actor_lookup)
func get_feedback_metrics() -> Dictionary:
return {
"combat": _combat_feedback != null,
"door_chest": _door_chest_feedback != null,
"loot": _loot_feedback != null,
"mapped_kinds": 8,
}
+55
View File
@@ -0,0 +1,55 @@
class_name LootFeedback
extends Node
const EFFECT_DURATION_MS := 160
const EFFECT_DURATION := float(EFFECT_DURATION_MS) / 1000.0
const LOOT_COLOR := Color(1.0, 0.82, 0.32, 1.0)
const TRAP_COLOR := Color(1.0, 0.38, 0.34, 1.0)
const QUEST_COLOR := Color(0.55, 1.0, 0.67, 1.0)
var _test_mode := false
var _last_feedback_state := {}
func _enter_tree() -> void:
_test_mode = "--test-mode" in OS.get_cmdline_user_args() and not Engine.is_editor_hint()
func set_test_mode_for_testing(enabled: bool) -> void:
_test_mode = enabled
func get_last_feedback_state() -> Dictionary:
return _last_feedback_state.duplicate()
func begin(event: GameEvent, presentation_kind: StringName) -> void:
var color := _color_for(presentation_kind)
_last_feedback_state = {
"kind": presentation_kind,
"duration_ms": EFFECT_DURATION_MS,
"color": color,
}
if _test_mode:
return
var label := Label.new()
label.text = _label_for(event, presentation_kind)
label.modulate = color
label.position = Vector2(390, 80)
label.z_index = 20
add_child(label)
var tween := create_tween()
tween.set_parallel(true)
tween.tween_property(label, "position:y", label.position.y - 14.0, EFFECT_DURATION)
tween.tween_property(label, "modulate:a", 0.0, EFFECT_DURATION)
tween.chain().tween_callback(label.queue_free)
await tween.finished
func _color_for(presentation_kind: StringName) -> Color:
match presentation_kind:
&"trap": return TRAP_COLOR
&"quest": return QUEST_COLOR
_: return LOOT_COLOR
func _label_for(event: GameEvent, presentation_kind: StringName) -> String:
match presentation_kind:
&"loot": return "✦ LOOT SECURED"
&"trap": return "! TRAP"
&"quest": return "✦ QUEST UPDATED"
_: return event.message
@@ -0,0 +1 @@
uid://dolen1gstmp82
@@ -0,0 +1,15 @@
class_name PresentationEvent
extends RefCounted
## A display-only translation of one authoritative GameEvent.
## Presentation consumers must never alter the source domain event or run state.
var source_event: GameEvent
var kind: StringName
var notification: String
var accent: Color
func _init(source: GameEvent, presentation_kind: StringName, text: String = "", color: Color = Color.WHITE) -> void:
source_event = source
kind = presentation_kind
notification = text if not text.is_empty() else source.message
accent = color
@@ -0,0 +1 @@
uid://vgwy34xn5id7
+57
View File
@@ -0,0 +1,57 @@
# G4 — Full visual presentation pass
## Scope
Implemented in the dedicated `slice/g4-presentation-polish` worktree only. No DCWASCII files were read or changed; no remote push or PR was made.
## Root cause
The pre-existing `EventPresenter` queued every `GameEvent` but passed all of them directly to `CombatFeedback`. `CombatFeedback.begin()` only animated movement, projectile/combat impact, and death kinds; door, chest, loot, trap, spell-start, and quest events were intentional no-ops. Consequently, the game had no explicit one-to-one semantic-to-presentation contract, no dedicated feedback views for exploration/narrative outcomes, and no way for a real scene test to observe presentation sequence independently from domain mutation.
## TDD presentation sequence
1. Established the pre-change unit baseline: **185 tests / 1,407 assertions**, passing.
2. Added the red mapping specification for the eight required kinds. Before implementation, the missing `map_event` API made the new test fail to compile/type-check, demonstrating that no mapping contract existed.
3. Added the real `Game.tscn` E2E sequence specification before implementation: combat, door, chest, loot, trap, spell, quest, death must emit exactly one ordered presentation event each.
4. Implemented the display-only mapping and feedback views, then ran unit and E2E suites green.
## Implementation
- Added immutable `PresentationEvent`, which wraps (without mutating) one source `GameEvent`, its feedback kind, notification text, and accent color.
- Extended `EventPresenter` with:
- explicit `map_event()` mapping for the required eight semantic categories;
- a `presentation_started` observation signal;
- queue-preserving dispatch to one appropriate feedback view;
- a structural `get_feedback_metrics()` seam (`mapped_kinds: 8`) without pixel snapshots.
- Added scene-owned feedback views:
- `DoorChestFeedback`: short 160 ms cyan/gold expanding marker;
- `LootFeedback`: short 160 ms gold/red/green floating notification for loot, traps, and quests.
- Kept combat/death in the existing short combat feedback path and gave untargeted spell casts a 120 ms non-blocking cast interval rather than a silent no-op.
- Wired the new views into `scenes/Game.tscn` under `EventPresenter`. Their colors follow the established blue-black dark UI palette and existing readable gold/cyan/red/green semantic accents.
- Added mapping unit coverage and `test_presentation_event_sequence_e2e.gd`, which instantiates the real game scene and asserts the full ordered sequence.
## Verification and capture evidence
`./scripts/verify.sh` passed after the final changes:
| Suite | Result |
| --- | ---: |
| Unit | 186 tests, 1,423 assertions passed |
| Integration | 11 tests, 59,470 assertions passed |
| E2E | 58 tests, 573 assertions passed |
| Visual structural captures | passed |
The existing non-brittle capture checker was run through the full verification command and confirmed both 1280×720 scripted reference scenes:
| Capture | dungeon non-black | visible | explored | unknown | explored luminance | unknown luminance |
| --- | ---: | ---: | ---: | ---: | ---: | ---: |
| `visual-check.png` | 489,308 | 17,524 | 10,438 | 365,325 | 0.012 | 0.001 |
| `visual-check-exit.png` | 489,252 | 17,404 | 17,146 | 439,497 | 0.012 | 0.001 |
These metrics verify the dark-art visibility/fog structure rather than comparing brittle snapshots.
Additional review passed: `git diff --check` reports no whitespace errors.
## Commit / delivery
A local task commit is created after this report. It is intentionally not pushed and no PR is opened.
@@ -0,0 +1,38 @@
extends GutTest
const GameScene = preload("res://scenes/Game.tscn")
const GameEvent = preload("res://scripts/domain/run/game_event.gd")
func test_real_game_scene_presents_one_ordered_feedback_event_for_each_major_domain_kind() -> void:
var game := GameScene.instantiate() as Game
add_child_autofree(game)
await get_tree().process_frame
var presenter := game.get_node("EventPresenter") as EventPresenter
var observed: Array[StringName] = []
presenter.presentation_started.connect(func(presentation: PresentationEvent) -> void:
observed.append(presentation.kind)
)
presenter.get_node("CombatFeedback").set_test_mode_for_testing(true)
presenter.get_node("DoorChestFeedback").set_test_mode_for_testing(true)
presenter.get_node("LootFeedback").set_test_mode_for_testing(true)
presenter.enqueue([
GameEvent.new(1, 0, &"damage_dealt", {"damage": 3}, "You strike.", &"player", &"goblin"),
GameEvent.new(1, 0, &"door_opened", {}, "Door opened.", &"player"),
GameEvent.new(1, 0, &"chest_opened", {}, "Chest opened.", &"player"),
GameEvent.new(1, 0, &"loot_taken", {}, "Loot taken.", &"player"),
GameEvent.new(1, 0, &"trap_triggered", {"damage": 1}, "Trap triggered.", &"player"),
GameEvent.new(1, 0, &"spell_cast_started", {}, "Spell cast.", &"player", &"goblin"),
GameEvent.new(1, 0, &"quest_started", {}, "Quest started.", &"player"),
GameEvent.new(1, 0, &"actor_died", {}, "Goblin defeated.", &"goblin", &"player"),
])
presenter.present_next()
await _wait_until_presented(observed, 8)
assert_eq(observed, [&"combat", &"door", &"chest", &"loot", &"trap", &"spell", &"quest", &"death"])
assert_eq(presenter.pending_count(), 0)
func _wait_until_presented(observed: Array[StringName], expected_count: int) -> void:
var deadline := Time.get_ticks_msec() + 2500
while observed.size() < expected_count and Time.get_ticks_msec() < deadline:
await get_tree().process_frame
@@ -0,0 +1 @@
uid://ng3wx4vhf7uk
+19
View File
@@ -54,3 +54,22 @@ func _wait_for_presented_events(observed: Array[GameEvent], expected_count: int)
var deadline := Time.get_ticks_msec() + 1000
while observed.size() < expected_count and Time.get_ticks_msec() < deadline:
await get_tree().process_frame
func test_major_domain_event_kinds_each_map_to_one_named_presentation_event() -> void:
var presenter := EventPresenter.new()
add_child_autofree(presenter)
var expected := {
&"damage_dealt": &"combat",
&"door_opened": &"door",
&"chest_opened": &"chest",
&"loot_taken": &"loot",
&"trap_triggered": &"trap",
&"spell_cast_started": &"spell",
&"quest_started": &"quest",
&"actor_died": &"death",
}
for domain_kind: StringName in expected:
var mapped: PresentationEvent = presenter.map_event(GameEvent.new(1, 0, domain_kind))
assert_not_null(mapped, "%s should have presentation feedback" % domain_kind)
assert_eq(mapped.kind, expected[domain_kind], "%s should map once to its feedback kind" % domain_kind)