From 75c98a87fbdc164af84006015d00226a0c56df22 Mon Sep 17 00:00:00 2001 From: Braedon Date: Thu, 13 Jan 2022 19:35:41 -0500 Subject: [PATCH] Time hopping improvements although still a bit buggy --- Assets/Scenes/Editor.unity | 4 +- Assets/Scripts/GameManager.cs | 67 +++++++++++++------ Assets/Scripts/Games/Spaceball/Spaceball.cs | 55 ++++++++------- Assets/Scripts/LevelEditor/BoxSelection.cs | 1 - .../Scripts/LevelEditor/GridGameSelector.cs | 2 +- Assets/Scripts/LevelEditor/Selector.cs | 34 ---------- Assets/Scripts/LevelEditor/Timeline.cs | 62 ++++++----------- .../Scripts/LevelEditor/TimelineEventObj.cs | 17 +++-- 8 files changed, 111 insertions(+), 131 deletions(-) diff --git a/Assets/Scenes/Editor.unity b/Assets/Scenes/Editor.unity index 974e656d..1f7770c3 100644 --- a/Assets/Scenes/Editor.unity +++ b/Assets/Scenes/Editor.unity @@ -4074,7 +4074,7 @@ Canvas: m_RenderMode: 0 m_Camera: {fileID: 2047408675} m_PlaneDistance: 100 - m_PixelPerfect: 0 + m_PixelPerfect: 1 m_ReceivesEvents: 1 m_OverrideSorting: 0 m_OverridePixelPerfect: 0 @@ -4767,7 +4767,7 @@ RectTransform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1791483799} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 90} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0.013888889, y: 0.013888889, z: 0.013888889} m_Children: - {fileID: 1110073995} diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 20f9fcf4..3104f15f 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -92,19 +92,6 @@ namespace RhythmHeavenMania if (!Conductor.instance.isPlaying) return; - /*if (Input.GetKeyDown(KeyCode.A)) - { - Conductor.instance.SetBeat(Conductor.instance.songPositionInBeats + 3); - - GetGame(currentGame).holder.GetComponent().OnTimeChange(); - } - else if (Input.GetKeyDown(KeyCode.S)) - { - Conductor.instance.SetBeat(Conductor.instance.songPositionInBeats - 3); - - GetGame(currentGame).holder.GetComponent().OnTimeChange(); - }*/ - List entities = Beatmap.entities.Select(c => c.beat).ToList(); if (currentEvent < Beatmap.entities.Count && currentEvent >= 0) @@ -118,17 +105,25 @@ namespace RhythmHeavenMania // GameManager entities should ALWAYS execute before gameplay entities for (int i = 0; i < gameManagerEntities.Count; i++) { - eventCaller.CallEvent(gameManagerEntities[i].datamodel); + var gameManagerEntity = gameManagerEntities[i]; + if ((gameManagerEntity.beat + eventCaller.GetGameAction(eventCaller.GetMinigame(gameManagerEntity.datamodel.Split(0)), gameManagerEntity.datamodel.Split(1)).defaultLength) > Conductor.instance.songPositionInBeats) + { + eventCaller.CallEvent(gameManagerEntities[i].datamodel); + } } for (int i = 0; i < entitesAtSameBeat.Count; 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]))) + var entity = entitesAtSameBeat[i]; + if ((entity.beat + eventCaller.GetGameAction(eventCaller.GetMinigame(entity.datamodel.Split(0)), entity.datamodel.Split(1)).defaultLength) > Conductor.instance.songPositionInBeats) { - PreloadGame(entitesAtSameBeat[i].datamodel.Split('/')[0]); + // 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]))) + { + PreloadGame(entitesAtSameBeat[i].datamodel.Split('/')[0]); + } + eventCaller.CallEvent(entitesAtSameBeat[i].datamodel); } - eventCaller.CallEvent(entitesAtSameBeat[i].datamodel); } currentEvent += entitesAtSameBeat.Count + gameManagerEntities.Count; @@ -136,6 +131,35 @@ namespace RhythmHeavenMania } } + #region Play Events + + public void Play(float beat) + { + StartCoroutine(PlayCo(beat)); + } + + private IEnumerator PlayCo(float beat) + { + yield return null; + Conductor.instance.Play(beat); + SetCurrentEventToClosest(beat); + } + + public void Pause() + { + Conductor.instance.Pause(); + } + + public void Stop(float beat) + { + Conductor.instance.Stop(beat); + SetCurrentEventToClosest(beat); + } + + #endregion + + #region List Functions + public void SortEventsList() { Beatmap.entities.Sort((x, y) => x.beat.CompareTo(y.beat)); @@ -165,14 +189,13 @@ namespace RhythmHeavenMania newGame = Beatmap.entities[entities.IndexOf(Mathp.GetClosestInList(Beatmap.entities.FindAll(c => c.datamodel != "gameManager" && c.beat < Conductor.instance.songPositionInBeats).ToList().Select(c => c.beat).ToList(), beat))].datamodel.Split('/')[0]; } - if (newGame != currentGame) - { - SwitchGame(newGame); - } + SetGame(newGame); } } } + #endregion + public void SwitchGame(string game) { if (currentGameSwitchIE != null) StopCoroutine(currentGameSwitchIE); diff --git a/Assets/Scripts/Games/Spaceball/Spaceball.cs b/Assets/Scripts/Games/Spaceball/Spaceball.cs index ca628dc2..034b8fbc 100644 --- a/Assets/Scripts/Games/Spaceball/Spaceball.cs +++ b/Assets/Scripts/Games/Spaceball/Spaceball.cs @@ -56,44 +56,51 @@ namespace RhythmHeavenMania.Games.Spaceball private void Update() { - var allPlayerActions = EventCaller.GetAllPlayerEntities("spaceball"); - int currentPlayerEvent = GameManager.instance.currentPlayerEvent - EventCaller.GetAllPlayerEntitiesExceptBeforeBeat("spaceball", Conductor.instance.songPositionInBeats).Count; - - if (currentPlayerEvent < allPlayerActions.Count) + try { - if (Conductor.instance.songPositionInBeats > allPlayerActions[currentPlayerEvent].beat - 1) + var allPlayerActions = EventCaller.GetAllPlayerEntities("spaceball"); + int currentPlayerEvent = GameManager.instance.currentPlayerEvent - EventCaller.GetAllPlayerEntitiesExceptBeforeBeat("spaceball", Conductor.instance.songPositionInBeats).Count; + + if (currentPlayerEvent < allPlayerActions.Count) { - Dispenser.GetComponent().Play("DispenserPrepare", 0, 0); + if (Conductor.instance.songPositionInBeats > allPlayerActions[currentPlayerEvent].beat - 1) + { + Dispenser.GetComponent().Play("DispenserPrepare", 0, 0); + } } - } - if (currentZoomIndex < allCameraEvents.Count && currentZoomIndex >= 0) - { - if (Conductor.instance.songPositionInBeats >= allCameraEvents[currentZoomIndex].beat) + if (currentZoomIndex < allCameraEvents.Count && currentZoomIndex >= 0) { - UpdateCameraZoom(); - currentZoomIndex++; + if (Conductor.instance.songPositionInBeats >= allCameraEvents[currentZoomIndex].beat) + { + UpdateCameraZoom(); + currentZoomIndex++; + } } - } - float normalizedBeat = Conductor.instance.GetLoopPositionFromBeat(currentZoomCamBeat, currentZoomCamLength); + float normalizedBeat = Conductor.instance.GetLoopPositionFromBeat(currentZoomCamBeat, currentZoomCamLength); - if (normalizedBeat > Minigame.EndTime()) - { - lastCamDistance = GameManager.instance.GameCamera.transform.localPosition.z; - } - else - { - if (currentZoomCamLength <= 0) + if (normalizedBeat > Minigame.EndTime()) { - GameManager.instance.GameCamera.transform.localPosition = new Vector3(0, 0, currentZoomCamDistance); + lastCamDistance = GameManager.instance.GameCamera.transform.localPosition.z; } else { - float newPosZ = Mathf.Lerp(lastCamDistance, currentZoomCamDistance, normalizedBeat); - GameManager.instance.GameCamera.transform.localPosition = new Vector3(0, 0, newPosZ); + if (currentZoomCamLength <= 0) + { + GameManager.instance.GameCamera.transform.localPosition = new Vector3(0, 0, currentZoomCamDistance); + } + else + { + float newPosZ = Mathf.Lerp(lastCamDistance, currentZoomCamDistance, normalizedBeat); + GameManager.instance.GameCamera.transform.localPosition = new Vector3(0, 0, newPosZ); + } } } + catch (System.Exception ex) + { + // this technically isn't game breaking so oh well + } } private void UpdateCameraZoom() diff --git a/Assets/Scripts/LevelEditor/BoxSelection.cs b/Assets/Scripts/LevelEditor/BoxSelection.cs index 594a91e5..393fdad4 100644 --- a/Assets/Scripts/LevelEditor/BoxSelection.cs +++ b/Assets/Scripts/LevelEditor/BoxSelection.cs @@ -116,7 +116,6 @@ namespace RhythmHeavenMania.Editor TimelineEventObj e = GameManager.instance.Beatmap.entities[i].eventObj; if (selectionBox.Contains(Camera.main.WorldToScreenPoint(e.transform.position))) { - print(RectTransformToScreenSpace(e.GetComponent())); Selections.instance.DragSelect(e); selected++; } diff --git a/Assets/Scripts/LevelEditor/GridGameSelector.cs b/Assets/Scripts/LevelEditor/GridGameSelector.cs index 0706f0ce..7872f565 100644 --- a/Assets/Scripts/LevelEditor/GridGameSelector.cs +++ b/Assets/Scripts/LevelEditor/GridGameSelector.cs @@ -46,7 +46,7 @@ namespace RhythmHeavenMania.Editor if (Timeline.instance.CheckIfMouseInTimeline() && dragTimes < 1) { dragTimes++; - Timeline.instance.AddEventObject(mg.name + "/" + mg.actions[currentEventIndex].actionName, true); + Timeline.instance.AddEventObject(mg.name + "/" + mg.actions[currentEventIndex].actionName, true, new Vector3(0, 0)); } } diff --git a/Assets/Scripts/LevelEditor/Selector.cs b/Assets/Scripts/LevelEditor/Selector.cs index 35b0801c..a6c112c8 100644 --- a/Assets/Scripts/LevelEditor/Selector.cs +++ b/Assets/Scripts/LevelEditor/Selector.cs @@ -14,39 +14,5 @@ namespace RhythmHeavenMania.Editor { instance = this; } - - private void LateUpdate() - { - /*if (Input.GetMouseButtonUp(0)) - { - if (!Timeline.instance.IsDraggingEvent()) - { - if (clicked == false) - { - if (!Input.GetKey(KeyCode.LeftShift)) - { - print('a'); - Selections.instance.DeselectAll(); - } - } - } - } - - clicked = false;*/ - } - - public void Click(TimelineEventObj eventObj) - { - /*if (Input.GetKey(KeyCode.LeftShift)) - { - Selections.instance.ShiftClickSelect(eventObj); - } - else - { - Selections.instance.ClickSelect(eventObj); - } - - clicked = true;*/ - } } } \ No newline at end of file diff --git a/Assets/Scripts/LevelEditor/Timeline.cs b/Assets/Scripts/LevelEditor/Timeline.cs index 6cb7fdbc..64b694f7 100644 --- a/Assets/Scripts/LevelEditor/Timeline.cs +++ b/Assets/Scripts/LevelEditor/Timeline.cs @@ -38,29 +38,6 @@ namespace RhythmHeavenMania.Editor for (int i = 0; i < GameManager.instance.Beatmap.entities.Count; i++) { - /*var entity = GameManager.instance.Beatmap.entities[i]; - var e = GameManager.instance.Beatmap.entities[i]; - - EventCaller.GameAction gameAction = EventCaller.instance.GetGameAction(EventCaller.instance.GetMinigame(e.datamodel.Split(0)), e.datamodel.Split(1)); - - GameObject g = Instantiate(TimelineEventObjRef.gameObject, TimelineEventObjRef.parent); - g.transform.localPosition = new Vector3(e.beat, Mathp.Round2Nearest(Random.Range(0, -205.36f), 51.34f)); - g.transform.GetChild(1).GetComponent().text = e.datamodel.Split('/')[1]; - - TimelineEventObj eventObj = g.GetComponent(); - eventObj.Icon.sprite = Editor.GameIcon(e.datamodel.Split(0)); - - if (gameAction != null) - { - g.GetComponent().sizeDelta = new Vector2(gameAction.defaultLength, g.GetComponent().sizeDelta.y); - float length = gameAction.defaultLength; - eventObj.length = length; - } - - g.SetActive(true); - entity.eventObj = g.GetComponent(); - entity.track = (int)(g.transform.localPosition.y / 51.34f * -1);*/ - var entity = GameManager.instance.Beatmap.entities[i]; var e = GameManager.instance.Beatmap.entities[i]; @@ -158,13 +135,13 @@ namespace RhythmHeavenMania.Editor TimelineSongPosLine.gameObject.SetActive(true); } - Conductor.instance.Play(time); + GameManager.instance.Play(time); } public void Pause() { // isPaused = true; - Conductor.instance.Pause(); + GameManager.instance.Pause(); } public void Stop(float time) @@ -175,7 +152,7 @@ namespace RhythmHeavenMania.Editor if (TimelineSongPosLine != null) Destroy(TimelineSongPosLine.gameObject); - Conductor.instance.Stop(time); + GameManager.instance.Stop(time); } #endregion @@ -217,16 +194,11 @@ namespace RhythmHeavenMania.Editor g.SetActive(true); - var entity = GameManager.instance.Beatmap.entities[entityId]; - var e = GameManager.instance.Beatmap.entities[entityId]; - - entity.eventObj = g.GetComponent(); - entity.track = (int)(g.transform.localPosition.y / 51.34f * -1); - if (dragNDrop) { - g.transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition); - eventObj.OnDown(); + var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); + g.transform.position = new Vector3(mousePos.x, mousePos.y, 0); + Beatmap.Entity en = new Beatmap.Entity(); en.datamodel = eventName; @@ -234,20 +206,30 @@ namespace RhythmHeavenMania.Editor GameManager.instance.Beatmap.entities.Add(en); GameManager.instance.SortEventsList(); + + Selections.instance.ClickSelect(eventObj); + eventObj.isDragging = true; + } + else + { + var entity = GameManager.instance.Beatmap.entities[entityId]; + var e = GameManager.instance.Beatmap.entities[entityId]; + + entity.eventObj = g.GetComponent(); + entity.track = (int)(g.transform.localPosition.y / 51.34f * -1); } Editor.EventObjs.Add(eventObj); eventObjs.Add(eventObj); } - public void DestroyEventObject(TimelineEventObj eventObj) + public void DestroyEventObject(Beatmap.Entity entity) { - var e = GameManager.instance.Beatmap.entities.Find(c => c.eventObj == eventObj); - GameManager.instance.Beatmap.entities.Remove(e); - GameManager.instance.SortEventsList(); - Destroy(eventObj.gameObject); + Editor.EventObjs.Remove(entity.eventObj); + GameManager.instance.Beatmap.entities.Remove(entity); - Editor.EventObjs.Remove(eventObj); + Destroy(entity.eventObj.gameObject); + GameManager.instance.SortEventsList(); } public bool IsMouseAboveEvents() diff --git a/Assets/Scripts/LevelEditor/TimelineEventObj.cs b/Assets/Scripts/LevelEditor/TimelineEventObj.cs index 495bb06e..c8cea130 100644 --- a/Assets/Scripts/LevelEditor/TimelineEventObj.cs +++ b/Assets/Scripts/LevelEditor/TimelineEventObj.cs @@ -22,7 +22,7 @@ namespace RhythmHeavenMania.Editor [SerializeField] public Image Icon; [Header("Properties")] - private int enemyIndex; + private Beatmap.Entity entity; public float length; private bool eligibleToMove = false; private bool lastVisible; @@ -36,6 +36,8 @@ namespace RhythmHeavenMania.Editor private void Update() { + entity = GameManager.instance.Beatmap.entities.Find(a => a.eventObj == this); + mouseHovering = RectTransformUtility.RectangleContainsScreenPoint(GetComponent(), Input.mousePosition, Camera.main); #region Optimizations @@ -57,6 +59,12 @@ namespace RhythmHeavenMania.Editor if (selected) { SetColor(1); + + if (Input.GetKeyDown(KeyCode.Delete)) + { + Selections.instance.Deselect(this); + Timeline.instance.DestroyEventObject(entity); + } } else { @@ -69,7 +77,6 @@ namespace RhythmHeavenMania.Editor return; } - enemyIndex = GameManager.instance.Beatmap.entities.FindIndex(a => a.eventObj == this); if (Input.GetMouseButtonDown(0) && Timeline.instance.IsMouseAboveEvents()) { @@ -112,9 +119,6 @@ namespace RhythmHeavenMania.Editor lastPos = this.transform.localPosition; } - if (Input.GetKeyDown(KeyCode.Delete)) - Timeline.instance.DestroyEventObject(this); - } private void OnMove() @@ -131,7 +135,6 @@ namespace RhythmHeavenMania.Editor private void OnComplete() { - var entity = GameManager.instance.Beatmap.entities[enemyIndex]; entity.beat = this.transform.localPosition.x; GameManager.instance.SortEventsList(); entity.track = (int)(this.transform.localPosition.y / 51.34f) * -1; @@ -216,7 +219,7 @@ namespace RhythmHeavenMania.Editor private void OnDestroy() { // better safety net than canada's healthcare system - GameManager.instance.Beatmap.entities.Remove(GameManager.instance.Beatmap.entities.Find(c => c.eventObj = this)); + // GameManager.instance.Beatmap.entities.Remove(GameManager.instance.Beatmap.entities.Find(c => c.eventObj = this)); } #endregion