89 lines
2.4 KiB
C#
89 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace IdleSpectator;
|
|
|
|
public sealed class DisasterInterestEntry
|
|
{
|
|
public string Id = "";
|
|
public float EventStrength = 90f;
|
|
public string Category = "Disaster";
|
|
public string WorldLogId = "";
|
|
public bool CreatesInterest = true;
|
|
public bool IsFallback;
|
|
}
|
|
|
|
/// <summary>Disaster dials from <c>event-catalog.json</c> <c>disasters</c>.</summary>
|
|
public static partial class EventCatalog
|
|
{
|
|
public static class Disaster
|
|
{
|
|
private static readonly Dictionary<string, DisasterInterestEntry> Entries =
|
|
new Dictionary<string, DisasterInterestEntry>(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.FillDisasters(Entries);
|
|
}
|
|
|
|
public static IEnumerable<string> AuthoredIds
|
|
{
|
|
get
|
|
{
|
|
Ensure();
|
|
return Entries.Keys;
|
|
}
|
|
}
|
|
|
|
public static bool HasAuthored(string disasterId)
|
|
{
|
|
Ensure();
|
|
return !string.IsNullOrEmpty(disasterId) && Entries.ContainsKey(disasterId.Trim());
|
|
}
|
|
|
|
public static bool TryGet(string disasterId, out DisasterInterestEntry entry)
|
|
{
|
|
Ensure();
|
|
entry = null;
|
|
if (string.IsNullOrEmpty(disasterId))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return Entries.TryGetValue(disasterId.Trim(), out entry);
|
|
}
|
|
|
|
public static DisasterInterestEntry GetOrFallback(string disasterId)
|
|
{
|
|
if (TryGet(disasterId, out DisasterInterestEntry entry))
|
|
{
|
|
return entry;
|
|
}
|
|
|
|
string id = string.IsNullOrEmpty(disasterId) ? "unknown" : disasterId.Trim();
|
|
return new DisasterInterestEntry
|
|
{
|
|
Id = id,
|
|
EventStrength = 90f,
|
|
Category = "Disaster",
|
|
WorldLogId = "",
|
|
CreatesInterest = true,
|
|
IsFallback = true
|
|
};
|
|
}
|
|
}
|
|
}
|