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) { if (active && !ModSettings.Enabled) { WorldTip.showNowTop("Idle Spectator disabled in mod settings", pTranslate: false); LogService.LogInfo("[IdleSpectator] Enable blocked: disabled in settings"); return; } if (Active == active) { return; } Active = active; if (Active) { InterestDirector.OnSpectatorEnabled(); SpeciesDiscovery.OnSpectatorEnabled(); Chronicle.OnSpectatorEnabled(); WorldTip.showNowTop("Idle Spectator ON (I or any input to stop; F9 chronicle)", pTranslate: false); LogService.LogInfo("[IdleSpectator] Spectator mode enabled"); } else { InterestDirector.OnSpectatorDisabled(); SpeciesDiscovery.OnSpectatorDisabled(); CameraDirector.ClearFollow(); WatchCaption.Clear(); StateProbe.Reset(); WorldTip.showNowTop("Idle Spectator OFF", pTranslate: false); 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); } }