From 7e291e0bfafaf2e7f5beac7254b697732b964537 Mon Sep 17 00:00:00 2001 From: Slaith <34562469+Slaith12@users.noreply.github.com> Date: Wed, 2 Mar 2022 13:59:35 -0800 Subject: [PATCH 1/5] Added inactive functions I'm going to flesh it out more in the next commit --- Assets/Scripts/EventCaller.cs | 12 ++++-- Assets/Scripts/GameManager.cs | 42 +++++++++++++------ Assets/Scripts/Games/ForkLifter/ForkLifter.cs | 1 + Assets/Scripts/Games/Minigame.cs | 15 +++++++ Assets/Scripts/Games/SpaceSoccer/Ball.cs | 15 ------- .../Scripts/Games/SpaceSoccer/SpaceSoccer.cs | 23 +++++++++- Assets/Scripts/Minigames.cs | 32 ++++++++++---- 7 files changed, 101 insertions(+), 39 deletions(-) diff --git a/Assets/Scripts/EventCaller.cs b/Assets/Scripts/EventCaller.cs index 2581694e3..7dc8234d5 100644 --- a/Assets/Scripts/EventCaller.cs +++ b/Assets/Scripts/EventCaller.cs @@ -60,7 +60,7 @@ namespace RhythmHeavenMania } - public void CallEvent(Beatmap.Entity entity) + public void CallEvent(Beatmap.Entity entity, bool gameActive) { string[] details = entity.datamodel.Split('/'); Minigames.Minigame game = minigames.Find(c => c.name == details[0]); @@ -71,8 +71,14 @@ namespace RhythmHeavenMania if (details.Length > 2) currentSwitchGame = details[2]; Minigames.GameAction action = game.actions.Find(c => c.actionName == details[1]); - action.function.Invoke(); - + if (gameActive) + { + action.function.Invoke(); + } + else + { + action.inactiveFunction.Invoke(); + } } catch (Exception ex) { diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index dac3fdd6e..cccf4e2f4 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -26,7 +26,7 @@ namespace RhythmHeavenMania public Games.Global.Flash fade; [Header("Games")] - public string currentGame; + public Minigame currentGame; Coroutine currentGameSwitchIE; [Header("Properties")] @@ -157,25 +157,29 @@ namespace RhythmHeavenMania if (Conductor.instance.songPositionInBeats >= entities[currentEvent] /*&& SongPosLessThanClipLength(Conductor.instance.songPositionInBeats)*/) { // allows for multiple events on the same beat to be executed on the same frame, so no more 1-frame delay - var entitesAtSameBeat = Beatmap.entities.FindAll(c => c.beat == Beatmap.entities[currentEvent].beat && !EventCaller.FXOnlyGames().Contains(EventCaller.instance.GetMinigame(c.datamodel.Split('/')[0]))); + var entitiesAtSameBeat = Beatmap.entities.FindAll(c => c.beat == Beatmap.entities[currentEvent].beat && !EventCaller.FXOnlyGames().Contains(EventCaller.instance.GetMinigame(c.datamodel.Split('/')[0]))); var fxEntities = Beatmap.entities.FindAll(c => c.beat == Beatmap.entities[currentEvent].beat && EventCaller.FXOnlyGames().Contains(EventCaller.instance.GetMinigame(c.datamodel.Split('/')[0]))); // FX entities should ALWAYS execute before gameplay entities for (int i = 0; i < fxEntities.Count; i++) { - eventCaller.CallEvent(fxEntities[i]); + eventCaller.CallEvent(fxEntities[i], true); currentEvent++; } - for (int i = 0; i < entitesAtSameBeat.Count; i++) + for (int i = 0; i < entitiesAtSameBeat.Count; i++) { - var entity = entitesAtSameBeat[i]; + var entity = entitiesAtSameBeat[i]; // if game isn't loaded, preload game so whatever event that would be called will still run outside if needed - if (entitesAtSameBeat[i].datamodel.Split('/')[0] != currentGame && !preloadedGames.Contains(preloadedGames.Find(c => c.name == entitesAtSameBeat[i].datamodel.Split('/')[0]))) + if (entitiesAtSameBeat[i].datamodel.Split('/')[0] != currentGame && !preloadedGames.Contains(preloadedGames.Find(c => c.name == entitiesAtSameBeat[i].datamodel.Split('/')[0]))) { - PreloadGame(entitesAtSameBeat[i].datamodel.Split('/')[0]); + //PreloadGame(entitesAtSameBeat[i].datamodel.Split('/')[0]); + eventCaller.CallEvent(entitiesAtSameBeat[i], false); + } + else + { + eventCaller.CallEvent(entitiesAtSameBeat[i], true); } - eventCaller.CallEvent(entitesAtSameBeat[i]); // Thank you to @shshwdr for bring this to my attention currentEvent++; @@ -362,7 +366,6 @@ namespace RhythmHeavenMania currentGameO.transform.parent = eventCaller.GamesHolder.transform; currentGameO.name = game; } - /*if (onGameSwitch) { if (GetGame(currentGame).GetComponent() != null) @@ -370,6 +373,9 @@ namespace RhythmHeavenMania }*/ SetCurrentGame(game); + Minigame miniGame = currentGameO.GetComponent(); + if (miniGame != null) + miniGame.OnGameSwitch(); ResetCamera(); } @@ -411,13 +417,23 @@ namespace RhythmHeavenMania return EventCaller.instance.minigames.Find(c => c.name == name); } - // never gonna use this - public Minigames.Minigame GetCurrentGame() + public Minigames.Minigame GetGameInfo(Minigame game) { - return eventCaller.minigames.Find(c => c.name == transform.GetComponentsInChildren()[1].name); + if (game == null) + return null; + return GetGameInfo(game.name); + } + + public string GetCurrentGameName() + { + if(currentGame == null) + { + return "noGame"; + } + return currentGame.name; } - public void SetCurrentGame(string game) + public void SetCurrentGame(Minigame game) { currentGame = game; if (GetGameInfo(currentGame) != null) CircleCursor.InnerCircle.GetComponent().color = Colors.Hex2RGB(GetGameInfo(currentGame).color); diff --git a/Assets/Scripts/Games/ForkLifter/ForkLifter.cs b/Assets/Scripts/Games/ForkLifter/ForkLifter.cs index ea12cef27..c128d8064 100644 --- a/Assets/Scripts/Games/ForkLifter/ForkLifter.cs +++ b/Assets/Scripts/Games/ForkLifter/ForkLifter.cs @@ -39,6 +39,7 @@ namespace RhythmHeavenMania.Games.ForkLifter public override void OnGameSwitch() { + base.OnGameSwitch(); ForkLifterHand.CheckNextFlick(); } diff --git a/Assets/Scripts/Games/Minigame.cs b/Assets/Scripts/Games/Minigame.cs index 01d985c96..caf136175 100644 --- a/Assets/Scripts/Games/Minigame.cs +++ b/Assets/Scripts/Games/Minigame.cs @@ -44,9 +44,24 @@ namespace RhythmHeavenMania.Games public int firstEnable = 0; + public string name = ""; + public virtual void OnGameSwitch() { + //Below is a template that can be used for handling previous entities. There are multiple sections that have different functions, you don't need to use all of them + + float beat = Conductor.instance.songPositionInBeats; + List prevEntities = GameManager.instance.Beatmap.entities.FindAll(c => c.beat <= beat && c.datamodel.Split(0) == name); + //section below is if you only want to look at entities that overlap the game switch + foreach(Beatmap.Entity entity in prevEntities) + { + if(entity.beat + entity.length >= beat) + { + + } + } + } public virtual void OnTimeChange() diff --git a/Assets/Scripts/Games/SpaceSoccer/Ball.cs b/Assets/Scripts/Games/SpaceSoccer/Ball.cs index ff0d92371..33c39a53a 100644 --- a/Assets/Scripts/Games/SpaceSoccer/Ball.cs +++ b/Assets/Scripts/Games/SpaceSoccer/Ball.cs @@ -44,21 +44,6 @@ namespace RhythmHeavenMania.Games.SpaceSoccer startBeat = dispensedBeat; nextAnimBeat = startBeat + GetAnimLength(State.Dispensing); kicker.kickTimes = 0; - if (kicker.player) - { - MultiSound.Play(new MultiSound.Sound[] - { - new MultiSound.Sound("spaceSoccer/dispenseNoise", dispensedBeat), - new MultiSound.Sound("spaceSoccer/dispenseTumble1", dispensedBeat + 0.25f), - new MultiSound.Sound("spaceSoccer/dispenseTumble2", dispensedBeat + 0.5f), - new MultiSound.Sound("spaceSoccer/dispenseTumble2B",dispensedBeat + 0.5f), - new MultiSound.Sound("spaceSoccer/dispenseTumble3", dispensedBeat + 0.75f), - new MultiSound.Sound("spaceSoccer/dispenseTumble4", dispensedBeat + 1f), - new MultiSound.Sound("spaceSoccer/dispenseTumble5", dispensedBeat + 1.25f), - new MultiSound.Sound("spaceSoccer/dispenseTumble6", dispensedBeat + 1.5f), - new MultiSound.Sound("spaceSoccer/dispenseTumble6B",dispensedBeat + 1.75f), - }); - } return; } diff --git a/Assets/Scripts/Games/SpaceSoccer/SpaceSoccer.cs b/Assets/Scripts/Games/SpaceSoccer/SpaceSoccer.cs index 7791a5579..c89fd9715 100644 --- a/Assets/Scripts/Games/SpaceSoccer/SpaceSoccer.cs +++ b/Assets/Scripts/Games/SpaceSoccer/SpaceSoccer.cs @@ -44,23 +44,44 @@ namespace RhythmHeavenMania.Games.SpaceSoccer { } + public void Dispense(float beat) { + ballDispensed = true; for (int i = 0; i < kickers.Count; i++) { Kicker kicker = kickers[i]; if (i == 0) kicker.player = true; if (kicker.ball != null) return; - ballDispensed = true; GameObject ball = Instantiate(ballRef, transform); ball.SetActive(true); Ball ball_ = ball.GetComponent(); ball_.Init(kicker, beat); + if (kicker.player) + { + DispenseSound(beat); + } } } + + public static void DispenseSound(float beat) + { + MultiSound.Play(new MultiSound.Sound[] + { + new MultiSound.Sound("games/spaceSoccer/dispenseNoise", beat), + new MultiSound.Sound("games/spaceSoccer/dispenseTumble1", beat + 0.25f), + new MultiSound.Sound("games/spaceSoccer/dispenseTumble2", beat + 0.5f), + new MultiSound.Sound("games/spaceSoccer/dispenseTumble2B",beat + 0.5f), + new MultiSound.Sound("games/spaceSoccer/dispenseTumble3", beat + 0.75f), + new MultiSound.Sound("games/spaceSoccer/dispenseTumble4", beat + 1f), + new MultiSound.Sound("games/spaceSoccer/dispenseTumble5", beat + 1.25f), + new MultiSound.Sound("games/spaceSoccer/dispenseTumble6", beat + 1.5f), + new MultiSound.Sound("games/spaceSoccer/dispenseTumble6B",beat + 1.75f), + }, false); + } } } \ No newline at end of file diff --git a/Assets/Scripts/Minigames.cs b/Assets/Scripts/Minigames.cs index 311452246..03caf604a 100644 --- a/Assets/Scripts/Minigames.cs +++ b/Assets/Scripts/Minigames.cs @@ -50,12 +50,21 @@ namespace RhythmHeavenMania public bool resizable; public List parameters; public bool hidden; + public EventCallback inactiveFunction; - /* If you want to add additional arguments to GameAction, leave `bool hidden = false` as the last parameter - * You can specify an action as hidden by adding `hidden: value` as the final parameter in your call - * (Even if you haven't used all prior arguments) - */ - public GameAction(string actionName, EventCallback function, float defaultLength = 1, bool resizable = false, List parameters = null, bool hidden = false) + /// + /// Creates a block that can be used in the editor. The block's function and attributes are defined in the parentheses. + /// Note: Every parameter after the second one is an optional parameter. You can change optional parameters by adding (name): (value) after the second parameter. + /// + /// Name of the block + /// What the block does when read during playback + /// Only does this if the game that it is associated with is loaded. + /// How long the block appears in the editor + /// Allows the user to resize the block + /// Extra parameters for this block that change how it functions. + /// Prevents the block from being shown in the game list. Block will still function normally if it is in the timeline. + /// What the block does when read while the game it's associated with isn't loaded. + public GameAction(string actionName, EventCallback function, float defaultLength = 1, bool resizable = false, List parameters = null, bool hidden = false, EventCallback inactiveFunction = null) { this.actionName = actionName; this.function = function; @@ -63,6 +72,8 @@ namespace RhythmHeavenMania this.resizable = resizable; this.parameters = parameters; this.hidden = hidden; + if(inactiveFunction == null) inactiveFunction = delegate { }; + this.inactiveFunction = inactiveFunction; } } @@ -74,6 +85,12 @@ namespace RhythmHeavenMania public string propertyCaption; public string tooltip; + /// + /// A parameter that changes the function of a GameAction. + /// + /// The name of the variable that's being changed. Must be one of the variables in + /// The value of the parameter + /// The name shown in the editor. Can be anything you want. public Param(string propertyName, object parameter, string propertyCaption, string tooltip = "") { this.propertyName = propertyName; @@ -91,7 +108,7 @@ namespace RhythmHeavenMania { new Minigame("gameManager", "Game Manager", "", false, true, new List() { - new GameAction("switchGame", delegate { GameManager.instance.SwitchGame(eventCaller.currentSwitchGame); }, 0.5f), + new GameAction("switchGame", delegate { GameManager.instance.SwitchGame(eventCaller.currentSwitchGame); }, 0.5f, inactiveFunction: delegate { GameManager.instance.SwitchGame(eventCaller.currentSwitchGame); }), new GameAction("end", delegate { Debug.Log("end"); }), new GameAction("skill star", delegate { }, 1f, true), new GameAction("flash", delegate @@ -271,7 +288,8 @@ namespace RhythmHeavenMania }), new Minigame("spaceSoccer", "Space Soccer", "B888F8", false, false, new List() { - new GameAction("ball dispense", delegate { SpaceSoccer.instance.Dispense(eventCaller.currentEntity.beat); }, 2f), + new GameAction("ball dispense", delegate { SpaceSoccer.instance.Dispense(eventCaller.currentEntity.beat); }, 2f, + inactiveFunction: delegate { SpaceSoccer.DispenseSound(eventCaller.currentEntity.beat); }), new GameAction("keep-up", delegate { }, 4f, true), new GameAction("high kick-toe!", delegate { }, 3f, false, new List() { From 896f4a450ae232dacb7685af6d2342cff847865a Mon Sep 17 00:00:00 2001 From: Slaith <34562469+Slaith12@users.noreply.github.com> Date: Sun, 6 Mar 2022 18:37:27 -0800 Subject: [PATCH 2/5] clean up --- Assets/Scripts/EventCaller.cs | 2 +- Assets/Scripts/GameManager.cs | 22 +++------------------- Assets/Scripts/Games/Minigame.cs | 15 ++++++--------- 3 files changed, 10 insertions(+), 29 deletions(-) diff --git a/Assets/Scripts/EventCaller.cs b/Assets/Scripts/EventCaller.cs index 7dc8234d5..519840685 100644 --- a/Assets/Scripts/EventCaller.cs +++ b/Assets/Scripts/EventCaller.cs @@ -82,7 +82,7 @@ namespace RhythmHeavenMania } catch (Exception ex) { - Debug.LogWarning("Event not found! May be spelled wrong or it is not implemented." + ex); + Debug.LogWarning("Event not found! May be spelled wrong or it is not implemented.\n" + ex); } } diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index cccf4e2f4..36236f359 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -26,7 +26,7 @@ namespace RhythmHeavenMania public Games.Global.Flash fade; [Header("Games")] - public Minigame currentGame; + public string currentGame; Coroutine currentGameSwitchIE; [Header("Properties")] @@ -372,10 +372,10 @@ namespace RhythmHeavenMania GetGame(game).GetComponent().OnGameSwitch(); }*/ - SetCurrentGame(game); Minigame miniGame = currentGameO.GetComponent(); if (miniGame != null) miniGame.OnGameSwitch(); + SetCurrentGame(game); ResetCamera(); } @@ -417,23 +417,7 @@ namespace RhythmHeavenMania return EventCaller.instance.minigames.Find(c => c.name == name); } - public Minigames.Minigame GetGameInfo(Minigame game) - { - if (game == null) - return null; - return GetGameInfo(game.name); - } - - public string GetCurrentGameName() - { - if(currentGame == null) - { - return "noGame"; - } - return currentGame.name; - } - - public void SetCurrentGame(Minigame game) + public void SetCurrentGame(string game) { currentGame = game; if (GetGameInfo(currentGame) != null) CircleCursor.InnerCircle.GetComponent().color = Colors.Hex2RGB(GetGameInfo(currentGame).color); diff --git a/Assets/Scripts/Games/Minigame.cs b/Assets/Scripts/Games/Minigame.cs index caf136175..def63233c 100644 --- a/Assets/Scripts/Games/Minigame.cs +++ b/Assets/Scripts/Games/Minigame.cs @@ -44,24 +44,21 @@ namespace RhythmHeavenMania.Games public int firstEnable = 0; - public string name = ""; - public virtual void OnGameSwitch() { - //Below is a template that can be used for handling previous entities. There are multiple sections that have different functions, you don't need to use all of them - - float beat = Conductor.instance.songPositionInBeats; - List prevEntities = GameManager.instance.Beatmap.entities.FindAll(c => c.beat <= beat && c.datamodel.Split(0) == name); - + //Below is a template that can be used for handling previous entities. //section below is if you only want to look at entities that overlap the game switch + /* + float beat = Conductor.instance.songPositionInBeats; + List prevEntities = GameManager.instance.Beatmap.entities.FindAll(c => c.beat <= beat && c.datamodel.Split(0) == [insert game name]); foreach(Beatmap.Entity entity in prevEntities) { if(entity.beat + entity.length >= beat) { - + EventCaller.instance.CallEvent(entity, true); } } - + */ } public virtual void OnTimeChange() From 2d328229c93ca8639f1de6241e0a7c4fa05eadb8 Mon Sep 17 00:00:00 2001 From: Slaith <34562469+Slaith12@users.noreply.github.com> Date: Sun, 6 Mar 2022 19:56:45 -0800 Subject: [PATCH 3/5] Gave sound objects a little more functionality --- Assets/Scripts/Util/MultiSound.cs | 11 +++++++++-- Assets/Scripts/Util/Sound.cs | 8 +++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/Util/MultiSound.cs b/Assets/Scripts/Util/MultiSound.cs index 270094ff4..9e6b441b9 100644 --- a/Assets/Scripts/Util/MultiSound.cs +++ b/Assets/Scripts/Util/MultiSound.cs @@ -25,7 +25,7 @@ namespace RhythmHeavenMania.Util } - public static void Play(Sound[] snds, bool game = true) + public static MultiSound Play(Sound[] snds, bool game = true) { List sounds = snds.ToList(); GameObject gameObj = new GameObject(); @@ -36,6 +36,7 @@ namespace RhythmHeavenMania.Util gameObj.name = "MultiSound"; GameManager.instance.SoundObjects.Add(gameObj); + return ms; } private void Update() @@ -57,8 +58,14 @@ namespace RhythmHeavenMania.Util if (songPositionInBeats >= (sounds[sounds.Count - 1].beat)) { - Destroy(this.gameObject); + Delete(); } } + + public void Delete() + { + GameManager.instance.SoundObjects.Remove(gameObject); + Destroy(gameObject); + } } } \ No newline at end of file diff --git a/Assets/Scripts/Util/Sound.cs b/Assets/Scripts/Util/Sound.cs index b4b13799a..4e5773c37 100644 --- a/Assets/Scripts/Util/Sound.cs +++ b/Assets/Scripts/Util/Sound.cs @@ -70,7 +70,13 @@ namespace RhythmHeavenMania.Util IEnumerator NotRelyOnBeatSound() { yield return new WaitForSeconds(clip.length); - Destroy(this.gameObject); + Delete(); + } + + public void Delete() + { + GameManager.instance.SoundObjects.Remove(gameObject); + Destroy(gameObject); } } } From fca105259c76881b056e78382502da9a94587521 Mon Sep 17 00:00:00 2001 From: Slaith <34562469+Slaith12@users.noreply.github.com> Date: Mon, 7 Mar 2022 20:46:49 -0800 Subject: [PATCH 4/5] Implemented inactive functions for all game count ins Also made some changes to how SwitchGame(), OnGameSwitch, and the jukebox work. --- Assets/Scripts/GameManager.cs | 18 ++-- Assets/Scripts/Games/CropStomp/CropStomp.cs | 102 ++++++++++++------ Assets/Scripts/Games/ForkLifter/ForkLifter.cs | 4 +- Assets/Scripts/Games/KarateMan/KarateMan.cs | 4 +- Assets/Scripts/Games/Minigame.cs | 3 +- Assets/Scripts/Games/MrUpbeat/MrUpbeat.cs | 41 +++++++ .../Scripts/Games/SpaceSoccer/SpaceSoccer.cs | 42 +++++--- Assets/Scripts/Games/Spaceball/Spaceball.cs | 2 +- Assets/Scripts/Minigames.cs | 6 +- Assets/Scripts/Util/Jukebox.cs | 8 +- Assets/Scripts/Util/MultiSound.cs | 6 +- 11 files changed, 169 insertions(+), 67 deletions(-) diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 36236f359..c40d57e16 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -173,7 +173,6 @@ namespace RhythmHeavenMania // if game isn't loaded, preload game so whatever event that would be called will still run outside if needed if (entitiesAtSameBeat[i].datamodel.Split('/')[0] != currentGame && !preloadedGames.Contains(preloadedGames.Find(c => c.name == entitiesAtSameBeat[i].datamodel.Split('/')[0]))) { - //PreloadGame(entitesAtSameBeat[i].datamodel.Split('/')[0]); eventCaller.CallEvent(entitiesAtSameBeat[i], false); } else @@ -316,28 +315,34 @@ namespace RhythmHeavenMania #endregion - public void SwitchGame(string game) + public void SwitchGame(string game, float beat) { if (game != currentGame) { if (currentGameSwitchIE != null) StopCoroutine(currentGameSwitchIE); - currentGameSwitchIE = StartCoroutine(SwitchGameIE(game)); + currentGameSwitchIE = StartCoroutine(SwitchGameIE(game, beat)); } } - IEnumerator SwitchGameIE(string game) + IEnumerator SwitchGameIE(string game, float beat) { this.GetComponent().enabled = true; SetGame(game); + yield return new WaitForEndOfFrame(); //this is needed so that the minigame can have Start() called before OnGameSwitch() + + Minigame miniGame = currentGameO.GetComponent(); + if (miniGame != null) + miniGame.OnGameSwitch(beat); + yield return new WaitForSeconds(0.1f); this.GetComponent().enabled = false; } - private void SetGame(string game, bool onGameSwitch = true) + private void SetGame(string game, bool onGameSwitch = true) { Destroy(currentGameO); @@ -372,9 +377,6 @@ namespace RhythmHeavenMania GetGame(game).GetComponent().OnGameSwitch(); }*/ - Minigame miniGame = currentGameO.GetComponent(); - if (miniGame != null) - miniGame.OnGameSwitch(); SetCurrentGame(game); ResetCamera(); diff --git a/Assets/Scripts/Games/CropStomp/CropStomp.cs b/Assets/Scripts/Games/CropStomp/CropStomp.cs index bac0e4e91..472023369 100644 --- a/Assets/Scripts/Games/CropStomp/CropStomp.cs +++ b/Assets/Scripts/Games/CropStomp/CropStomp.cs @@ -1,11 +1,9 @@ -using System.Collections; +using DG.Tweening; +using NaughtyBezierCurves; +using RhythmHeavenMania.Util; +using System; using System.Collections.Generic; using UnityEngine; -using System; -using NaughtyBezierCurves; -using DG.Tweening; - -using RhythmHeavenMania.Util; namespace RhythmHeavenMania.Games.CropStomp { @@ -24,6 +22,7 @@ namespace RhythmHeavenMania.Games.CropStomp private int currentMarchBeat; private int stepCount; private bool isStepping; + private static float inactiveStart = -1f; public bool isMarching => marchStartBeat != -1f; @@ -118,6 +117,21 @@ namespace RhythmHeavenMania.Games.CropStomp } } + public override void OnGameSwitch(float beat) + { + if(inactiveStart != -1f) + { + StartMarching(inactiveStart); + float diff = beat - marchStartBeat; + newBeat = (Mathf.Ceil(diff) + marchStartBeat-1)*Conductor.instance.secPerBeat; + currentMarchBeat = Mathf.CeilToInt(diff); + stepCount = currentMarchBeat / 2; + farmer.nextStompBeat = newBeat/Conductor.instance.secPerBeat; + inactiveStart = -1f; + PlayAnims(); + } + } + List cuedMoleSounds = new List(); private void Update() { @@ -143,38 +157,17 @@ namespace RhythmHeavenMania.Games.CropStomp if (!isMarching) return; + Debug.Log(newBeat); if (cond.ReportBeat(ref newBeat, marchOffset, true)) { currentMarchBeat += 1; - // Step. - if (currentMarchBeat % 2 != 0) + PlayAnims(); + if (currentMarchBeat % 2 != 0) //step sound { - // Don't step if already stomped. - if (!isStepping) - { - stepCount += 1; - var stepAnim = (stepCount % 2 != 0 ? "StepFront" : "StepBack"); - - legsAnim.Play(stepAnim, 0, 0); - - isStepping = true; - } - Jukebox.PlayOneShotGame("cropStomp/hmm"); } - // Lift. - else - { - var liftAnim = (stepCount % 2 != 0 ? "LiftBack" : "LiftFront"); - legsAnim.Play(liftAnim, 0, 0); - - var farmerPos = farmerTrans.localPosition; - farmerTrans.localPosition = new Vector3(farmerPos.x - stepDistance, farmerPos.y, farmerPos.z); - - isStepping = false; - } } // Object scroll. @@ -214,6 +207,36 @@ namespace RhythmHeavenMania.Games.CropStomp isFlicking = false; } + private void PlayAnims() + { + // Step. + if (currentMarchBeat % 2 != 0) + { + // Don't step if already stomped. + if (!isStepping) + { + stepCount += 1; + var stepAnim = (stepCount % 2 != 0 ? "StepFront" : "StepBack"); + + legsAnim.Play(stepAnim, 0, 0); + + isStepping = true; + } + + } + // Lift. + else + { + var liftAnim = (stepCount % 2 != 0 ? "LiftBack" : "LiftFront"); + legsAnim.Play(liftAnim, 0, 0); + + var farmerPos = farmerTrans.localPosition; + farmerTrans.localPosition = new Vector3(farmerPos.x - stepDistance, farmerPos.y, farmerPos.z); + + isStepping = false; + } + } + public void StartMarching(float beat) { marchStartBeat = beat; @@ -257,5 +280,24 @@ namespace RhythmHeavenMania.Games.CropStomp newVeggie.gameObject.SetActive(true); } + + public static void MarchInactive(float beat) + { + if (GameManager.instance.currentGame == "cropStomp") //this function is only meant for making march sounds while the game is inactive + { + return; + } + inactiveStart = beat; + Beatmap.Entity gameSwitch = GameManager.instance.Beatmap.entities.Find(c => c.beat >= beat && c.datamodel == "gameManager/switchGame/cropStomp"); + if (gameSwitch == null) + return; + int length = Mathf.CeilToInt((gameSwitch.beat - beat)/2); + MultiSound.Sound[] sounds = new MultiSound.Sound[length]; + for(int i = 0; i < length; i++) + { + sounds[i] = new MultiSound.Sound("cropStomp/hmm", beat + i*2); + } + MultiSound.Play(sounds, forcePlay:true); + } } } diff --git a/Assets/Scripts/Games/ForkLifter/ForkLifter.cs b/Assets/Scripts/Games/ForkLifter/ForkLifter.cs index c128d8064..310df41f6 100644 --- a/Assets/Scripts/Games/ForkLifter/ForkLifter.cs +++ b/Assets/Scripts/Games/ForkLifter/ForkLifter.cs @@ -37,9 +37,9 @@ namespace RhythmHeavenMania.Games.ForkLifter instance = this; } - public override void OnGameSwitch() + public override void OnGameSwitch(float beat) { - base.OnGameSwitch(); + base.OnGameSwitch(beat); ForkLifterHand.CheckNextFlick(); } diff --git a/Assets/Scripts/Games/KarateMan/KarateMan.cs b/Assets/Scripts/Games/KarateMan/KarateMan.cs index 04f7f593a..95a23f599 100644 --- a/Assets/Scripts/Games/KarateMan/KarateMan.cs +++ b/Assets/Scripts/Games/KarateMan/KarateMan.cs @@ -120,9 +120,9 @@ namespace RhythmHeavenMania.Games.KarateMan Shadow = 0; } - public override void OnGameSwitch() + public override void OnGameSwitch(float beat) { - base.OnGameSwitch(); + base.OnGameSwitch(beat); SetBackgroundColor((int)BGType, (int)Shadow, BGColor, ShadowColor); } diff --git a/Assets/Scripts/Games/Minigame.cs b/Assets/Scripts/Games/Minigame.cs index def63233c..3d3e02b14 100644 --- a/Assets/Scripts/Games/Minigame.cs +++ b/Assets/Scripts/Games/Minigame.cs @@ -44,12 +44,11 @@ namespace RhythmHeavenMania.Games public int firstEnable = 0; - public virtual void OnGameSwitch() + public virtual void OnGameSwitch(float beat) { //Below is a template that can be used for handling previous entities. //section below is if you only want to look at entities that overlap the game switch /* - float beat = Conductor.instance.songPositionInBeats; List prevEntities = GameManager.instance.Beatmap.entities.FindAll(c => c.beat <= beat && c.datamodel.Split(0) == [insert game name]); foreach(Beatmap.Entity entity in prevEntities) { diff --git a/Assets/Scripts/Games/MrUpbeat/MrUpbeat.cs b/Assets/Scripts/Games/MrUpbeat/MrUpbeat.cs index ac60d8c63..39aca89a5 100644 --- a/Assets/Scripts/Games/MrUpbeat/MrUpbeat.cs +++ b/Assets/Scripts/Games/MrUpbeat/MrUpbeat.cs @@ -14,6 +14,7 @@ namespace RhythmHeavenMania.Games.MrUpbeat public GameObject metronome; public UpbeatMan man; public GameObject bt; + private static MultiSound beeps; //only used when this game isn't active. public GameEvent beat = new GameEvent(); public bool canGo = false; @@ -70,6 +71,28 @@ namespace RhythmHeavenMania.Games.MrUpbeat } } + public override void OnGameSwitch(float beat) + { + foreach (Beatmap.Entity entity in GameManager.instance.Beatmap.entities) + { + if (entity.beat > beat) //the list is sorted based on the beat of the entity, so this should work fine. + { + break; + } + if (entity.datamodel != "mrUpbeat/prepare" || entity.beat + entity.length < beat) //check for prepares that happen before the switch + { + continue; + } + SetInterval(entity.beat); + break; + } + if(beeps != null) + { + beeps.Delete(); //the beeps are only for when the game isn't active + beeps = null; + } + } + public void SetInterval(float beat) { beatCount = 0; @@ -106,5 +129,23 @@ namespace RhythmHeavenMania.Games.MrUpbeat yield return new WaitForSeconds(Conductor.instance.secPerBeat * 0.5f - offset); man.Blip(); } + + public static void Beep(float beat, float length) + { + if(GameManager.instance.currentGame == "mrUpbeat") //this function is only meant for making beeps while the game is inactive + { + return; + } + if (beeps != null) + { + beeps.Delete(); + } + MultiSound.Sound[] beepSounds = new MultiSound.Sound[Mathf.CeilToInt(length)]; + for(int i = 0; i < beepSounds.Length; i++) + { + beepSounds[i] = new MultiSound.Sound("mrUpbeat/blip", beat + 0.5f + i); + } + beeps = MultiSound.Play(beepSounds, forcePlay:true); + } } } \ No newline at end of file diff --git a/Assets/Scripts/Games/SpaceSoccer/SpaceSoccer.cs b/Assets/Scripts/Games/SpaceSoccer/SpaceSoccer.cs index c89fd9715..457139d53 100644 --- a/Assets/Scripts/Games/SpaceSoccer/SpaceSoccer.cs +++ b/Assets/Scripts/Games/SpaceSoccer/SpaceSoccer.cs @@ -44,9 +44,25 @@ namespace RhythmHeavenMania.Games.SpaceSoccer { } - - public void Dispense(float beat) + public override void OnGameSwitch(float beat) + { + foreach(Beatmap.Entity entity in GameManager.instance.Beatmap.entities) + { + if(entity.beat > beat) //the list is sorted based on the beat of the entity, so this should work fine. + { + break; + } + if(entity.datamodel != "spaceSoccer/ball dispense" || entity.beat + entity.length <= beat) //check for dispenses that happen right before the switch + { + continue; + } + Dispense(entity.beat, false); + break; + } + } + + public void Dispense(float beat, bool playSound = true) { ballDispensed = true; for (int i = 0; i < kickers.Count; i++) @@ -60,7 +76,7 @@ namespace RhythmHeavenMania.Games.SpaceSoccer ball.SetActive(true); Ball ball_ = ball.GetComponent(); ball_.Init(kicker, beat); - if (kicker.player) + if (kicker.player && playSound) { DispenseSound(beat); } @@ -71,16 +87,16 @@ namespace RhythmHeavenMania.Games.SpaceSoccer { MultiSound.Play(new MultiSound.Sound[] { - new MultiSound.Sound("games/spaceSoccer/dispenseNoise", beat), - new MultiSound.Sound("games/spaceSoccer/dispenseTumble1", beat + 0.25f), - new MultiSound.Sound("games/spaceSoccer/dispenseTumble2", beat + 0.5f), - new MultiSound.Sound("games/spaceSoccer/dispenseTumble2B",beat + 0.5f), - new MultiSound.Sound("games/spaceSoccer/dispenseTumble3", beat + 0.75f), - new MultiSound.Sound("games/spaceSoccer/dispenseTumble4", beat + 1f), - new MultiSound.Sound("games/spaceSoccer/dispenseTumble5", beat + 1.25f), - new MultiSound.Sound("games/spaceSoccer/dispenseTumble6", beat + 1.5f), - new MultiSound.Sound("games/spaceSoccer/dispenseTumble6B",beat + 1.75f), - }, false); + new MultiSound.Sound("spaceSoccer/dispenseNoise", beat), + new MultiSound.Sound("spaceSoccer/dispenseTumble1", beat + 0.25f), + new MultiSound.Sound("spaceSoccer/dispenseTumble2", beat + 0.5f), + new MultiSound.Sound("spaceSoccer/dispenseTumble2B",beat + 0.5f), + new MultiSound.Sound("spaceSoccer/dispenseTumble3", beat + 0.75f), + new MultiSound.Sound("spaceSoccer/dispenseTumble4", beat + 1f), + new MultiSound.Sound("spaceSoccer/dispenseTumble5", beat + 1.25f), + new MultiSound.Sound("spaceSoccer/dispenseTumble6", beat + 1.5f), + new MultiSound.Sound("spaceSoccer/dispenseTumble6B",beat + 1.75f), + }, forcePlay:true); } } diff --git a/Assets/Scripts/Games/Spaceball/Spaceball.cs b/Assets/Scripts/Games/Spaceball/Spaceball.cs index 7f30ac3b6..fd7d7a105 100644 --- a/Assets/Scripts/Games/Spaceball/Spaceball.cs +++ b/Assets/Scripts/Games/Spaceball/Spaceball.cs @@ -37,7 +37,7 @@ namespace RhythmHeavenMania.Games.Spaceball public static Spaceball instance { get; set; } - public override void OnGameSwitch() + public override void OnGameSwitch(float beat) { for (int i = 1; i < BallsHolder.transform.childCount; i++) Destroy(BallsHolder.transform.GetChild(i).gameObject); diff --git a/Assets/Scripts/Minigames.cs b/Assets/Scripts/Minigames.cs index 00d47a21a..3a7cf2b89 100644 --- a/Assets/Scripts/Minigames.cs +++ b/Assets/Scripts/Minigames.cs @@ -110,7 +110,7 @@ namespace RhythmHeavenMania { new Minigame("gameManager", "Game Manager", "", false, true, new List() { - new GameAction("switchGame", delegate { GameManager.instance.SwitchGame(eventCaller.currentSwitchGame); }, 0.5f, inactiveFunction: delegate { GameManager.instance.SwitchGame(eventCaller.currentSwitchGame); }), + new GameAction("switchGame", delegate { GameManager.instance.SwitchGame(eventCaller.currentSwitchGame, eventCaller.currentEntity.beat); }, 0.5f, inactiveFunction: delegate { GameManager.instance.SwitchGame(eventCaller.currentSwitchGame, eventCaller.currentEntity.beat); }), new GameAction("end", delegate { Debug.Log("end"); }), new GameAction("skill star", delegate { }, 1f, true), new GameAction("flash", delegate @@ -383,7 +383,7 @@ namespace RhythmHeavenMania }), new Minigame("cropStomp", "Crop Stomp", "BFDEA6", false, false, new List() { - new GameAction("start marching", delegate { CropStomp.instance.StartMarching(eventCaller.currentEntity.beat); }, 2f, false), + new GameAction("start marching", delegate { CropStomp.instance.StartMarching(eventCaller.currentEntity.beat); }, 2f, false, inactiveFunction: delegate { CropStomp.MarchInactive(eventCaller.currentEntity.beat); }), new GameAction("veggies", delegate { }, 4f, true), new GameAction("mole", delegate { }, 2f, false), }), @@ -394,7 +394,7 @@ namespace RhythmHeavenMania }), new Minigame("mrUpbeat", "Mr. Upbeat", "FFFFFF", false, false, new List() { - new GameAction("prepare", delegate { MrUpbeat.instance.SetInterval(eventCaller.currentEntity.beat); }, 0.5f, true), + new GameAction("prepare", delegate { MrUpbeat.instance.SetInterval(eventCaller.currentEntity.beat); }, 0.5f, true, inactiveFunction: delegate { MrUpbeat.Beep(eventCaller.currentEntity.beat, eventCaller.currentEntity.length); }), new GameAction("go", delegate { MrUpbeat.instance.Go(eventCaller.currentEntity.beat); }, 4f, true), new GameAction("ding!", delegate { MrUpbeat.instance.Ding(eventCaller.currentEntity.toggle); }, 0.5f, parameters: new List() { diff --git a/Assets/Scripts/Util/Jukebox.cs b/Assets/Scripts/Util/Jukebox.cs index 079039fd8..f2c339a32 100644 --- a/Assets/Scripts/Util/Jukebox.cs +++ b/Assets/Scripts/Util/Jukebox.cs @@ -81,9 +81,9 @@ namespace RhythmHeavenMania.Util return audioSource; } - public static AudioSource PlayOneShotGame(string name, float beat = -1) + public static AudioSource PlayOneShotGame(string name, float beat = -1, bool forcePlay = false) { - if (GameManager.instance.currentGame == name.Split('/')[0]) + if (GameManager.instance.currentGame == name.Split('/')[0] || forcePlay) { return PlayOneShot($"games/{name}", beat); } @@ -91,9 +91,9 @@ namespace RhythmHeavenMania.Util return null; } - public static AudioSource PlayOneShotScheduledGame(string name, double targetTime) + public static AudioSource PlayOneShotScheduledGame(string name, double targetTime, bool forcePlay = false) { - if (GameManager.instance.currentGame == name.Split('/')[0]) + if (GameManager.instance.currentGame == name.Split('/')[0] || forcePlay) { return PlayOneShotScheduled($"games/{name}", targetTime); } diff --git a/Assets/Scripts/Util/MultiSound.cs b/Assets/Scripts/Util/MultiSound.cs index 9e6b441b9..0e238e942 100644 --- a/Assets/Scripts/Util/MultiSound.cs +++ b/Assets/Scripts/Util/MultiSound.cs @@ -10,6 +10,7 @@ namespace RhythmHeavenMania.Util private float startBeat; private int index; private bool game; + private bool forcePlay; public List sounds = new List(); public class Sound @@ -25,7 +26,7 @@ namespace RhythmHeavenMania.Util } - public static MultiSound Play(Sound[] snds, bool game = true) + public static MultiSound Play(Sound[] snds, bool game = true, bool forcePlay = false) { List sounds = snds.ToList(); GameObject gameObj = new GameObject(); @@ -33,6 +34,7 @@ namespace RhythmHeavenMania.Util ms.sounds = sounds; ms.startBeat = sounds[0].beat; ms.game = game; + ms.forcePlay = forcePlay; gameObj.name = "MultiSound"; GameManager.instance.SoundObjects.Add(gameObj); @@ -48,7 +50,7 @@ namespace RhythmHeavenMania.Util if (songPositionInBeats >= sounds[i].beat && index == i) { if (game) - Jukebox.PlayOneShotGame(sounds[i].name); + Jukebox.PlayOneShotGame(sounds[i].name, forcePlay:forcePlay); else Jukebox.PlayOneShot(sounds[i].name); From 0462781aadc0ffea7a6241490ffb64b65be31aa2 Mon Sep 17 00:00:00 2001 From: Slaith <34562469+Slaith12@users.noreply.github.com> Date: Mon, 7 Mar 2022 21:27:36 -0800 Subject: [PATCH 5/5] Fixed error --- Assets/Scripts/Util/Jukebox.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/Util/Jukebox.cs b/Assets/Scripts/Util/Jukebox.cs index aadd87b2d..bb082a710 100644 --- a/Assets/Scripts/Util/Jukebox.cs +++ b/Assets/Scripts/Util/Jukebox.cs @@ -87,7 +87,7 @@ namespace RhythmHeavenMania.Util return audioSource; } - public static AudioSource PlayOneShotGame(string name, float beat = -1, bool forcePlay = false , float pitch = 1f, float volume = 1f, bool looping = false) + public static AudioSource PlayOneShotGame(string name, float beat = -1, float pitch = 1f, float volume = 1f, bool looping = false, bool forcePlay = false) { if (GameManager.instance.currentGame == name.Split('/')[0] || forcePlay) { @@ -97,7 +97,7 @@ namespace RhythmHeavenMania.Util return null; } - public static AudioSource PlayOneShotScheduledGame(string name, double targetTime, bool forcePlay = false, float pitch = 1f, float volume = 1f, bool looping = false) + public static AudioSource PlayOneShotScheduledGame(string name, double targetTime, float pitch = 1f, float volume = 1f, bool looping = false, bool forcePlay = false) { if (GameManager.instance.currentGame == name.Split('/')[0] || forcePlay) {