G4: Complete graphical feedback pass #50
@@ -2,78 +2,52 @@ class_name PresentationEvent
|
|||||||
extends RefCounted
|
extends RefCounted
|
||||||
|
|
||||||
## A display-only, immutable translation of one authoritative GameEvent.
|
## A display-only, immutable translation of one authoritative GameEvent.
|
||||||
## Getter calls return a fresh source snapshot so presentation code cannot mutate
|
## Snapshot data belongs to this class, not an instance, so direct writes cannot
|
||||||
## the source domain event or this adapter's captured event data.
|
## create mutable instance state. Getter calls return a fresh source snapshot.
|
||||||
##
|
## RefCounted teardown cannot safely call script methods, so the static store is
|
||||||
## GDScript's leading underscore is only a convention: declared fields remain
|
## intentionally process-lifetime; entries contain only frozen presentation data.
|
||||||
## writable. The backing properties below are virtual so _set can absorb every
|
const FORMER_BACKING_PROPERTIES := [
|
||||||
## write after construction.
|
&"_backing_values",
|
||||||
const BACKING_PROPERTIES := [&"_source_event", &"_kind", &"_notification", &"_accent"]
|
&"_is_initialized",
|
||||||
|
&"_source_event",
|
||||||
|
&"_kind",
|
||||||
|
&"_notification",
|
||||||
|
&"_accent",
|
||||||
|
]
|
||||||
|
|
||||||
var _backing_values: Dictionary[StringName, Variant] = {}
|
static var _snapshots: Dictionary[int, Dictionary] = {}
|
||||||
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:
|
var source_event: GameEvent:
|
||||||
get:
|
get:
|
||||||
return _copy_event(_source_event)
|
return _copy_event(_snapshot()[&"source_event"] as GameEvent)
|
||||||
|
|
||||||
var kind: StringName:
|
var kind: StringName:
|
||||||
get:
|
get:
|
||||||
return _kind
|
return _snapshot()[&"kind"] as StringName
|
||||||
|
|
||||||
var notification: String:
|
var notification: String:
|
||||||
get:
|
get:
|
||||||
return _notification
|
return _snapshot()[&"notification"] as String
|
||||||
|
|
||||||
var accent: Color:
|
var accent: Color:
|
||||||
get:
|
get:
|
||||||
return _accent
|
return _snapshot()[&"accent"] as Color
|
||||||
|
|
||||||
func _init(source: GameEvent, presentation_kind: StringName, text: String = "", color: Color = Color.WHITE) -> void:
|
func _init(source: GameEvent, presentation_kind: StringName, text: String = "", color: Color = Color.WHITE) -> void:
|
||||||
_source_event = _copy_event(source)
|
_snapshots[get_instance_id()] = {
|
||||||
_kind = presentation_kind
|
&"source_event": _copy_event(source),
|
||||||
_notification = text if not text.is_empty() else source.message
|
&"kind": presentation_kind,
|
||||||
_accent = color
|
&"notification": text if not text.is_empty() else source.message,
|
||||||
_is_initialized = true
|
&"accent": color,
|
||||||
|
}
|
||||||
|
|
||||||
func _set(property: StringName, value: Variant) -> bool:
|
## Former fields are intentionally undeclared. _set absorbs legacy direct writes
|
||||||
if property not in BACKING_PROPERTIES:
|
## without creating per-instance storage or changing the captured snapshot.
|
||||||
return false
|
func _set(property: StringName, _value: Variant) -> bool:
|
||||||
if not _is_initialized:
|
return property in FORMER_BACKING_PROPERTIES
|
||||||
_backing_values[property] = value
|
|
||||||
return true
|
|
||||||
|
|
||||||
func _get(property: StringName) -> Variant:
|
func _snapshot() -> Dictionary:
|
||||||
if property in BACKING_PROPERTIES:
|
return _snapshots.get(get_instance_id(), {}) as Dictionary
|
||||||
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:
|
static func _copy_event(event: GameEvent) -> GameEvent:
|
||||||
return GameEvent.new(
|
return GameEvent.new(
|
||||||
|
|||||||
@@ -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.
|
||||||
@@ -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:
|
while observed.size() < expected_count and Time.get_ticks_msec() < deadline:
|
||||||
await get_tree().process_frame
|
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()
|
var presenter := EventPresenter.new()
|
||||||
add_child_autofree(presenter)
|
add_child_autofree(presenter)
|
||||||
var source := GameEvent.new(7, 2, &"damage_dealt", {"damage": 3}, "Goblin takes 3 damage.", &"player", &"goblin", Vector2i(6, 12))
|
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 mapped: PresentationEvent = presenter.map_event(source)
|
||||||
var replacement := GameEvent.new(99, 9, &"actor_died", {"damage": 99}, "Replacement.")
|
var replacement := GameEvent.new(99, 9, &"actor_died", {"damage": 99}, "Replacement.")
|
||||||
|
|
||||||
# Leading underscores are not private in GDScript. The adapter absorbs direct
|
# Former fields are undeclared. Leading underscores are not private in
|
||||||
# writes to its virtual backing properties once initialization is complete.
|
# GDScript, so every legacy direct write must be absorbed by _set.
|
||||||
mapped._kind = &"death"
|
mapped._kind = &"death"
|
||||||
mapped._source_event = replacement
|
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.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.kind, &"damage_dealt")
|
||||||
assert_eq(mapped.source_event.payload, {"damage": 3})
|
assert_eq(mapped.source_event.payload, {"damage": 3})
|
||||||
assert_eq(source.kind, &"damage_dealt")
|
assert_eq(source.kind, &"damage_dealt")
|
||||||
|
|||||||
Reference in New Issue
Block a user