using Cthangover.Core.Events; using Cthangover.Core.Interactive; using Cthangover.Core.Mods; using Cthangover.Core.Utils; using Godot; namespace Cthangover.Mods.Interactive { /// /// Engine-mod initializer for the interactive subsystem. Takes over the /// lifecycle SceneContextNode owned before the migration: on /// resources-ready it initializes the InteractiveManager singleton /// and subscribes the per-scene teardown (InteractiveManager.Shutdown) /// to SceneExitedEvent, so tracked interactive objects are destroyed /// on every scene change. All operations are idempotent: /// ModManager.Reload() re-runs OnModResourcesReady, so repeat /// invocations must not corrupt state. /// public class InteractiveModInitializer : IModInitializer { private static bool initialized; /// No per-mod setup is required; lifecycle happens on resources-ready. public void OnModLoaded(string modId) { } /// /// Initializes the manager singleton and wires the scene-exit teardown. /// Safe to call again after a mod reload. /// public void OnModResourcesReady() { if (initialized) return; initialized = true; InteractiveManager.Initialize(); GameLogger.Log("INTERACTIVE", "InteractiveModInitializer: manager initialized"); ModEventBus.Subscribe(_ => InteractiveManager.Shutdown()); } } }