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 IAudioTrack? CurrentTrack; | ||||||
|         internal static BeatTimeState? BeatTimeState; |  | ||||||
| 
 | 
 | ||||||
|         public static void SetLightColor(Color color) |         public static void SetLightColor(Color color) | ||||||
|         { |         { | ||||||
|  | @ -2263,6 +2262,8 @@ namespace MuzikaGromche | ||||||
|         // Resets on SettingChanged. |         // Resets on SettingChanged. | ||||||
|         private int SelectedTrackIndex = 0; |         private int SelectedTrackIndex = 0; | ||||||
| 
 | 
 | ||||||
|  |         internal BeatTimeState? BeatTimeState = null; | ||||||
|  | 
 | ||||||
|         public override void OnNetworkSpawn() |         public override void OnNetworkSpawn() | ||||||
|         { |         { | ||||||
|             ChooseTrackDeferred(); |             ChooseTrackDeferred(); | ||||||
|  | @ -2382,6 +2383,8 @@ namespace MuzikaGromche | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|  |             var behaviour = __instance.GetComponent<MuzikaGromcheJesterNetworkBehaviour>(); | ||||||
|  | 
 | ||||||
|             if (__instance.previousState == 1 && __state.previousState != 1) |             if (__instance.previousState == 1 && __state.previousState != 1) | ||||||
|             { |             { | ||||||
|                 // if just started winding up |                 // if just started winding up | ||||||
|  | @ -2390,7 +2393,7 @@ namespace MuzikaGromche | ||||||
|                 __instance.creatureVoice.Stop(); |                 __instance.creatureVoice.Stop(); | ||||||
| 
 | 
 | ||||||
|                 //  ...and start modded music |                 //  ...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 |                 // Set up custom popup timer, which is shorter than Start audio | ||||||
|                 __instance.popUpTimer = Plugin.CurrentTrack.WindUpTimer; |                 __instance.popUpTimer = Plugin.CurrentTrack.WindUpTimer; | ||||||
| 
 | 
 | ||||||
|  | @ -2416,7 +2419,7 @@ namespace MuzikaGromche | ||||||
| 
 | 
 | ||||||
|             if (__instance.previousState != 2 && __state.previousState == 2) |             if (__instance.previousState != 2 && __state.previousState == 2) | ||||||
|             { |             { | ||||||
|                 Plugin.BeatTimeState = null; |                 behaviour.BeatTimeState = null; | ||||||
|                 Plugin.ResetLightColor(); |                 Plugin.ResetLightColor(); | ||||||
|                 DiscoBallManager.Disable(); |                 DiscoBallManager.Disable(); | ||||||
|                 // Rotate track groups |                 // Rotate track groups | ||||||
|  | @ -2442,7 +2445,7 @@ namespace MuzikaGromche | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             // Manage the timeline: switch color of the lights according to the current playback/beat position. |             // 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); |                 var events = beatTimeState.Update(intro: __instance.farAudio, loop: __instance.creatureVoice); | ||||||
|                 foreach (var ev in events) |                 foreach (var ev in events) | ||||||
|  | @ -2487,7 +2490,7 @@ namespace MuzikaGromche | ||||||
|                 Plugin.ResetLightColor(); |                 Plugin.ResetLightColor(); | ||||||
|                 DiscoBallManager.Disable(); |                 DiscoBallManager.Disable(); | ||||||
|                 // Just in case if players have spawned multiple Jesters, |                 // 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. |                 // so that the code wouldn't crash without extra null checks. | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue