From e67de4556cabd0a12732df58cc8b31521081dbe9 Mon Sep 17 00:00:00 2001 From: ivan tkachenko Date: Thu, 21 Aug 2025 16:09:07 +0300 Subject: [PATCH] Move BeatTimeState from global static to per-Jester-instance Behaviour --- MuzikaGromche/Plugin.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/MuzikaGromche/Plugin.cs b/MuzikaGromche/Plugin.cs index 3912393..28841f3 100644 --- a/MuzikaGromche/Plugin.cs +++ b/MuzikaGromche/Plugin.cs @@ -605,7 +605,6 @@ namespace MuzikaGromche } internal static IAudioTrack? CurrentTrack; - internal static BeatTimeState? BeatTimeState; public static void SetLightColor(Color color) { @@ -2263,6 +2262,8 @@ namespace MuzikaGromche // Resets on SettingChanged. private int SelectedTrackIndex = 0; + internal BeatTimeState? BeatTimeState = null; + public override void OnNetworkSpawn() { ChooseTrackDeferred(); @@ -2382,6 +2383,8 @@ namespace MuzikaGromche return; } + var behaviour = __instance.GetComponent(); + if (__instance.previousState == 1 && __state.previousState != 1) { // if just started winding up @@ -2390,7 +2393,7 @@ namespace MuzikaGromche __instance.creatureVoice.Stop(); // ...and start modded music - Plugin.BeatTimeState = new BeatTimeState(Plugin.CurrentTrack); + behaviour.BeatTimeState = new BeatTimeState(Plugin.CurrentTrack); // Set up custom popup timer, which is shorter than Start audio __instance.popUpTimer = Plugin.CurrentTrack.WindUpTimer; @@ -2416,7 +2419,7 @@ namespace MuzikaGromche if (__instance.previousState != 2 && __state.previousState == 2) { - Plugin.BeatTimeState = null; + behaviour.BeatTimeState = null; Plugin.ResetLightColor(); DiscoBallManager.Disable(); // Rotate track groups @@ -2442,7 +2445,7 @@ namespace MuzikaGromche } // Manage the timeline: switch color of the lights according to the current playback/beat position. - if ((__instance.previousState == 1 || __instance.previousState == 2) && Plugin.BeatTimeState is { } beatTimeState) + if ((__instance.previousState == 1 || __instance.previousState == 2) && behaviour.BeatTimeState is { } beatTimeState) { var events = beatTimeState.Update(intro: __instance.farAudio, loop: __instance.creatureVoice); foreach (var ev in events) @@ -2487,7 +2490,7 @@ namespace MuzikaGromche Plugin.ResetLightColor(); DiscoBallManager.Disable(); // Just in case if players have spawned multiple Jesters, - // Don't reset Plugin.CurrentTrack and Plugin.BeatTimeState to null, + // Don't reset Plugin.CurrentTrack to null, // so that the code wouldn't crash without extra null checks. } }