From ad10e99de9b7e119b8887acace9624493613f5b8 Mon Sep 17 00:00:00 2001 From: goose Date: Sun, 4 Oct 2026 00:17:33 -0400 Subject: [PATCH 1/5] feat: complete graphical feedback pass --- scenes/Game.tscn | 10 ++- scripts/presentation/door_chest_feedback.gd | 43 +++++++++++ .../presentation/door_chest_feedback.gd.uid | 1 + scripts/presentation/event_presenter.gd | 76 ++++++++++++++++++- scripts/presentation/loot_feedback.gd | 55 ++++++++++++++ scripts/presentation/loot_feedback.gd.uid | 1 + scripts/presentation/presentation_event.gd | 15 ++++ .../presentation/presentation_event.gd.uid | 1 + task-G4-report.md | 57 ++++++++++++++ .../test_presentation_event_sequence_e2e.gd | 38 ++++++++++ ...est_presentation_event_sequence_e2e.gd.uid | 1 + tests/unit/test_event_presenter.gd | 19 +++++ 12 files changed, 315 insertions(+), 2 deletions(-) create mode 100644 scripts/presentation/door_chest_feedback.gd create mode 100644 scripts/presentation/door_chest_feedback.gd.uid create mode 100644 scripts/presentation/loot_feedback.gd create mode 100644 scripts/presentation/loot_feedback.gd.uid create mode 100644 scripts/presentation/presentation_event.gd create mode 100644 scripts/presentation/presentation_event.gd.uid create mode 100644 task-G4-report.md create mode 100644 tests/e2e/test_presentation_event_sequence_e2e.gd create mode 100644 tests/e2e/test_presentation_event_sequence_e2e.gd.uid diff --git a/scenes/Game.tscn b/scenes/Game.tscn index 178ecf4..3b3438b 100644 --- a/scenes/Game.tscn +++ b/scenes/Game.tscn @@ -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) diff --git a/scripts/presentation/door_chest_feedback.gd b/scripts/presentation/door_chest_feedback.gd new file mode 100644 index 0000000..5e67708 --- /dev/null +++ b/scripts/presentation/door_chest_feedback.gd @@ -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 diff --git a/scripts/presentation/door_chest_feedback.gd.uid b/scripts/presentation/door_chest_feedback.gd.uid new file mode 100644 index 0000000..dad9443 --- /dev/null +++ b/scripts/presentation/door_chest_feedback.gd.uid @@ -0,0 +1 @@ +uid://dd8w2d6h57ult diff --git a/scripts/presentation/event_presenter.gd b/scripts/presentation/event_presenter.gd index 1989c65..d3d6073 100644 --- a/scripts/presentation/event_presenter.gd +++ b/scripts/presentation/event_presenter.gd @@ -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, + } diff --git a/scripts/presentation/loot_feedback.gd b/scripts/presentation/loot_feedback.gd new file mode 100644 index 0000000..0f1d10c --- /dev/null +++ b/scripts/presentation/loot_feedback.gd @@ -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 diff --git a/scripts/presentation/loot_feedback.gd.uid b/scripts/presentation/loot_feedback.gd.uid new file mode 100644 index 0000000..f61385a --- /dev/null +++ b/scripts/presentation/loot_feedback.gd.uid @@ -0,0 +1 @@ +uid://dolen1gstmp82 diff --git a/scripts/presentation/presentation_event.gd b/scripts/presentation/presentation_event.gd new file mode 100644 index 0000000..6f6899f --- /dev/null +++ b/scripts/presentation/presentation_event.gd @@ -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 diff --git a/scripts/presentation/presentation_event.gd.uid b/scripts/presentation/presentation_event.gd.uid new file mode 100644 index 0000000..5042576 --- /dev/null +++ b/scripts/presentation/presentation_event.gd.uid @@ -0,0 +1 @@ +uid://vgwy34xn5id7 diff --git a/task-G4-report.md b/task-G4-report.md new file mode 100644 index 0000000..86c50fe --- /dev/null +++ b/task-G4-report.md @@ -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. diff --git a/tests/e2e/test_presentation_event_sequence_e2e.gd b/tests/e2e/test_presentation_event_sequence_e2e.gd new file mode 100644 index 0000000..8177cca --- /dev/null +++ b/tests/e2e/test_presentation_event_sequence_e2e.gd @@ -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 diff --git a/tests/e2e/test_presentation_event_sequence_e2e.gd.uid b/tests/e2e/test_presentation_event_sequence_e2e.gd.uid new file mode 100644 index 0000000..55f75db --- /dev/null +++ b/tests/e2e/test_presentation_event_sequence_e2e.gd.uid @@ -0,0 +1 @@ +uid://ng3wx4vhf7uk diff --git a/tests/unit/test_event_presenter.gd b/tests/unit/test_event_presenter.gd index 1da01f5..0f7bc63 100644 --- a/tests/unit/test_event_presenter.gd +++ b/tests/unit/test_event_presenter.gd @@ -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) -- 2.54.0 From 0a9b14be26fd239f00e1bf04ae69bb416a04c007 Mon Sep 17 00:00:00 2001 From: goose Date: Sun, 4 Oct 2026 00:40:52 -0400 Subject: [PATCH 2/5] fix: make presentation events immutable --- scripts/presentation/presentation_event.gd | 49 +++++++-- task-G4-report.md | 109 ++++++++++++++------- tests/unit/test_event_presenter.gd | 34 +++++++ 3 files changed, 147 insertions(+), 45 deletions(-) diff --git a/scripts/presentation/presentation_event.gd b/scripts/presentation/presentation_event.gd index 6f6899f..0403db2 100644 --- a/scripts/presentation/presentation_event.gd +++ b/scripts/presentation/presentation_event.gd @@ -1,15 +1,44 @@ 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 +## A display-only, immutable translation of one authoritative GameEvent. +## Getter calls return a fresh source snapshot so presentation code cannot mutate +## the source domain event or this adapter's captured event data. +var _source_event: GameEvent +var _kind: StringName +var _notification: String +var _accent: Color + +var source_event: GameEvent: + get: + return _copy_event(_source_event) + +var kind: StringName: + get: + return _kind + +var notification: String: + get: + return _notification + +var accent: Color: + get: + return _accent 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 + _source_event = _copy_event(source) + _kind = presentation_kind + _notification = text if not text.is_empty() else source.message + _accent = color + +static func _copy_event(event: GameEvent) -> GameEvent: + return GameEvent.new( + event.turn, + event.floor, + event.kind, + event.payload, + event.message, + event.actor_id, + event.target_id, + event.cell, + ) diff --git a/task-G4-report.md b/task-G4-report.md index 86c50fe..d1a108c 100644 --- a/task-G4-report.md +++ b/task-G4-report.md @@ -1,57 +1,96 @@ -# G4 — Full visual presentation pass +# G4 — Master presentation report -## Scope +## Scope and boundary -Implemented in the dedicated `slice/g4-presentation-polish` worktree only. No DCWASCII files were read or changed; no remote push or PR was made. +This is the G4 documentation record for commit `ad10e99` (`feat: complete graphical feedback pass`). It covers presentation translation and feedback only: -## Root cause +- eight semantic event mappings; +- an immutable-at-the-presentation-boundary adapter; +- short, nonblocking feedback UI using the existing dark palette; +- ordered sequence E2E coverage and capture metrics; +- reconstructed RED evidence and final GREEN evidence. -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. +No DCWASCII source or unrelated product area is in scope. **G5 is explicitly out of scope**; this report makes no G5 claims. -## TDD presentation sequence +## Eight event mappings -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. +`EventPresenter.map_event()` maps each required domain category to exactly one named `PresentationEvent`. The source `GameEvent` remains the authoritative object and is not mutated by presentation. -## Implementation +| Domain event | Presentation kind | Feedback path | Accent | +| --- | --- | --- | --- | +| `damage_dealt` (combat family) | `combat` | existing `CombatFeedback` | coral/red | +| `door_opened` | `door` | `DoorChestFeedback` | cyan | +| `chest_opened` | `chest` | `DoorChestFeedback` | gold | +| `loot_taken` (loot family) | `loot` | `LootFeedback` | gold | +| `trap_triggered` (trap family) | `trap` | `LootFeedback` | red | +| `spell_cast_started` (spell family) | `spell` | cast flash / combat path | violet | +| `quest_started` (quest family) | `quest` | `LootFeedback` | green | +| `actor_died` (death family) | `death` | existing `CombatFeedback` | red | -- 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. +The implementation also accepts the related members of each family (for example `loot_dropped`, `trap_disarmed`, `spell_effect_applied`, and `quest_completed`) while preserving the same eight presentation kinds. Unsupported events pass through the ordered queue without a presentation effect. -## Verification and capture evidence +## Immutable presentation adapter -`./scripts/verify.sh` passed after the final changes: +`PresentationEvent` is a display-only immutable snapshot of one source `GameEvent`. Its private backing fields are exposed only through getter-only properties for the normalized presentation kind, notification text, and accent color. Rather than retaining the authoritative event reference, it copies the event values and deep-copies its payload at mapping time; every `source_event` getter call returns another independent event snapshot. Presentation therefore cannot assign adapter properties, mutate the original `GameEvent` through the adapter, or alter prior mapped presentation data by changing nested source payload values later. + +The mapping unit test mutates both the original event after mapping and a returned adapter snapshot (including a nested payload value), then asserts the mapped values remain captured and the source has no changes caused through the adapter. Direct assignment to a getter-only property is rejected by GDScript at compile time, so the test exercises the equivalent feasible runtime paths without embedding uncompilable code. + +`EventPresenter` emits `presentation_started` for observation and then emits the original `event_presented` event after its short feedback interval. This keeps semantic event order visible without coupling domain resolution to rendering details. + +## Nonblocking feedback UI and dark palette + +- Door and chest markers are asynchronous 160 ms expanding/fading diamond cues. +- Loot, trap, and quest notifications are asynchronous 160 ms floating/fading labels. +- Untargeted or starting spells receive a 120 ms cast interval rather than a silent no-op. +- Combat and death retain the existing short combat feedback path. +- Feedback is scene-owned below `EventPresenter`; it does not mutate gameplay state, wait on input, or prevent the game from resolving its domain action. +- Colors use the established blue-black panel treatment and existing semantic accents: cyan/gold for exploration rewards, violet for magic, green for quest state, and red for danger/death. + +The UI therefore gives every required category visible feedback while keeping cues transient and nonblocking rather than introducing a modal presentation layer. + +## RED reconstruction and GREEN result + +### RED reconstruction + +Before the `ad10e99` implementation, `EventPresenter` only queued `GameEvent` values and sent every event to `CombatFeedback`. `CombatFeedback` had no meaningful view for door, chest, loot, trap, spell-start, or quest events. There was no explicit semantic-to-presentation mapping contract, no display-only adapter, no dedicated exploration/narrative feedback nodes, and no observable presentation sequence seam. + +The G4 tests were authored against those missing contracts first: + +1. The mapping unit specification required `map_event()` and named presentation kinds. The pre-change implementation failed to compile/type-check because that API and `PresentationEvent` did not exist. +2. The real `Game.tscn` sequence specification required `presentation_started` and the eight ordered categories. The pre-change scene/presenter had neither the signal nor the dedicated feedback paths. + +These failures establish a behavior-level RED state rather than relying on a screenshot mismatch. + +### GREEN implementation + +`ad10e99` adds `PresentationEvent`, the eight-family mapping table, `presentation_started`, `DoorChestFeedback`, `LootFeedback`, scene wiring, and the ordered real-scene E2E test. The E2E enqueues and observes this exact sequence: + +`combat → door → chest → loot → trap → spell → quest → death` + +The test asserts one presentation event per source event, preserves order, and ends with an empty presenter queue. The unit contract also asserts that each of the eight canonical domain kinds maps to one named presentation event. + +## E2E and capture metrics + +Recorded final verification for `ad10e99` (Godot 4.5.0 / GUT 9.5.0): | 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 | +| Unit | 186 tests / 1,423 assertions passed | +| Integration | 11 tests / 59,470 assertions passed | +| E2E | 58 tests / 573 assertions passed | +| Visual structural capture | passed | -The existing non-brittle capture checker was run through the full verification command and confirmed both 1280×720 scripted reference scenes: +The non-brittle capture checker validated both scripted 1280×720 captures: -| Capture | dungeon non-black | visible | explored | unknown | explored luminance | unknown luminance | +| 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. +These are structural visibility/fog metrics, not brittle pixel snapshots. The capture checker confirms the dark unexplored field, visible dungeon content, and explored-state luminance remain distinguishable. -Additional review passed: `git diff --check` reports no whitespace errors. +The review remediation added one immutable-adapter mapping test. The complete post-remediation `./scripts/verify.sh` run passed: unit **187/187 tests, 1,432 assertions**; integration **11/11 tests, 59,470 assertions**; E2E **58/58 tests, 573 assertions**; and both visual structural captures. Existing GUT invalid-UID/resource-cleanup diagnostics are third-party/project warnings, not G4 assertions. -## Commit / delivery +## Delivery boundary -A local task commit is created after this report. It is intentionally not pushed and no PR is opened. +This review remediation changes only the `PresentationEvent` boundary, its mapping coverage, and this G4 report. A local task commit is created after verification; it is intentionally **not pushed** and no pull request is opened. **No G5 work is included.** diff --git a/tests/unit/test_event_presenter.gd b/tests/unit/test_event_presenter.gd index 0f7bc63..bb374a4 100644 --- a/tests/unit/test_event_presenter.gd +++ b/tests/unit/test_event_presenter.gd @@ -55,6 +55,40 @@ func _wait_for_presented_events(observed: Array[GameEvent], expected_count: int) while observed.size() < expected_count and Time.get_ticks_msec() < deadline: await get_tree().process_frame +func test_mapping_captures_an_immutable_source_snapshot() -> void: + var presenter := EventPresenter.new() + add_child_autofree(presenter) + var source := GameEvent.new(7, 2, &"damage_dealt", {"damage": 3, "nested": {"critical": false}}, "Goblin takes 3 damage.", &"player", &"goblin", Vector2i(6, 12)) + var mapped: PresentationEvent = presenter.map_event(source) + var exposed_snapshot := mapped.source_event + + # The adapter captures source values at mapping time, including nested payload. + source.kind = &"actor_died" + source.payload["damage"] = 7 + source.payload["nested"]["critical"] = true + + # PresentationEvent only exposes getter-backed values. Assigning to locals or + # to a returned snapshot cannot change the adapter or authoritative event. + var reassigned_kind := mapped.kind + reassigned_kind = &"death" + var reassigned_notification := mapped.notification + reassigned_notification = "rewritten" + var reassigned_accent := mapped.accent + reassigned_accent = Color.BLACK + exposed_snapshot.kind = &"death" + exposed_snapshot.payload["damage"] = 99 + exposed_snapshot.payload["nested"]["critical"] = true + + assert_eq(mapped.kind, &"combat") + assert_eq(mapped.notification, "Goblin takes 3 damage.") + assert_eq(mapped.accent, EventPresenter.COMBAT_COLOR) + assert_eq(mapped.source_event.kind, &"damage_dealt") + assert_eq(mapped.source_event.payload, {"damage": 3, "nested": {"critical": false}}) + assert_eq(source.kind, &"actor_died") + assert_eq(source.payload, {"damage": 7, "nested": {"critical": true}}) + assert_ne(mapped.source_event, source) + assert_ne(mapped.source_event, exposed_snapshot) + func test_major_domain_event_kinds_each_map_to_one_named_presentation_event() -> void: var presenter := EventPresenter.new() add_child_autofree(presenter) -- 2.54.0 From 782fcabc083bf927d375df2ec31566ab70e16b7e Mon Sep 17 00:00:00 2001 From: goose Date: Sun, 4 Oct 2026 00:56:22 -0400 Subject: [PATCH 3/5] fix: harden presentation event immutability --- scripts/presentation/presentation_event.gd | 52 +++++++++++- task-G4-report.md | 96 ---------------------- tests/unit/test_event_presenter.gd | 20 +++++ 3 files changed, 68 insertions(+), 100 deletions(-) delete mode 100644 task-G4-report.md diff --git a/scripts/presentation/presentation_event.gd b/scripts/presentation/presentation_event.gd index 0403db2..97f445f 100644 --- a/scripts/presentation/presentation_event.gd +++ b/scripts/presentation/presentation_event.gd @@ -4,10 +4,38 @@ extends RefCounted ## A display-only, immutable translation of one authoritative GameEvent. ## Getter calls return a fresh source snapshot so presentation code cannot mutate ## the source domain event or this adapter's captured event data. -var _source_event: GameEvent -var _kind: StringName -var _notification: String -var _accent: Color +## +## GDScript's leading underscore is only a convention: declared fields remain +## writable. The backing properties below are virtual so _set can absorb every +## write after construction. +const BACKING_PROPERTIES := [&"_source_event", &"_kind", &"_notification", &"_accent"] + +var _backing_values: Dictionary[StringName, Variant] = {} +var _is_initialized := false + +var _source_event: GameEvent: + set(value): + _set(&"_source_event", value) + get: + return _captured_source_snapshot() + +var _kind: StringName: + set(value): + _set(&"_kind", value) + get: + return _backing_values.get(&"_kind", &"") as StringName + +var _notification: String: + set(value): + _set(&"_notification", value) + get: + return _backing_values.get(&"_notification", "") as String + +var _accent: Color: + set(value): + _set(&"_accent", value) + get: + return _backing_values.get(&"_accent", Color.WHITE) as Color var source_event: GameEvent: get: @@ -30,6 +58,22 @@ func _init(source: GameEvent, presentation_kind: StringName, text: String = "", _kind = presentation_kind _notification = text if not text.is_empty() else source.message _accent = color + _is_initialized = true + +func _set(property: StringName, value: Variant) -> bool: + if property not in BACKING_PROPERTIES: + return false + if not _is_initialized: + _backing_values[property] = value + return true + +func _get(property: StringName) -> Variant: + if property in BACKING_PROPERTIES: + return _backing_values.get(property) + return null + +func _captured_source_snapshot() -> GameEvent: + return _copy_event(_backing_values.get(&"_source_event") as GameEvent) static func _copy_event(event: GameEvent) -> GameEvent: return GameEvent.new( diff --git a/task-G4-report.md b/task-G4-report.md deleted file mode 100644 index d1a108c..0000000 --- a/task-G4-report.md +++ /dev/null @@ -1,96 +0,0 @@ -# G4 — Master presentation report - -## Scope and boundary - -This is the G4 documentation record for commit `ad10e99` (`feat: complete graphical feedback pass`). It covers presentation translation and feedback only: - -- eight semantic event mappings; -- an immutable-at-the-presentation-boundary adapter; -- short, nonblocking feedback UI using the existing dark palette; -- ordered sequence E2E coverage and capture metrics; -- reconstructed RED evidence and final GREEN evidence. - -No DCWASCII source or unrelated product area is in scope. **G5 is explicitly out of scope**; this report makes no G5 claims. - -## Eight event mappings - -`EventPresenter.map_event()` maps each required domain category to exactly one named `PresentationEvent`. The source `GameEvent` remains the authoritative object and is not mutated by presentation. - -| Domain event | Presentation kind | Feedback path | Accent | -| --- | --- | --- | --- | -| `damage_dealt` (combat family) | `combat` | existing `CombatFeedback` | coral/red | -| `door_opened` | `door` | `DoorChestFeedback` | cyan | -| `chest_opened` | `chest` | `DoorChestFeedback` | gold | -| `loot_taken` (loot family) | `loot` | `LootFeedback` | gold | -| `trap_triggered` (trap family) | `trap` | `LootFeedback` | red | -| `spell_cast_started` (spell family) | `spell` | cast flash / combat path | violet | -| `quest_started` (quest family) | `quest` | `LootFeedback` | green | -| `actor_died` (death family) | `death` | existing `CombatFeedback` | red | - -The implementation also accepts the related members of each family (for example `loot_dropped`, `trap_disarmed`, `spell_effect_applied`, and `quest_completed`) while preserving the same eight presentation kinds. Unsupported events pass through the ordered queue without a presentation effect. - -## Immutable presentation adapter - -`PresentationEvent` is a display-only immutable snapshot of one source `GameEvent`. Its private backing fields are exposed only through getter-only properties for the normalized presentation kind, notification text, and accent color. Rather than retaining the authoritative event reference, it copies the event values and deep-copies its payload at mapping time; every `source_event` getter call returns another independent event snapshot. Presentation therefore cannot assign adapter properties, mutate the original `GameEvent` through the adapter, or alter prior mapped presentation data by changing nested source payload values later. - -The mapping unit test mutates both the original event after mapping and a returned adapter snapshot (including a nested payload value), then asserts the mapped values remain captured and the source has no changes caused through the adapter. Direct assignment to a getter-only property is rejected by GDScript at compile time, so the test exercises the equivalent feasible runtime paths without embedding uncompilable code. - -`EventPresenter` emits `presentation_started` for observation and then emits the original `event_presented` event after its short feedback interval. This keeps semantic event order visible without coupling domain resolution to rendering details. - -## Nonblocking feedback UI and dark palette - -- Door and chest markers are asynchronous 160 ms expanding/fading diamond cues. -- Loot, trap, and quest notifications are asynchronous 160 ms floating/fading labels. -- Untargeted or starting spells receive a 120 ms cast interval rather than a silent no-op. -- Combat and death retain the existing short combat feedback path. -- Feedback is scene-owned below `EventPresenter`; it does not mutate gameplay state, wait on input, or prevent the game from resolving its domain action. -- Colors use the established blue-black panel treatment and existing semantic accents: cyan/gold for exploration rewards, violet for magic, green for quest state, and red for danger/death. - -The UI therefore gives every required category visible feedback while keeping cues transient and nonblocking rather than introducing a modal presentation layer. - -## RED reconstruction and GREEN result - -### RED reconstruction - -Before the `ad10e99` implementation, `EventPresenter` only queued `GameEvent` values and sent every event to `CombatFeedback`. `CombatFeedback` had no meaningful view for door, chest, loot, trap, spell-start, or quest events. There was no explicit semantic-to-presentation mapping contract, no display-only adapter, no dedicated exploration/narrative feedback nodes, and no observable presentation sequence seam. - -The G4 tests were authored against those missing contracts first: - -1. The mapping unit specification required `map_event()` and named presentation kinds. The pre-change implementation failed to compile/type-check because that API and `PresentationEvent` did not exist. -2. The real `Game.tscn` sequence specification required `presentation_started` and the eight ordered categories. The pre-change scene/presenter had neither the signal nor the dedicated feedback paths. - -These failures establish a behavior-level RED state rather than relying on a screenshot mismatch. - -### GREEN implementation - -`ad10e99` adds `PresentationEvent`, the eight-family mapping table, `presentation_started`, `DoorChestFeedback`, `LootFeedback`, scene wiring, and the ordered real-scene E2E test. The E2E enqueues and observes this exact sequence: - -`combat → door → chest → loot → trap → spell → quest → death` - -The test asserts one presentation event per source event, preserves order, and ends with an empty presenter queue. The unit contract also asserts that each of the eight canonical domain kinds maps to one named presentation event. - -## E2E and capture metrics - -Recorded final verification for `ad10e99` (Godot 4.5.0 / GUT 9.5.0): - -| Suite | Result | -| --- | ---: | -| Unit | 186 tests / 1,423 assertions passed | -| Integration | 11 tests / 59,470 assertions passed | -| E2E | 58 tests / 573 assertions passed | -| Visual structural capture | passed | - -The non-brittle capture checker validated both scripted 1280×720 captures: - -| 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 are structural visibility/fog metrics, not brittle pixel snapshots. The capture checker confirms the dark unexplored field, visible dungeon content, and explored-state luminance remain distinguishable. - -The review remediation added one immutable-adapter mapping test. The complete post-remediation `./scripts/verify.sh` run passed: unit **187/187 tests, 1,432 assertions**; integration **11/11 tests, 59,470 assertions**; E2E **58/58 tests, 573 assertions**; and both visual structural captures. Existing GUT invalid-UID/resource-cleanup diagnostics are third-party/project warnings, not G4 assertions. - -## Delivery boundary - -This review remediation changes only the `PresentationEvent` boundary, its mapping coverage, and this G4 report. A local task commit is created after verification; it is intentionally **not pushed** and no pull request is opened. **No G5 work is included.** diff --git a/tests/unit/test_event_presenter.gd b/tests/unit/test_event_presenter.gd index bb374a4..1a64e6a 100644 --- a/tests/unit/test_event_presenter.gd +++ b/tests/unit/test_event_presenter.gd @@ -55,6 +55,26 @@ func _wait_for_presented_events(observed: Array[GameEvent], expected_count: int) while observed.size() < expected_count and Time.get_ticks_msec() < deadline: await get_tree().process_frame +func test_direct_backing_field_writes_are_absorbed_after_mapping() -> void: + var presenter := EventPresenter.new() + add_child_autofree(presenter) + var source := GameEvent.new(7, 2, &"damage_dealt", {"damage": 3}, "Goblin takes 3 damage.", &"player", &"goblin", Vector2i(6, 12)) + var mapped: PresentationEvent = presenter.map_event(source) + var replacement := GameEvent.new(99, 9, &"actor_died", {"damage": 99}, "Replacement.") + + # Leading underscores are not private in GDScript. The adapter absorbs direct + # writes to its virtual backing properties once initialization is complete. + mapped._kind = &"death" + mapped._source_event = replacement + mapped._source_event.payload["damage"] = 99 + + assert_eq(mapped.kind, &"combat") + assert_eq(mapped.source_event.kind, &"damage_dealt") + assert_eq(mapped.source_event.payload, {"damage": 3}) + assert_eq(source.kind, &"damage_dealt") + assert_eq(source.payload, {"damage": 3}) + assert_ne(mapped.source_event, replacement) + func test_mapping_captures_an_immutable_source_snapshot() -> void: var presenter := EventPresenter.new() add_child_autofree(presenter) -- 2.54.0 From e8ec8415bf27f14aa7aea47a3b884830ce158620 Mon Sep 17 00:00:00 2001 From: goose Date: Sun, 4 Oct 2026 01:08:53 -0400 Subject: [PATCH 4/5] fix: finalize presentation event immutability --- scripts/presentation/presentation_event.gd | 84 ++++++++-------------- task-G4-report.md | 56 +++++++++++++++ tests/unit/test_event_presenter.gd | 11 +-- 3 files changed, 92 insertions(+), 59 deletions(-) create mode 100644 task-G4-report.md diff --git a/scripts/presentation/presentation_event.gd b/scripts/presentation/presentation_event.gd index 97f445f..828b7c7 100644 --- a/scripts/presentation/presentation_event.gd +++ b/scripts/presentation/presentation_event.gd @@ -2,78 +2,52 @@ class_name PresentationEvent extends RefCounted ## A display-only, immutable translation of one authoritative GameEvent. -## Getter calls return a fresh source snapshot so presentation code cannot mutate -## the source domain event or this adapter's captured event data. -## -## GDScript's leading underscore is only a convention: declared fields remain -## writable. The backing properties below are virtual so _set can absorb every -## write after construction. -const BACKING_PROPERTIES := [&"_source_event", &"_kind", &"_notification", &"_accent"] +## Snapshot data belongs to this class, not an instance, so direct writes cannot +## create mutable instance state. Getter calls return a fresh source snapshot. +## RefCounted teardown cannot safely call script methods, so the static store is +## intentionally process-lifetime; entries contain only frozen presentation data. +const FORMER_BACKING_PROPERTIES := [ + &"_backing_values", + &"_is_initialized", + &"_source_event", + &"_kind", + &"_notification", + &"_accent", +] -var _backing_values: Dictionary[StringName, Variant] = {} -var _is_initialized := false - -var _source_event: GameEvent: - set(value): - _set(&"_source_event", value) - get: - return _captured_source_snapshot() - -var _kind: StringName: - set(value): - _set(&"_kind", value) - get: - return _backing_values.get(&"_kind", &"") as StringName - -var _notification: String: - set(value): - _set(&"_notification", value) - get: - return _backing_values.get(&"_notification", "") as String - -var _accent: Color: - set(value): - _set(&"_accent", value) - get: - return _backing_values.get(&"_accent", Color.WHITE) as Color +static var _snapshots: Dictionary[int, Dictionary] = {} var source_event: GameEvent: get: - return _copy_event(_source_event) + return _copy_event(_snapshot()[&"source_event"] as GameEvent) var kind: StringName: get: - return _kind + return _snapshot()[&"kind"] as StringName var notification: String: get: - return _notification + return _snapshot()[&"notification"] as String var accent: Color: get: - return _accent + return _snapshot()[&"accent"] as Color func _init(source: GameEvent, presentation_kind: StringName, text: String = "", color: Color = Color.WHITE) -> void: - _source_event = _copy_event(source) - _kind = presentation_kind - _notification = text if not text.is_empty() else source.message - _accent = color - _is_initialized = true + _snapshots[get_instance_id()] = { + &"source_event": _copy_event(source), + &"kind": presentation_kind, + &"notification": text if not text.is_empty() else source.message, + &"accent": color, + } -func _set(property: StringName, value: Variant) -> bool: - if property not in BACKING_PROPERTIES: - return false - if not _is_initialized: - _backing_values[property] = value - return true +## Former fields are intentionally undeclared. _set absorbs legacy direct writes +## without creating per-instance storage or changing the captured snapshot. +func _set(property: StringName, _value: Variant) -> bool: + return property in FORMER_BACKING_PROPERTIES -func _get(property: StringName) -> Variant: - if property in BACKING_PROPERTIES: - return _backing_values.get(property) - return null - -func _captured_source_snapshot() -> GameEvent: - return _copy_event(_backing_values.get(&"_source_event") as GameEvent) +func _snapshot() -> Dictionary: + return _snapshots.get(get_instance_id(), {}) as Dictionary static func _copy_event(event: GameEvent) -> GameEvent: return GameEvent.new( diff --git a/task-G4-report.md b/task-G4-report.md new file mode 100644 index 0000000..d9367cc --- /dev/null +++ b/task-G4-report.md @@ -0,0 +1,56 @@ +# G4 final — PresentationEvent immutability architecture + +## Scope + +This final remediation changes only `PresentationEvent`, its focused unit coverage, and this report. No domain, gameplay, presentation routing, asset, or DCWASCII source was changed. + +## Architecture + +`PresentationEvent` no longer declares any mutable instance backing field: + +- removed `_backing_values` and `_is_initialized`; +- removed declared `_source_event`, `_kind`, `_notification`, and `_accent` properties; +- records the complete captured event/presentation snapshot once in class-level `_snapshots`, keyed by `get_instance_id()`; +- exposes only getter APIs (`source_event`, `kind`, `notification`, and `accent`) from each instance; +- deep-copies the source `GameEvent` at capture time and returns a new copy from `source_event` on every read. + +The internal snapshot table is the sole data owner. No instance field can be changed after construction to alter the mapped result. + +## Legacy direct writes + +Because GDScript permits direct writes to underscore-named members, `_set` explicitly absorbs every former mutable field name: + +- `_kind` +- `_source_event` +- `_backing_values` +- `_is_initialized` +- `_notification` +- `_accent` + +Those names are intentionally undeclared, so these writes create no per-instance state and never modify the frozen snapshot. The focused mapping test performs all four requested writes (`_kind`, `_source_event`, `_backing_values`, `_is_initialized`) and verifies the mapped kind, notification, accent, source event, and source payload are unchanged. + +## Store lifecycle + +A `RefCounted` pre-delete notification was tested as a cleanup mechanism. Godot invokes it after the script instance is unavailable, producing `Cannot call method 'get_instance_id' on a null value`; it is therefore not viable or safe. The final store is intentionally process-lifetime and contains only captured presentation snapshots. This avoids teardown errors while preserving the required immutable instance architecture. + +## Verification + +`./scripts/verify.sh` passed with Godot 4.5.0: + +| Suite | Result | +| --- | ---: | +| Unit | 188 / 188 tests, 1,440 assertions | +| Integration | 11 / 11 tests, 59,470 assertions | +| E2E | 58 / 58 tests, 573 assertions | +| Visual structural capture | passed | + +Visual metrics: + +- `artifacts/visual-check.png`: `dungeon_non_black_pixels=489308`, `visible_pixels=17524`, `explored_pixels=10438`, `explored_luminance=0.012`, `unknown_pixels=365325`, `unknown_luminance=0.001`. +- `artifacts/visual-check-exit.png`: `dungeon_non_black_pixels=489252`, `visible_pixels=17404`, `explored_pixels=17146`, `explored_luminance=0.012`, `unknown_pixels=439497`, `unknown_luminance=0.001`. + +The existing GUT invalid-UID and engine resource-cleanup diagnostics were emitted, but there were no project script errors, parse errors, test failures, or visual verification failures. + +## Delivery + +A local commit is created for this final remediation. No push and no pull request are created. diff --git a/tests/unit/test_event_presenter.gd b/tests/unit/test_event_presenter.gd index 1a64e6a..fe6383c 100644 --- a/tests/unit/test_event_presenter.gd +++ b/tests/unit/test_event_presenter.gd @@ -55,20 +55,23 @@ func _wait_for_presented_events(observed: Array[GameEvent], expected_count: int) while observed.size() < expected_count and Time.get_ticks_msec() < deadline: await get_tree().process_frame -func test_direct_backing_field_writes_are_absorbed_after_mapping() -> void: +func test_direct_former_backing_field_writes_are_absorbed_after_mapping() -> void: var presenter := EventPresenter.new() add_child_autofree(presenter) var source := GameEvent.new(7, 2, &"damage_dealt", {"damage": 3}, "Goblin takes 3 damage.", &"player", &"goblin", Vector2i(6, 12)) var mapped: PresentationEvent = presenter.map_event(source) var replacement := GameEvent.new(99, 9, &"actor_died", {"damage": 99}, "Replacement.") - # Leading underscores are not private in GDScript. The adapter absorbs direct - # writes to its virtual backing properties once initialization is complete. + # Former fields are undeclared. Leading underscores are not private in + # GDScript, so every legacy direct write must be absorbed by _set. mapped._kind = &"death" mapped._source_event = replacement - mapped._source_event.payload["damage"] = 99 + mapped._backing_values = {&"_kind": &"death"} + mapped._is_initialized = false assert_eq(mapped.kind, &"combat") + assert_eq(mapped.notification, "Goblin takes 3 damage.") + assert_eq(mapped.accent, EventPresenter.COMBAT_COLOR) assert_eq(mapped.source_event.kind, &"damage_dealt") assert_eq(mapped.source_event.payload, {"damage": 3}) assert_eq(source.kind, &"damage_dealt") -- 2.54.0 From bd646243098938d7ccace22078b3e3a8f66f31e3 Mon Sep 17 00:00:00 2001 From: goose Date: Sun, 4 Oct 2026 01:09:30 -0400 Subject: [PATCH 5/5] chore: archive G4 report outside product tree --- task-G4-report.md | 56 ----------------------------------------------- 1 file changed, 56 deletions(-) delete mode 100644 task-G4-report.md diff --git a/task-G4-report.md b/task-G4-report.md deleted file mode 100644 index d9367cc..0000000 --- a/task-G4-report.md +++ /dev/null @@ -1,56 +0,0 @@ -# G4 final — PresentationEvent immutability architecture - -## Scope - -This final remediation changes only `PresentationEvent`, its focused unit coverage, and this report. No domain, gameplay, presentation routing, asset, or DCWASCII source was changed. - -## Architecture - -`PresentationEvent` no longer declares any mutable instance backing field: - -- removed `_backing_values` and `_is_initialized`; -- removed declared `_source_event`, `_kind`, `_notification`, and `_accent` properties; -- records the complete captured event/presentation snapshot once in class-level `_snapshots`, keyed by `get_instance_id()`; -- exposes only getter APIs (`source_event`, `kind`, `notification`, and `accent`) from each instance; -- deep-copies the source `GameEvent` at capture time and returns a new copy from `source_event` on every read. - -The internal snapshot table is the sole data owner. No instance field can be changed after construction to alter the mapped result. - -## Legacy direct writes - -Because GDScript permits direct writes to underscore-named members, `_set` explicitly absorbs every former mutable field name: - -- `_kind` -- `_source_event` -- `_backing_values` -- `_is_initialized` -- `_notification` -- `_accent` - -Those names are intentionally undeclared, so these writes create no per-instance state and never modify the frozen snapshot. The focused mapping test performs all four requested writes (`_kind`, `_source_event`, `_backing_values`, `_is_initialized`) and verifies the mapped kind, notification, accent, source event, and source payload are unchanged. - -## Store lifecycle - -A `RefCounted` pre-delete notification was tested as a cleanup mechanism. Godot invokes it after the script instance is unavailable, producing `Cannot call method 'get_instance_id' on a null value`; it is therefore not viable or safe. The final store is intentionally process-lifetime and contains only captured presentation snapshots. This avoids teardown errors while preserving the required immutable instance architecture. - -## Verification - -`./scripts/verify.sh` passed with Godot 4.5.0: - -| Suite | Result | -| --- | ---: | -| Unit | 188 / 188 tests, 1,440 assertions | -| Integration | 11 / 11 tests, 59,470 assertions | -| E2E | 58 / 58 tests, 573 assertions | -| Visual structural capture | passed | - -Visual metrics: - -- `artifacts/visual-check.png`: `dungeon_non_black_pixels=489308`, `visible_pixels=17524`, `explored_pixels=10438`, `explored_luminance=0.012`, `unknown_pixels=365325`, `unknown_luminance=0.001`. -- `artifacts/visual-check-exit.png`: `dungeon_non_black_pixels=489252`, `visible_pixels=17404`, `explored_pixels=17146`, `explored_luminance=0.012`, `unknown_pixels=439497`, `unknown_luminance=0.001`. - -The existing GUT invalid-UID and engine resource-cleanup diagnostics were emitted, but there were no project script errors, parse errors, test failures, or visual verification failures. - -## Delivery - -A local commit is created for this final remediation. No push and no pull request are created. -- 2.54.0