class_name RecapLog extends RefCounted const HIGHLIGHT_KINDS := [&"actor_died", &"item_picked_up", &"damage_dealt", &"quest_completed", &"sponsor_unlocked"] const MAX_HIGHLIGHTS := 3 var _state: Dictionary func _init(state: Dictionary = {}) -> void: _state = state if not _state.has("recap_recent_highlights"): _state["recap_recent_highlights"] = [] if not _state.has("recap_episodes"): _state["recap_episodes"] = [] func observe(kind: StringName, message: String) -> void: if kind not in HIGHLIGHT_KINDS or message.is_empty(): return _state["recap_recent_highlights"].append(message) while _state["recap_recent_highlights"].size() > MAX_HIGHLIGHTS: _state["recap_recent_highlights"].pop_front() func record_episode(turn: int, spectacle: int, followers: int, sponsors: Array[StringName]) -> Dictionary: var snapshot: Array[StringName] = [] for sponsor_id in sponsors: snapshot.append(sponsor_id) var episode := { "number": _state["recap_episodes"].size() + 1, "turn": turn, "spectacle": spectacle, "followers": followers, "sponsors": snapshot, "highlights": _state["recap_recent_highlights"].duplicate(), } _state["recap_episodes"].append(episode) return episode.duplicate(true) func episodes() -> Array[Dictionary]: var result: Array[Dictionary] = [] for episode: Dictionary in _state["recap_episodes"]: result.append(episode.duplicate(true)) return result func timeline() -> Array[Dictionary]: return episodes()