Reorder some statements to make them visually more grouped together
Postfix patch went from 5 if-blocks down to only 3 \o/ There is no need to stop the creatureVoice and start it delayed in two separate condition blocks. Also, the code should only rely on state transitions, and not on AudioSource.isPlaying property.
This commit is contained in:
parent
2617bcaf1b
commit
2b42899779
|
@ -1,18 +1,18 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using BepInEx.Configuration;
|
||||
using BepInEx;
|
||||
using BepInEx.Configuration;
|
||||
using CSync.Extensions;
|
||||
using CSync.Lib;
|
||||
using LethalConfig;
|
||||
using LethalConfig.ConfigItems;
|
||||
using LethalConfig.ConfigItems.Options;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using LethalConfig.ConfigItems.Options;
|
||||
using LethalConfig.ConfigItems;
|
||||
using LethalConfig;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuzikaGromche
|
||||
{
|
||||
|
@ -387,6 +387,8 @@ namespace MuzikaGromche
|
|||
}
|
||||
}
|
||||
|
||||
// farAudio is during windup, Start overrides popGoesTheWeaselTheme
|
||||
// creatureVoice is when popped, Loop overrides screamingSFX
|
||||
[HarmonyPatch(typeof(JesterAI))]
|
||||
internal class JesterPatch
|
||||
{
|
||||
|
@ -404,13 +406,18 @@ namespace MuzikaGromche
|
|||
{
|
||||
__state = new State
|
||||
{
|
||||
previousState = __instance.previousState
|
||||
farAudio = __instance.farAudio,
|
||||
previousState = __instance.previousState,
|
||||
};
|
||||
if (__instance.currentBehaviourStateIndex == 2 && __instance.previousState != 2)
|
||||
{
|
||||
// if just popped out
|
||||
// then override farAudio so that vanilla logic does not stop the music
|
||||
__state.farAudio = __instance.farAudio;
|
||||
// If just popped out, then override farAudio so that vanilla logic does not stop the modded Start music.
|
||||
// The game will stop farAudio it during its Update, so we temporarily set it to any other AudioSource
|
||||
// which we don't care about stopping for now.
|
||||
//
|
||||
// Why creatureVoice though? We gonna need creatureVoice later in Postfix to schedule the Loop,
|
||||
// but right now we still don't care if it's stopped, so it shouldn't matter.
|
||||
// And it's cheaper and simpler than figuring out how to instantiate an AudioSource behaviour.
|
||||
__instance.farAudio = __instance.creatureVoice;
|
||||
}
|
||||
}
|
||||
|
@ -419,11 +426,6 @@ namespace MuzikaGromche
|
|||
[HarmonyPostfix]
|
||||
public static void DoNotStopTheMusic(JesterAI __instance, State __state)
|
||||
{
|
||||
if (__state.farAudio != null)
|
||||
{
|
||||
__instance.farAudio = __state.farAudio;
|
||||
}
|
||||
|
||||
if (__instance.previousState == 1 && __state.previousState != 1)
|
||||
{
|
||||
// if just started winding up
|
||||
|
@ -433,18 +435,16 @@ namespace MuzikaGromche
|
|||
|
||||
// ...and start modded music
|
||||
Plugin.CurrentTrack = Plugin.ChooseTrack();
|
||||
// Set up custom popup timer, which is shorter than Start audio
|
||||
__instance.popUpTimer = Plugin.CurrentTrack.WindUpTimer;
|
||||
|
||||
// Override popGoesTheWeaselTheme with Start audio
|
||||
__instance.farAudio.maxDistance = 150;
|
||||
__instance.farAudio.clip = Plugin.CurrentTrack.LoadedStart;
|
||||
__instance.farAudio.loop = false;
|
||||
Debug.Log($"Playing start music: maxDistance: {__instance.farAudio.maxDistance}, minDistance: {__instance.farAudio.minDistance}, volume: {__instance.farAudio.volume}, spread: {__instance.farAudio.spread}");
|
||||
__instance.farAudio.Play();
|
||||
}
|
||||
|
||||
if (__instance.previousState == 2 && __state.previousState != 2)
|
||||
{
|
||||
__instance.creatureVoice.Stop();
|
||||
Plugin.StartLightSwitching(__instance);
|
||||
Debug.Log($"Playing start music: maxDistance: {__instance.farAudio.maxDistance}, minDistance: {__instance.farAudio.minDistance}, volume: {__instance.farAudio.volume}, spread: {__instance.farAudio.spread}");
|
||||
}
|
||||
|
||||
if (__instance.previousState != 2 && __state.previousState == 2)
|
||||
|
@ -453,15 +453,24 @@ namespace MuzikaGromche
|
|||
Plugin.ResetLightColor();
|
||||
}
|
||||
|
||||
if (__instance.previousState == 2 && !__instance.creatureVoice.isPlaying)
|
||||
if (__instance.previousState == 2 && __state.previousState != 2)
|
||||
{
|
||||
__instance.creatureVoice.maxDistance = 150;
|
||||
__instance.creatureVoice.clip = Plugin.CurrentTrack.LoadedLoop;
|
||||
// Restore stashed AudioSource. See the comment in Prefix
|
||||
__instance.farAudio = __state.farAudio;
|
||||
|
||||
var time = __instance.farAudio.time;
|
||||
var delay = Plugin.CurrentTrack.LoadedStart.length - time;
|
||||
|
||||
// Override screamingSFX with Loop, delayed by the remaining time of the Start audio
|
||||
__instance.creatureVoice.Stop();
|
||||
__instance.creatureVoice.maxDistance = 150;
|
||||
__instance.creatureVoice.clip = Plugin.CurrentTrack.LoadedLoop;
|
||||
__instance.creatureVoice.PlayDelayed(delay);
|
||||
|
||||
Debug.Log($"Start length: {Plugin.CurrentTrack.LoadedStart.length}; played time: {time}");
|
||||
Debug.Log($"Playing loop music: maxDistance: {__instance.creatureVoice.maxDistance}, minDistance: {__instance.creatureVoice.minDistance}, volume: {__instance.creatureVoice.volume}, spread: {__instance.creatureVoice.spread}, in seconds: {delay}");
|
||||
__instance.creatureVoice.PlayDelayed(delay);
|
||||
|
||||
Plugin.StartLightSwitching(__instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue