worldbox-observer-mod/IdleSpectator/LiveLibraryInterest.cs
2026-07-15 22:16:24 -05:00

82 lines
2.4 KiB
C#

using System;
using System.Collections.Generic;
namespace IdleSpectator;
/// <summary>
/// Live-seeded interest catalogs: every live library id is authored (Ambient default),
/// with curated Signal overlays for spectacle / kingdom-affecting entries.
/// </summary>
public static class LiveLibraryInterest
{
public static void EnsureSeeded(
Dictionary<string, DiscreteEventEntry> entries,
Func<List<string>> enumerateLive,
string category,
string labelTemplate,
float ambientStrength,
HashSet<string> signalIds,
float signalStrength,
Func<string, bool> signalPredicate = null)
{
if (entries == null || enumerateLive == null)
{
return;
}
List<string> live;
try
{
live = enumerateLive() ?? new List<string>();
}
catch
{
live = new List<string>();
}
for (int i = 0; i < live.Count; i++)
{
string id = live[i];
if (string.IsNullOrEmpty(id) || entries.ContainsKey(id))
{
continue;
}
bool signal = (signalIds != null && signalIds.Contains(id))
|| (signalPredicate != null && signalPredicate(id));
entries[id] = new DiscreteEventEntry
{
Id = id,
EventStrength = signal ? signalStrength : ambientStrength,
Category = category,
OwnsCamera = signal ? InterestOwnership.Signal : InterestOwnership.Ambient,
CreatesInterest = true,
LabelTemplate = labelTemplate
};
}
}
public static DiscreteEventEntry Lookup(
Dictionary<string, DiscreteEventEntry> entries,
string id,
string category,
string labelTemplate,
float fallbackStrength = 40f)
{
if (!string.IsNullOrEmpty(id) && entries != null && entries.TryGetValue(id.Trim(), out DiscreteEventEntry entry))
{
return entry;
}
string key = string.IsNullOrEmpty(id) ? "unknown" : id.Trim();
return new DiscreteEventEntry
{
Id = key,
EventStrength = fallbackStrength,
Category = category,
OwnsCamera = InterestOwnership.Ambient,
LabelTemplate = labelTemplate,
IsFallback = true
};
}
}