From d2bc7d98711a4ee7e53637a9faaef5c43cacc120 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] 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 2581694e..7dc8234d 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 dac3fdd6..cccf4e2f 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 ea12cef2..c128d806 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 01d985c9..caf13617 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 ff0d9237..33c39a53 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 7791a557..c89fd971 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 31145224..03caf604 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() {