using System;
using System.Collections.Generic;
namespace IdleSpectator;
/// World-session immutable observation store. Persistence is added in Phase 5.
public static class NarrativeEventStore
{
private static readonly Dictionary Events =
new Dictionary(StringComparer.Ordinal);
public static int Count => Events.Count;
public static void Clear()
{
Events.Clear();
}
public static NarrativeEventRecord Get(string id)
{
if (string.IsNullOrEmpty(id))
{
return null;
}
Events.TryGetValue(id, out NarrativeEventRecord record);
return record;
}
public static bool Add(NarrativeEventRecord record)
{
if (record == null || string.IsNullOrEmpty(record.Id) || Events.ContainsKey(record.Id))
{
return false;
}
Events[record.Id] = record;
NarrativePersistence.MarkDirty();
return true;
}
public static IEnumerable All() => Events.Values;
internal static bool Import(NarrativeEventRecord record)
{
if (record == null || string.IsNullOrEmpty(record.Id) || Events.ContainsKey(record.Id))
{
return false;
}
Events[record.Id] = record;
return true;
}
}