using NeoModLoader.services; using UnityEngine; namespace IdleSpectator; /// /// ManualControl vs SpectatorMode toggle (I). /// public static class SpectatorMode { public const KeyCode ToggleKey = KeyCode.I; public static bool Active { get; private set; } private static bool _forceFileChecked; public static void Toggle() { SetActive(!Active); } public static void SetActive(bool active, bool quiet = false) { if (active && !ModSettings.Enabled) { LogService.LogInfo("[IdleSpectator] Enable blocked: disabled in settings"); return; } if (Active == active) { return; } Active = active; if (Active) { WatchCaption.ClearPausePin(); InterestDirector.OnSpectatorEnabled(); SpeciesDiscovery.OnSpectatorEnabled(); Chronicle.OnSpectatorEnabled(); ChronicleHud.OnIdleResumed(); FocusRelationshipArrows.OnSpectatorEnabled(); LogService.LogInfo("[IdleSpectator] Spectator mode enabled (I or any input to stop; L for Lore)"); } else { InterestDirector.OnSpectatorDisabled(); SpeciesDiscovery.OnSpectatorDisabled(); FocusRelationshipArrows.OnSpectatorDisabled(); CameraDirector.ClearFollow(); if (quiet) { // Manual-input pause: leave dossier up so ShowStatusBanner can reuse it. StateProbe.Reset(); } else { WatchCaption.Clear(); StateProbe.Reset(); LogService.LogInfo("[IdleSpectator] Spectator mode disabled"); } } } public static void PollInput() { if (!Config.game_loaded) { return; } if (!ModSettings.Enabled) { if (Active) { SetActive(false); } return; } TryForceOnFile(); if (Input.GetKeyDown(ToggleKey)) { Toggle(); } } /// /// Optional one-shot: place an empty .force-on file in the mod folder to enable Spectator once (deleted after use). /// private static void TryForceOnFile() { if (_forceFileChecked || Active || !ModSettings.Enabled) { return; } string modFolder = ModClass.ModFolder; if (string.IsNullOrEmpty(modFolder)) { return; } string path = System.IO.Path.Combine(modFolder, ".force-on"); if (!System.IO.File.Exists(path)) { return; } _forceFileChecked = true; try { System.IO.File.Delete(path); } catch { // Still enable even if delete fails. } SetActive(true); } }