diff --git a/Scripts/Game/Game.cs b/Scripts/Game/Game.cs index fa722b5..9a65d57 100644 --- a/Scripts/Game/Game.cs +++ b/Scripts/Game/Game.cs @@ -8,6 +8,7 @@ using System.Linq; using UITypes; using BangerTypes; +using Unity.VisualScripting; public class Game : MonoBehaviour { @@ -23,7 +24,9 @@ public class Game : MonoBehaviour Song song = null; - Note[] activeNotes; + List allNotes = new(); + + List activeNotes = new(); void Awake() { @@ -47,14 +50,12 @@ public class Game : MonoBehaviour { float timestamp = manager.source.time; - activeNotes = song.Notes.Where(note => note.t >= timestamp && timestamp + 1f <= note.t).ToArray(); + List newNotes = allNotes.Where(note => note.t >= timestamp && timestamp + 1f <= note.t).ToList(); + newNotes.ForEach(note => activeNotes.Remove(note)); - if(activeNotes.Length > 0) - { - Debug.Log("Found some notes"); - } - - menu.GameElem.UpdateNotes(activeNotes); + menu.GameElem.CheckNoteSelf(timestamp); + menu.GameElem.UpdateMargin(timestamp); + menu.GameElem.UpdateNotes(newNotes); } IEnumerator GameLoop() @@ -69,6 +70,8 @@ public class Game : MonoBehaviour public void LoadSong(SongEntry song) { this.song = song.Song; + allNotes = this.song.Notes.ToList(); + totalDuration = song.Song.Duration; manager.source.clip = song.Song.Clip; diff --git a/Scripts/UI Types/GameElement.cs b/Scripts/UI Types/GameElement.cs index 4f00bcb..5a7f348 100644 --- a/Scripts/UI Types/GameElement.cs +++ b/Scripts/UI Types/GameElement.cs @@ -46,6 +46,9 @@ namespace UITypes Game game; + + List activeNoteElements = new(); + public void InitGame(Game game) { this.game = game; @@ -62,7 +65,7 @@ namespace UITypes leftBackgroundImage = this.Q("GameBackgroundImageLeft"); rightBackgroundImage = this.Q("GameBackgroundImageRight"); - + leftUpcomingColumn = this.Q("LeftArrowUpcomingColumn"); rightUpcomingColumn = this.Q("RightArrowUpcomingColumn"); upUpcomingColumn = this.Q("UpArrowUpcomingColumn"); @@ -75,12 +78,12 @@ namespace UITypes rightVisualizer.InitVisualizer("RightBar"); buttonDictionary = new() - { - { KeyCode.LeftArrow, Left }, - { KeyCode.RightArrow, Right }, - { KeyCode.UpArrow, Up }, - { KeyCode.DownArrow, Down }, - }; + { + { KeyCode.LeftArrow, Left }, + { KeyCode.RightArrow, Right }, + { KeyCode.UpArrow, Up }, + { KeyCode.DownArrow, Down }, + }; } public void SetColumnColor(Color32 color) @@ -103,7 +106,7 @@ namespace UITypes songTime.text = time; } - public void UpdateNotes(Note[] notes) + public void UpdateNotes(List notes) { leftActive = notes.Where(note => note.a == "left").Count() > 0; rightActive = notes.Where(note => note.a == "right").Count() > 0; @@ -114,6 +117,48 @@ namespace UITypes rightUpcomingColumn.EnableInClassList("ColumnActive", rightActive); downUpcomingColumn.EnableInClassList("ColumnActive", downActive); upUpcomingColumn.EnableInClassList("ColumnActive", upActive); + + foreach (var note in notes) + { + NoteElement el = new(); + el.Init(note); + + if (note.a == "left") + { + leftUpcomingColumn.Add(el); + } + else if (note.a == "right") + { + rightUpcomingColumn.Add(el); + } + else if (note.a == "up") + { + upUpcomingColumn.Add(el); + } + else if (note.a == "down") + { + downUpcomingColumn.Add(el); + } + } + } + + public void UpdateMargin(float timestamp) + { + foreach (var note in activeNoteElements) + { + note.UpdateMargin(timestamp); + } + } + + public void CheckNoteSelf(float timestamp) + { + foreach (var note in activeNoteElements) + { + if (note.CheckSelf(timestamp)) + { + activeNoteElements.Remove(note); + } + } } void OnKeyDown(KeyDownEvent ev) diff --git a/Scripts/UI Types/NoteElement.cs b/Scripts/UI Types/NoteElement.cs new file mode 100644 index 0000000..1f6bf9a --- /dev/null +++ b/Scripts/UI Types/NoteElement.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using BangerTypes; +using UnityEngine; +using UnityEngine.UIElements; + +namespace UITypes +{ + + public class NoteElement : VisualElement + { + [UnityEngine.Scripting.Preserve] + public new class UxmlFactory : UxmlFactory { } + + public Note note; + + public void Init(Note note) + { + AddToClassList("NoteElement"); + + AddToClassList(note.a[..1].ToUpper() + note.a[1..] + "Note"); + + this.note = note; + } + + public void UpdateMargin(float timestamp) + { + style.marginTop = new((note.t - timestamp) / 1000f); + } + + public bool CheckSelf(float timestamp) + { + return note.t - timestamp < 0; + } + } +} \ No newline at end of file diff --git a/Scripts/UI Types/NoteElement.cs.meta b/Scripts/UI Types/NoteElement.cs.meta new file mode 100644 index 0000000..ee38a93 --- /dev/null +++ b/Scripts/UI Types/NoteElement.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0faf98c2edf4306b9a433b5d75c9ffa0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UI/Game.uss b/UI/Game.uss index dba5a6f..5af6ae9 100644 --- a/UI/Game.uss +++ b/UI/Game.uss @@ -37,6 +37,33 @@ border-width: 0px; } +.NoteElement { + width: 20%; + height: 20%; + margin: auto; + font-size: 32px; + border-radius: 45px; + border-width: 0px; + position: absolute; +} + + +.LeftNote { + background-color: red; +} + +.RightNote { + background-color: green; +} + +.UpNote { + background-color: blue; +} + +.DownNote { + background-color: yellow; +} + .Bar { width: 100%; height: 0.7%;