Work on upcoming notes, reworked active notes a bit

This commit is contained in:
Thastertyn 2024-06-15 21:03:21 +02:00
parent e56da61974
commit e1dbbafe99
5 changed files with 139 additions and 16 deletions

View File

@ -8,6 +8,7 @@ using System.Linq;
using UITypes; using UITypes;
using BangerTypes; using BangerTypes;
using Unity.VisualScripting;
public class Game : MonoBehaviour public class Game : MonoBehaviour
{ {
@ -23,7 +24,9 @@ public class Game : MonoBehaviour
Song song = null; Song song = null;
Note[] activeNotes; List<Note> allNotes = new();
List<Note> activeNotes = new();
void Awake() void Awake()
{ {
@ -47,14 +50,12 @@ public class Game : MonoBehaviour
{ {
float timestamp = manager.source.time; float timestamp = manager.source.time;
activeNotes = song.Notes.Where(note => note.t >= timestamp && timestamp + 1f <= note.t).ToArray(); List<Note> newNotes = allNotes.Where(note => note.t >= timestamp && timestamp + 1f <= note.t).ToList();
newNotes.ForEach(note => activeNotes.Remove(note));
if(activeNotes.Length > 0) menu.GameElem.CheckNoteSelf(timestamp);
{ menu.GameElem.UpdateMargin(timestamp);
Debug.Log("Found some notes"); menu.GameElem.UpdateNotes(newNotes);
}
menu.GameElem.UpdateNotes(activeNotes);
} }
IEnumerator GameLoop() IEnumerator GameLoop()
@ -69,6 +70,8 @@ public class Game : MonoBehaviour
public void LoadSong(SongEntry song) public void LoadSong(SongEntry song)
{ {
this.song = song.Song; this.song = song.Song;
allNotes = this.song.Notes.ToList();
totalDuration = song.Song.Duration; totalDuration = song.Song.Duration;
manager.source.clip = song.Song.Clip; manager.source.clip = song.Song.Clip;

View File

@ -46,6 +46,9 @@ namespace UITypes
Game game; Game game;
List<NoteElement> activeNoteElements = new();
public void InitGame(Game game) public void InitGame(Game game)
{ {
this.game = game; this.game = game;
@ -62,7 +65,7 @@ namespace UITypes
leftBackgroundImage = this.Q("GameBackgroundImageLeft"); leftBackgroundImage = this.Q("GameBackgroundImageLeft");
rightBackgroundImage = this.Q("GameBackgroundImageRight"); rightBackgroundImage = this.Q("GameBackgroundImageRight");
leftUpcomingColumn = this.Q("LeftArrowUpcomingColumn"); leftUpcomingColumn = this.Q("LeftArrowUpcomingColumn");
rightUpcomingColumn = this.Q("RightArrowUpcomingColumn"); rightUpcomingColumn = this.Q("RightArrowUpcomingColumn");
upUpcomingColumn = this.Q("UpArrowUpcomingColumn"); upUpcomingColumn = this.Q("UpArrowUpcomingColumn");
@ -75,12 +78,12 @@ namespace UITypes
rightVisualizer.InitVisualizer("RightBar"); rightVisualizer.InitVisualizer("RightBar");
buttonDictionary = new() buttonDictionary = new()
{ {
{ KeyCode.LeftArrow, Left }, { KeyCode.LeftArrow, Left },
{ KeyCode.RightArrow, Right }, { KeyCode.RightArrow, Right },
{ KeyCode.UpArrow, Up }, { KeyCode.UpArrow, Up },
{ KeyCode.DownArrow, Down }, { KeyCode.DownArrow, Down },
}; };
} }
public void SetColumnColor(Color32 color) public void SetColumnColor(Color32 color)
@ -103,7 +106,7 @@ namespace UITypes
songTime.text = time; songTime.text = time;
} }
public void UpdateNotes(Note[] notes) public void UpdateNotes(List<Note> notes)
{ {
leftActive = notes.Where(note => note.a == "left").Count() > 0; leftActive = notes.Where(note => note.a == "left").Count() > 0;
rightActive = notes.Where(note => note.a == "right").Count() > 0; rightActive = notes.Where(note => note.a == "right").Count() > 0;
@ -114,6 +117,48 @@ namespace UITypes
rightUpcomingColumn.EnableInClassList("ColumnActive", rightActive); rightUpcomingColumn.EnableInClassList("ColumnActive", rightActive);
downUpcomingColumn.EnableInClassList("ColumnActive", downActive); downUpcomingColumn.EnableInClassList("ColumnActive", downActive);
upUpcomingColumn.EnableInClassList("ColumnActive", upActive); 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) void OnKeyDown(KeyDownEvent ev)

View File

@ -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<NoteElement> { }
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;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0faf98c2edf4306b9a433b5d75c9ffa0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -37,6 +37,33 @@
border-width: 0px; 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 { .Bar {
width: 100%; width: 100%;
height: 0.7%; height: 0.7%;