80 lines
2.2 KiB
C#
80 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace IdleSpectator;
|
|
|
|
/// <summary>
|
|
/// Happiness policy + prose. Source of truth: <c>event-catalog.json</c> <c>happiness</c> section.
|
|
/// </summary>
|
|
public static partial class EventCatalog
|
|
{
|
|
public static class Happiness
|
|
{
|
|
private static readonly Dictionary<string, HappinessCatalogEntry> Entries =
|
|
new Dictionary<string, HappinessCatalogEntry>(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.FillHappiness(Entries);
|
|
}
|
|
|
|
public static IEnumerable<string> AuthoredIds
|
|
{
|
|
get
|
|
{
|
|
Ensure();
|
|
return Entries.Keys;
|
|
}
|
|
}
|
|
|
|
public static bool HasAuthored(string effectId)
|
|
{
|
|
Ensure();
|
|
return !string.IsNullOrEmpty(effectId) && Entries.ContainsKey(effectId.Trim());
|
|
}
|
|
|
|
public static bool TryGet(string effectId, out HappinessCatalogEntry entry)
|
|
{
|
|
Ensure();
|
|
entry = null;
|
|
if (string.IsNullOrEmpty(effectId))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return Entries.TryGetValue(effectId.Trim(), out entry);
|
|
}
|
|
|
|
public static HappinessCatalogEntry GetOrFallback(string effectId)
|
|
{
|
|
if (TryGet(effectId, out HappinessCatalogEntry entry))
|
|
{
|
|
return entry;
|
|
}
|
|
|
|
string id = string.IsNullOrEmpty(effectId) ? "unknown" : effectId.Trim();
|
|
return new HappinessCatalogEntry
|
|
{
|
|
Id = id,
|
|
EventStrength = 40f,
|
|
Presentation = HappinessPresentationTier.Ambient,
|
|
IsFallback = true,
|
|
VariantsWithoutRelated = new[] { "feels something (" + id + ")" }
|
|
};
|
|
}
|
|
}
|
|
}
|