Move BeatTimeState from global static to per-Jester-instance Behaviour
This commit is contained in:
		
							parent
							
								
									0b0383003f
								
							
						
					
					
						commit
						e67de4556c
					
				|  | @ -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<MuzikaGromcheJesterNetworkBehaviour>(); | ||||
| 
 | ||||
|             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. | ||||
|             } | ||||
|         } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue