worldbox-observer-mod/IdleSpectator/Main.cs
DazedAnon c11b87aa2e Implement gravestone features and enhance Lore interactions.
- Add gravestone management with max stack and lifetime settings
- Introduce new commands for grave interactions in scenarios
- Update Lore handling to include gravestone context and details
- Refactor death cause formatting for improved readability
- Increment version to 0.28.11 in mod.json
2026-07-17 16:32:10 -05:00

116 lines
3 KiB
C#

using System;
using System.IO;
using HarmonyLib;
using NeoModLoader.api;
using NeoModLoader.services;
using UnityEngine;
namespace IdleSpectator;
/// <summary>
/// Idle Spectator entry: I key AFK camera director over WorldLog events.
/// </summary>
public class ModClass : MonoBehaviour, IMod, IConfigurable, ILocalizable
{
private ModDeclare _declare;
private GameObject _gameObject;
private Harmony _harmony;
private ModConfig _config;
/// <summary>Absolute path to this mod's folder (parent of mod.json).</summary>
public static string ModFolder { get; private set; }
public static ModClass Instance { get; private set; }
public ModDeclare GetDeclaration()
{
return _declare;
}
public GameObject GetGameObject()
{
return _gameObject;
}
public string GetUrl()
{
return "";
}
public ModConfig GetConfig()
{
return _config;
}
public string GetLocaleFilesDirectory(ModDeclare pModDeclare)
{
return Path.Combine(pModDeclare.FolderPath, "Locales");
}
public void OnLoad(ModDeclare pModDecl, GameObject pGameObject)
{
Instance = this;
_declare = pModDecl;
_gameObject = pGameObject;
ModFolder = pModDecl.FolderPath;
_config = ModSettings.Load(pModDecl);
InterestScoringConfig.LoadFromModFolder(ModFolder);
EventCatalogConfig.LoadFromModFolder(ModFolder);
_harmony = new Harmony(pModDecl.UID);
ApplyHarmonyPatches(pModDecl.Name);
LogService.LogInfo($"[{pModDecl.Name}]: Harmony patches applied");
LogService.LogInfo($"[{pModDecl.Name}]: Press I for Idle Spectator, L for Lore");
Chronicle.EnsureWindow();
}
private void ApplyHarmonyPatches(string modName)
{
Exception firstFailure = null;
foreach (Type type in typeof(ModClass).Assembly.GetTypes())
{
try
{
new PatchClassProcessor(_harmony, type).Patch();
}
catch (Exception ex)
{
LogService.LogError($"[{modName}]: Harmony failed on {type.FullName}: {ex}");
if (ex.InnerException != null)
{
LogService.LogError($"[{modName}]: Inner: {ex.InnerException}");
}
if (firstFailure == null)
{
firstFailure = ex;
}
}
}
if (firstFailure != null)
{
throw firstFailure;
}
}
private void Update()
{
AgentHarness.Update();
SpectatorMode.PollInput();
Chronicle.PollInput();
InterestDirector.Update();
if (!AgentHarness.FreezeDirector)
{
SpeciesDiscovery.Update();
}
WatchCaption.Update();
Chronicle.Update();
GraveMarkers.Update();
InspectUi.Update();
FocusRelationshipArrows.PinFocusActor();
StateProbe.Update();
AutoTest.Update();
}
}