new song and ogg/vorbis format #1

Open
ratijas wants to merge 9 commits from ratijas/muzika-gromche:work/r/en_US into master
1 changed files with 60 additions and 37 deletions
Showing only changes of commit ceb11e36f4 - Show all commits

View File

@ -55,6 +55,54 @@ namespace MuzikaGromche
public static Coroutine JesterLightSwitching;
public static Track CurrentTrack;
public static void StartLightSwitching(MonoBehaviour __instance)
{
StopLightSwitching(__instance);
JesterLightSwitching = __instance.StartCoroutine(rotateColors());
}
public static void StopLightSwitching(MonoBehaviour __instance)
{
if (JesterLightSwitching != null) {
__instance.StopCoroutine(JesterLightSwitching);
JesterLightSwitching = null;
}
}
public static void SetLightColor(Color color)
{
foreach (var light in RoundManager.Instance.allPoweredLights)
{
light.color = color;
}
}
public static void ResetLightColor()
{
SetLightColor(Color.white);
}
// TODO: Move to Track class to make them customizable per-song
static List<Color> colors = [Color.magenta, Color.cyan, Color.green, Color.yellow];
public static IEnumerator rotateColors()
{
Debug.Log("Starting color rotation");
var i = 0;
while (true)
{
var color = colors[i];
Debug.Log("Chose color " + color);
SetLightColor(color);
i = (i + 1) % colors.Count;
if (CurrentTrack != null) {
yield return new WaitForSeconds(60f / CurrentTrack.Bpm);
} else {
yield break;
}
}
}
private void Awake()
{
string text = Info.Location.TrimEnd((PluginInfo.PLUGIN_NAME + ".dll").ToCharArray());
@ -71,8 +119,9 @@ namespace MuzikaGromche
if (requests.All(request => request.result == UnityWebRequest.Result.Success)) {
for (int i = 0; i < Tracks.Length; i++) {
Tracks[i].LoadedStart = DownloadHandlerAudioClip.GetContent(requests[i * 2]);
Tracks[i].LoadedLoop = DownloadHandlerAudioClip.GetContent(requests[i * 2 + 1]);
Track track = Tracks[i];
track.LoadedStart = DownloadHandlerAudioClip.GetContent(requests[i * 2]);
track.LoadedLoop = DownloadHandlerAudioClip.GetContent(requests[i * 2 + 1]);
}
new Harmony(PluginInfo.PLUGIN_NAME).PatchAll(typeof(JesterPatch));
} else {
@ -84,8 +133,14 @@ namespace MuzikaGromche
public class Track
{
public string Name;
// Wind-up time can be shorter than the Start audio track, so that
// the "pop" effect can be baked in the Start audio and kept away
// from the looped part.
public float WindUpTimer;
// BPM for light switching in sync with the music. There is no offset,
// so the Loop track should start precisely on a beat.
public float Bpm;
public AudioClip LoadedStart;
public AudioClip LoadedLoop;
}
@ -107,27 +162,6 @@ namespace MuzikaGromche
}
}
static List<Color> colors = [Color.magenta, Color.cyan, Color.green, Color.yellow];
public static IEnumerator rotateColors()
{
Debug.Log("Starting color rotation");
var i = 0;
while (true)
{
var color = colors[i];
Debug.Log("Chose color " + color);
foreach (var light in RoundManager.Instance.allPoweredLights)
{
light.color = color;
}
i += 1;
if (i >= colors.Count) i = 0;
yield return new WaitForSeconds(60f / Plugin.CurrentTrack.Bpm);
}
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
public static void DoNotStopTheMusic(JesterAI __instance, State __state)
@ -170,24 +204,13 @@ namespace MuzikaGromche
if (__instance.currentBehaviourStateIndex is 2 && __state.prevStateindex != 2)
{
__instance.creatureVoice.Stop();
if (Plugin.JesterLightSwitching != null) {
__instance.StopCoroutine(Plugin.JesterLightSwitching);
Plugin.JesterLightSwitching = null;
}
Plugin.JesterLightSwitching = __instance.StartCoroutine(rotateColors());
Plugin.StartLightSwitching(__instance);
}
if (__instance.currentBehaviourStateIndex != 2 && __state.prevStateindex == 2)
{
if (Plugin.JesterLightSwitching != null) {
__instance.StopCoroutine(Plugin.JesterLightSwitching);
Plugin.JesterLightSwitching = null;
}
foreach (var light in RoundManager.Instance.allPoweredLights)
{
light.color = Color.white;
}
Plugin.StopLightSwitching(__instance);
Plugin.ResetLightColor();
}
if (__instance.currentBehaviourStateIndex is 2 && !__instance.creatureVoice.isPlaying)