feat: structured narrative event feed with per-NPC inspector timeline

Add narrative event types (task_started, npc_slept, npc_died, resource_depleted) alongside economic transfers. EconomicEventRecord gains create_narrative factory and human-readable description method. SimulationManager records task-start and sleep/death events, exposes get_npc_events() for per-NPC history queries. Inspector now shows a Recent timeline of the last 5 events for the selected NPC, plus displays carried wood count. Relax EconomicEventRecord validation to accept non-economic events. Update roadmap with completed milestones.
This commit is contained in:
2026-07-08 19:02:11 +02:00
parent c61d286005
commit 8a1913c5ae
6 changed files with 151 additions and 22 deletions
+53 -4
View File
@@ -35,6 +35,30 @@ static func create(
)
static func create_narrative(
event_id: int,
event_type: StringName,
tick: int,
actor_id: int,
source_id: StringName,
action_display: String = ""
) -> EconomicEventRecord:
return EconomicEventRecord.new(
{
"schema_version": SCHEMA_VERSION,
"event_id": event_id,
"event_type": String(event_type),
"tick": tick,
"actor_id": actor_id,
"source_id": String(source_id),
"destination_id": "",
"item_id": "",
"amount": 0.0,
"action_name": action_display
}
)
static func from_dictionary(record_data: Dictionary) -> EconomicEventRecord:
if int(record_data.get("schema_version", -1)) != SCHEMA_VERSION:
return null
@@ -65,10 +89,6 @@ static func from_dictionary(record_data: Dictionary) -> EconomicEventRecord:
normalized["event_id"] < 0
or normalized["tick"] < 0
or normalized["event_type"].is_empty()
or normalized["source_id"].is_empty()
or normalized["destination_id"].is_empty()
or normalized["item_id"].is_empty()
or normalized["amount"] <= 0.0
):
return null
return EconomicEventRecord.new(normalized)
@@ -76,3 +96,32 @@ static func from_dictionary(record_data: Dictionary) -> EconomicEventRecord:
func to_dictionary() -> Dictionary:
return data.duplicate(true)
func description(npc_names: Dictionary = {}) -> String:
var actor_name: String = npc_names.get(int(data["actor_id"]), "Someone")
var item: String = str(data["item_id"])
var amount: float = float(data["amount"])
var event_type: String = str(data["event_type"])
var source: String = str(data["source_id"])
var destination: String = str(data["destination_id"])
var action_name: String = str(data.get("action_name", ""))
match event_type:
"resource_extracted":
return "%s gathered %.0f %s from %s" % [actor_name, amount, item, source]
"storage_deposited":
return "%s deposited %.0f %s into %s" % [actor_name, amount, item, destination]
"storage_withdrawn":
return "%s withdrew %.0f %s from %s" % [actor_name, amount, item, source]
"item_consumed":
return "%s consumed %.0f %s" % [actor_name, amount, item]
"npc_slept":
return "%s slept and recovered energy" % actor_name
"npc_died":
return "%s died from starvation" % actor_name
"task_started":
return "%s began %s" % [actor_name, action_name if not action_name.is_empty() else item]
"resource_depleted":
return "%s was depleted" % source
_:
return "tick %d: %s" % [int(data["tick"]), event_type]