From f6df1644bc58c3aa2a75bb637b2d942a7537dc00 Mon Sep 17 00:00:00 2001 From: minenice55 <43734252+minenice55@users.noreply.github.com> Date: Tue, 22 Mar 2022 14:29:15 -0400 Subject: [PATCH] Conductor: property that returns secPerBeat scaled to song pitch NEEDS TESTING --- Assets/Scripts/Conductor.cs | 5 ++++- Assets/Scripts/Games/CropStomp/CropStomp.cs | 2 +- Assets/Scripts/Games/CropStomp/Veggie.cs | 2 +- Assets/Scripts/Games/DJSchool/DJSchool.cs | 8 ++++---- Assets/Scripts/Games/ForkLifter/Pea.cs | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Assets/Scripts/Conductor.cs b/Assets/Scripts/Conductor.cs index d92b874e..60b0efe4 100644 --- a/Assets/Scripts/Conductor.cs +++ b/Assets/Scripts/Conductor.cs @@ -17,6 +17,9 @@ namespace HeavenStudio // The number of seconds for each song beat public float secPerBeat; + // The number of seconds for each song beat, inversely scaled to song pitch (higer pitch = shorter time) + public float pitchedSecPerBeat => (secPerBeat / musicSource.pitch); + // Current song position, in seconds private float songPos; // for Conductor use only public float songPosition; @@ -237,7 +240,7 @@ namespace HeavenStudio // convert real seconds to beats public float GetRestFromRealTime(float seconds) { - return seconds/secPerBeat; + return seconds/pitchedSecPerBeat; } public void SetBpm(float bpm) diff --git a/Assets/Scripts/Games/CropStomp/CropStomp.cs b/Assets/Scripts/Games/CropStomp/CropStomp.cs index db859cb0..db892a89 100644 --- a/Assets/Scripts/Games/CropStomp/CropStomp.cs +++ b/Assets/Scripts/Games/CropStomp/CropStomp.cs @@ -14,7 +14,7 @@ namespace HeavenStudio.Games const float stepDistance = 2.115f; public static float[] moleSoundOffsets = new float[]{ 0.134f, 0.05f, 0.061f }; - float scrollRate => stepDistance / (Conductor.instance.secPerBeat * 2f / Conductor.instance.musicSource.pitch); + float scrollRate => stepDistance / (Conductor.instance.pitchedSecPerBeat * 2f); float grassWidth; float dotsWidth = 19.2f; diff --git a/Assets/Scripts/Games/CropStomp/Veggie.cs b/Assets/Scripts/Games/CropStomp/Veggie.cs index c5cde9fc..46e9c45c 100644 --- a/Assets/Scripts/Games/CropStomp/Veggie.cs +++ b/Assets/Scripts/Games/CropStomp/Veggie.cs @@ -231,7 +231,7 @@ namespace HeavenStudio.Games.Scripts_CropStomp var veggieScale = veggieTrans.localScale; veggieTrans.localScale = new Vector3(veggieScale.x * 0.5f, veggieScale.y, veggieScale.z); - squashTween = veggieTrans.DOScaleX(veggieScale.x, cond.secPerBeat * 0.5f / cond.musicSource.pitch); + squashTween = veggieTrans.DOScaleX(veggieScale.x, cond.pitchedSecPerBeat * 0.5f); ResetState(); diff --git a/Assets/Scripts/Games/DJSchool/DJSchool.cs b/Assets/Scripts/Games/DJSchool/DJSchool.cs index ddc71d66..8298259f 100644 --- a/Assets/Scripts/Games/DJSchool/DJSchool.cs +++ b/Assets/Scripts/Games/DJSchool/DJSchool.cs @@ -108,7 +108,7 @@ namespace HeavenStudio.Games var sound = new MultiSound.Sound[] { new MultiSound.Sound(sounds[0], beat), - new MultiSound.Sound(sounds[1], beat + 1f - (0.030f/Conductor.instance.secPerBeat)*Conductor.instance.musicSource.pitch), + new MultiSound.Sound(sounds[1], beat + 1f, offset: 0.030f), new MultiSound.Sound("", beat + 2f) }; @@ -136,7 +136,7 @@ namespace HeavenStudio.Games var sound = new MultiSound.Sound[] { new MultiSound.Sound("djSchool/andStop1", beat), - new MultiSound.Sound("djSchool/andStop2", beat + .5f - (0.1200f/Conductor.instance.secPerBeat)*Conductor.instance.musicSource.pitch), + new MultiSound.Sound("djSchool/andStop2", beat + .5f, offset: 0.1200f), new MultiSound.Sound("", beat + 1.5f) }; @@ -178,8 +178,8 @@ namespace HeavenStudio.Games new MultiSound.Sound(sounds[0], beat), new MultiSound.Sound(sounds[1], beat + .25f), new MultiSound.Sound(sounds[2], beat + .5f), - new MultiSound.Sound(sounds[3], beat + 1f - (0.0500f/Conductor.instance.secPerBeat)*Conductor.instance.musicSource.pitch), - new MultiSound.Sound(sounds[4], beat + 2f - (0.070f/Conductor.instance.secPerBeat)*Conductor.instance.musicSource.pitch), + new MultiSound.Sound(sounds[3], beat + 1f, offset: 0.0500f), + new MultiSound.Sound(sounds[4], beat + 2f, offset: 0.070f), }); BeatAction.New(djYellow, new List() diff --git a/Assets/Scripts/Games/ForkLifter/Pea.cs b/Assets/Scripts/Games/ForkLifter/Pea.cs index 851a6067..15650549 100644 --- a/Assets/Scripts/Games/ForkLifter/Pea.cs +++ b/Assets/Scripts/Games/ForkLifter/Pea.cs @@ -23,7 +23,7 @@ namespace HeavenStudio.Games.Scripts_ForkLifter // SCHEDULING zoom sound so it lines up with when it meets the fork. var currentDspTime = AudioSettings.dspTime; var cond = Conductor.instance; - var zoomStartTime = currentDspTime + (double)(cond.secPerBeat * 2 / cond.musicSource.pitch) - 0.317; + var zoomStartTime = currentDspTime + (double)(cond.pitchedSecPerBeat * 2) - 0.317; Jukebox.PlayOneShotScheduledGame("forkLifter/zoomFast", (double)zoomStartTime); GetComponentInChildren().sprite = ForkLifter.instance.peaSprites[type];