From cb25e97699bbbba941159b103f6302b382c812ef Mon Sep 17 00:00:00 2001 From: Braedon Date: Sat, 15 Jan 2022 13:46:50 -0500 Subject: [PATCH] Game switching in every game --- Assets/Scenes/Editor.unity | 4 +- Assets/Scripts/GameManager.cs | 26 +++++++++--- .../Games/ForkLifter/ForkLifterHand.cs | 12 +++--- .../Scripts/LevelEditor/GridGameSelector.cs | 40 ++++++++++++++----- Assets/Scripts/LevelEditor/Timeline.cs | 10 ++++- 5 files changed, 68 insertions(+), 24 deletions(-) diff --git a/Assets/Scenes/Editor.unity b/Assets/Scenes/Editor.unity index 0bd0cb68e..94116d9ac 100644 --- a/Assets/Scenes/Editor.unity +++ b/Assets/Scenes/Editor.unity @@ -5944,8 +5944,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: f86858990a87c764892672104bdaef1f, type: 3} m_Name: m_EditorClassIdentifier: - level: {fileID: 4900000, guid: 4b7512c586e16a847a5b8490bf35e852, type: 3} - music: {fileID: 0} + level: {fileID: 4900000, guid: 244c565c8088cfa4597e0ebda9c7de98, type: 3} + music: {fileID: 8300000, guid: e5cf71158cc9bff4a8fbfbca1e73e500, type: 3} debugUI: 0 playOnStart: 0 editor: 1 diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 83f070cf7..d5c70c8e8 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -176,19 +176,33 @@ namespace RhythmHeavenMania currentEvent = entities.IndexOf(Mathp.GetClosestInList(entities, beat)); - var gameSwitchs = Beatmap.entities.FindAll(c => c.datamodel.Split(1) == "switchGame" && c.beat <= beat); + var gameSwitchs = Beatmap.entities.FindAll(c => c.datamodel.Split(1) == "switchGame"); string newGame = Beatmap.entities[currentEvent].datamodel.Split(0); if (gameSwitchs.Count > 0) { - newGame = gameSwitchs[gameSwitchs.IndexOf(gameSwitchs.Find(c => c.beat == Mathp.GetClosestInList(gameSwitchs.Select(c => c.beat).ToList(), beat)))].datamodel.Split(2); + int index = gameSwitchs.FindIndex(c => c.beat == Mathp.GetClosestInList(gameSwitchs.Select(c => c.beat).ToList(), beat)); + var closestGameSwitch = gameSwitchs[index]; + if (closestGameSwitch.beat <= beat) + { + newGame = closestGameSwitch.datamodel.Split(2); + } + else if (closestGameSwitch.beat > beat) + { + if (index - 1 >= 0) + { + newGame = gameSwitchs[index - 1].datamodel.Split(2); + } + else + { + newGame = Beatmap.entities[Beatmap.entities.IndexOf(closestGameSwitch) - 1].datamodel.Split(0); + } + } + // newGame = gameSwitchs[gameSwitchs.IndexOf(gameSwitchs.Find(c => c.beat == Mathp.GetClosestInList(gameSwitchs.Select(c => c.beat).ToList(), beat)))].datamodel.Split(2); } - if (Beatmap.entities[currentEvent].datamodel.Split(1) != "switchGame" && Beatmap.entities[currentEvent].datamodel.Split(0) != "gameManager") - { - SetGame(newGame); - } + SetGame(newGame); } } diff --git a/Assets/Scripts/Games/ForkLifter/ForkLifterHand.cs b/Assets/Scripts/Games/ForkLifter/ForkLifterHand.cs index aedefcbaf..acce84200 100644 --- a/Assets/Scripts/Games/ForkLifter/ForkLifterHand.cs +++ b/Assets/Scripts/Games/ForkLifter/ForkLifterHand.cs @@ -15,11 +15,11 @@ namespace RhythmHeavenMania.Games.ForkLifter public void CheckNextFlick() { - // allPlayerActions = EventCaller.GetAllInGameManagerList("forkLifter", new string[] { "gulp", "sigh", "prepare" }); - var allPlayerActions = EventCaller.GetAllPlayerEntities("forkLifter"); - int currentPlayerEvent = GameManager.instance.currentPlayerEvent - EventCaller.GetAllPlayerEntitiesExceptBeforeBeat("forkLifter", Conductor.instance.songPositionInBeats).Count; + // var allPlayerActions = EventCaller.GetAllInGameManagerList("forkLifter", new string[] { "gulp", "sigh", "prepare" }); + // var allPlayerActions = EventCaller.GetAllPlayerEntities("forkLifter"); + // int currentPlayerEvent = GameManager.instance.currentEvent - EventCaller.GetAllPlayerEntitiesExceptBeforeBeat("forkLifter", Conductor.instance.songPositionInBeats).Count; - if (currentPlayerEvent < allPlayerActions.Count) + /* if (currentPlayerEvent < allPlayerActions.Count) { switch (allPlayerActions[currentPlayerEvent].datamodel.Split('/')[1]) { @@ -44,7 +44,9 @@ namespace RhythmHeavenMania.Games.ForkLifter else { ForkLifter.instance.peaPreview.sprite = null; - } + }*/ + + // will fix later } public void Prepare() diff --git a/Assets/Scripts/LevelEditor/GridGameSelector.cs b/Assets/Scripts/LevelEditor/GridGameSelector.cs index 63f4d6acc..a751a295f 100644 --- a/Assets/Scripts/LevelEditor/GridGameSelector.cs +++ b/Assets/Scripts/LevelEditor/GridGameSelector.cs @@ -48,7 +48,14 @@ namespace RhythmHeavenMania.Editor if (Timeline.instance.CheckIfMouseInTimeline() && dragTimes < 1) { dragTimes++; - Timeline.instance.AddEventObject(mg.name + "/" + mg.actions[currentEventIndex].actionName, true, new Vector3(0, 0)); + if (currentEventIndex == 0) + { + Timeline.instance.AddEventObject($"gameManager/switchGame/{mg.name}", true, new Vector3(0, 0)); + } + else + { + Timeline.instance.AddEventObject(mg.name + "/" + mg.actions[currentEventIndex - 1].actionName, true, new Vector3(0, 0)); + } } } @@ -69,9 +76,9 @@ namespace RhythmHeavenMania.Editor if (currentEventIndex < 0) { - currentEventIndex = mg.actions.Count - 1; + currentEventIndex = EventRef.transform.parent.childCount - 2; } - else if (currentEventIndex > mg.actions.Count - 1) + else if (currentEventIndex > EventRef.transform.parent.childCount - 2) { currentEventIndex = 0; } @@ -100,18 +107,33 @@ namespace RhythmHeavenMania.Editor mg = EventCaller.instance.minigames.Find(c => c.displayName == gameName); - for (int i = 0; i < mg.actions.Count; i++) - { - GameObject e = Instantiate(EventRef, EventRef.transform.parent); - e.GetComponent().text = mg.actions[i].actionName; - e.SetActive(true); - } + AddEvents(); gameOpen = true; currentEventIndex = 0; SetColor(0); } + private void AddEvents() + { + if (mg.name != "gameManager") + { + GameObject sg = Instantiate(EventRef, EventRef.transform.parent); + sg.GetComponent().text = "switchGame"; + sg.SetActive(true); + } + + for (int i = 0; i < mg.actions.Count; i++) + { + if (mg.actions[i].actionName != "switchGame") + { + GameObject e = Instantiate(EventRef, EventRef.transform.parent); + e.GetComponent().text = mg.actions[i].actionName; + e.SetActive(true); + } + } + } + private void SetColor(int ind) { for (int i = 0; i < EventRef.transform.parent.childCount; i++) diff --git a/Assets/Scripts/LevelEditor/Timeline.cs b/Assets/Scripts/LevelEditor/Timeline.cs index 981a6377f..31784ec47 100644 --- a/Assets/Scripts/LevelEditor/Timeline.cs +++ b/Assets/Scripts/LevelEditor/Timeline.cs @@ -121,14 +121,16 @@ namespace RhythmHeavenMania.Editor } - lastBeatPos = Conductor.instance.songPositionInBeats; if (Input.GetMouseButton(1) && !Conductor.instance.isPlaying && CheckIfMouseInTimeline()) { RectTransformUtility.ScreenPointToLocalPointInRectangle(TimelineContent, Input.mousePosition, Editor.instance.EditorCamera, out lastMousePos); TimelineSlider.localPosition = new Vector3(Mathf.Clamp(Mathp.Round2Nearest(lastMousePos.x + 0.12f, 0.25f), 0, Mathf.Infinity), TimelineSlider.transform.localPosition.y); - Conductor.instance.SetBeat(TimelineSlider.transform.localPosition.x); + if (TimelineSlider.localPosition.x != lastBeatPos) + Conductor.instance.SetBeat(TimelineSlider.transform.localPosition.x); + + lastBeatPos = TimelineSlider.localPosition.x; } float moveSpeed = 750; @@ -276,6 +278,10 @@ namespace RhythmHeavenMania.Editor g.transform.GetChild(2).GetComponent().text = eventName.Split('/')[1]; TimelineEventObj eventObj = g.GetComponent(); + + if (eventName.Split(1) == "switchGame") + eventObj.Icon.sprite = Editor.GameIcon(eventName.Split(2)); + else eventObj.Icon.sprite = Editor.GameIcon(eventName.Split(0)); EventCaller.GameAction gameAction = EventCaller.instance.GetGameAction(EventCaller.instance.GetMinigame(eventName.Split(0)), eventName.Split(1));