fix: make presentation events immutable

This commit is contained in:
goose
2026-10-04 00:40:52 -04:00
parent ad10e99de9
commit 0a9b14be26
3 changed files with 147 additions and 45 deletions
+39 -10
View File
@@ -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,
)