diff --git a/Assets/Scripts/Games/ClappyTrio/ClappyTrio.cs b/Assets/Scripts/Games/ClappyTrio/ClappyTrio.cs index 2e1d94adc..b43cea3b8 100644 --- a/Assets/Scripts/Games/ClappyTrio/ClappyTrio.cs +++ b/Assets/Scripts/Games/ClappyTrio/ClappyTrio.cs @@ -72,9 +72,13 @@ namespace HeavenStudio.Games public static ClappyTrio instance { get; set; } + MultiSound clapSounds = null; + BeatAction clapAction = null; + private void Awake() { instance = this; + clapSounds = null; InitLions(); } public override void OnGameSwitch(float beat) @@ -108,52 +112,16 @@ namespace HeavenStudio.Games ClappyTrioPlayer = lion.AddComponent(); } + if (clapSounds != null) + clapSounds.Delete(); + + if (clapAction != null) + clapAction.Delete(); } private void Update() { - if (isClapping) - { - float songPosBeat = Conductor.instance.songPositionInBeats; - for (int i = 0; i < Lion.Count; i++) - { - float length = currentClappingLength * (i); - float lengthplusone = (currentClappingLength * (i + 1)); - - // i spent like 25 minutes trying to figure out what was wrong with this when i forgot to subtract the currentClapLength :( - if (i == Lion.Count - 1) - { - length = 0; - } - - if (songPosBeat > lastClapStart + length && songPosBeat < lastClapStart + lengthplusone && clapIndex == i) - { - if (i == Lion.Count - 1) - { - ClappyTrioPlayer.SetClapAvailability(lastClapStart + (currentClappingLength * (i - 1)), currentClappingLength); - - clapIndex = 0; - isClapping = false; - currentClappingLength = 0; - ClappyTrioPlayer.clapStarted = false; - } else - { - SetFace(i, 4); - Lion[i].GetComponent().Play("Clap", 0, 0); - - // lazy fix rn - if (i > 0) - Jukebox.PlayOneShotGame("clappyTrio/middleClap"); - else - Jukebox.PlayOneShotGame("clappyTrio/leftClap"); - - clapIndex++; - } - break; - } - } - } } public void Clap(float beat, float length) @@ -163,8 +131,21 @@ namespace HeavenStudio.Games playerHitLast = false; isClapping = true; - lastClapStart = beat; - currentClappingLength = length; + + // makes the other lions clap + List sounds = new List(); + List actions = new List(); + for (int i = 0; i < Lion.Count - 1; i++) + { + int idx = i; + sounds.Add(new MultiSound.Sound((i > 0) ? "clappyTrio/middleClap" : "clappyTrio/leftClap", beat + (length * i))); + actions.Add(new BeatAction.Action(beat + (length * i), delegate { SetFace(idx, 4); Lion[idx].GetComponent().Play("Clap", 0, 0);})); + } + clapSounds = MultiSound.Play(sounds.ToArray()); + clapAction = BeatAction.New(this.gameObject, actions); + + // prepare player input + ClappyTrioPlayer.QueueClap(beat, length * (Lion.Count - 1)); } public void Prepare(int type) diff --git a/Assets/Scripts/Games/ClappyTrio/ClappyTrioPlayer.cs b/Assets/Scripts/Games/ClappyTrio/ClappyTrioPlayer.cs index 0b7a27b49..f4466c28d 100644 --- a/Assets/Scripts/Games/ClappyTrio/ClappyTrioPlayer.cs +++ b/Assets/Scripts/Games/ClappyTrio/ClappyTrioPlayer.cs @@ -8,84 +8,81 @@ namespace HeavenStudio.Games.Scripts_ClappyTrio { public class ClappyTrioPlayer : PlayerActionObject { + ClappyTrio game; private float lastClapBeat; private float lastClapLength; - [SerializeField] private bool clapVacant; public bool clapStarted = false; public bool canHit; private GameObject clapEffect; - new int aceTimes = 0; private void Awake() { + game = ClappyTrio.instance; clapEffect = transform.GetChild(4).GetChild(3).gameObject; } - public override void OnAce() - { - if (aceTimes == 0) - { - Clap(true); - aceTimes++; - } - } - private void Update() { - if (clapVacant == true) - { - float normalizedBeat = (Conductor.instance.GetPositionFromBeat(lastClapBeat, lastClapLength)); - - StateCheck(normalizedBeat); - - if (normalizedBeat > Minigame.EndTime()) - { - clapVacant = false; - lastClapLength = 0; - lastClapBeat = 0; - } - } - - if (PlayerInput.Pressed()) + if (PlayerInput.Pressed() && !game.IsExpectingInputNow(InputType.STANDARD_DOWN)) { Clap(false); } - } - public void SetClapAvailability(float startBeat, float length) + public void QueueClap(float startBeat, float length) { - aceTimes = 0; lastClapBeat = startBeat; - clapVacant = true; lastClapLength = length; - ResetState(); + game.ScheduleInput(startBeat, length, InputType.STANDARD_DOWN, Just, Miss, Out); } - private void Clap(bool overrideCanHit) + private void Just(PlayerActionEvent caller, float state) { - if (state.early || state.perfect || overrideCanHit) + if (!canHit) { + Clap(false); + return; + } + if (state >= 1f || state <= -1f) { //todo: proper near miss feedback + Clap(false); + return; + } + Clap(true); + } + + private void Miss(PlayerActionEvent caller) { + game.playerHitLast = false; + + if (clapStarted) + this.canHit = false; + } + + private void Out(PlayerActionEvent caller) {} + + private void Clap(bool just) + { + if (just) { clapEffect.SetActive(true); Jukebox.PlayOneShotGame("clappyTrio/rightClap"); if (this.canHit) - ClappyTrio.instance.playerHitLast = true; + game.playerHitLast = true; } else { clapEffect.SetActive(false); Jukebox.PlayOneShot("miss"); - ClappyTrio.instance.playerHitLast = false; + game.playerHitLast = false; if (clapStarted) this.canHit = false; } - ClappyTrio.instance.SetFace(ClappyTrio.instance.Lion.Count - 1, 4); + clapStarted = false; + game.SetFace(game.Lion.Count - 1, 4); this.GetComponent().Play("Clap", 0, 0); } } diff --git a/Assets/Scripts/Util/BeatAction.cs b/Assets/Scripts/Util/BeatAction.cs index 60d81c8f2..a45b17982 100644 --- a/Assets/Scripts/Util/BeatAction.cs +++ b/Assets/Scripts/Util/BeatAction.cs @@ -13,25 +13,27 @@ namespace HeavenStudio.Util public class Action { - public float beat { get; set; } + public double beat { get; set; } public EventCallback function { get; set; } - public Action(float beat, EventCallback function) + public Action(double beat, EventCallback function) { this.beat = beat; this.function = function; } } - public static void New(GameObject prefab, List actions) + public static BeatAction New(GameObject prefab, List actions) { BeatAction beatAction = prefab.AddComponent(); beatAction.actions = actions; + + return beatAction; } private void Update() { - float songPositionInBeats = Conductor.instance.songPositionInBeats; + double songPositionInBeats = Conductor.instance.songPositionInBeatsAsDouble; for (int i = 0; i < actions.Count; i++) { @@ -42,6 +44,11 @@ namespace HeavenStudio.Util } } } + + public void Delete() + { + Destroy(this); + } } } \ No newline at end of file