worldbox-observer-mod/IdleSpectator/Events/Catalogs/EventCatalog.Plot.cs
2026-07-16 14:21:48 -05:00

68 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
namespace IdleSpectator;
/// <summary>Plot dials from <c>event-catalog.json</c> <c>plots</c>.</summary>
public static partial class EventCatalog
{
public static class Plot
{
private static readonly Dictionary<string, DiscreteEventEntry> Entries =
new Dictionary<string, DiscreteEventEntry>(StringComparer.OrdinalIgnoreCase);
private static int _appliedGeneration = -1;
public static void InvalidateOverlays()
{
Entries.Clear();
_appliedGeneration = -1;
}
private static void Ensure()
{
if (_appliedGeneration == EventCatalogConfig.Generation)
{
return;
}
_appliedGeneration = EventCatalogConfig.Generation;
EventCatalogConfig.FillPlots(Entries);
}
public static IEnumerable<string> AuthoredIds
{
get
{
Ensure();
return Entries.Keys;
}
}
public static bool HasAuthored(string id)
{
Ensure();
return !string.IsNullOrEmpty(id) && Entries.ContainsKey(id.Trim());
}
public static DiscreteEventEntry GetOrFallback(string id)
{
Ensure();
if (!string.IsNullOrEmpty(id) && Entries.TryGetValue(id.Trim(), out DiscreteEventEntry entry))
{
return entry;
}
string key = string.IsNullOrEmpty(id) ? "unknown" : id.Trim();
return new DiscreteEventEntry
{
Id = key,
EventStrength = 55f,
Category = "Plot",
LabelTemplate = "{a} · {id}",
CreatesInterest = false,
IsFallback = true
};
}
}
}