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 BangerTypes;
using Unity.VisualScripting;
public class Game : MonoBehaviour
{
@ -23,7 +24,9 @@ public class Game : MonoBehaviour
Song song = null;
Note[] activeNotes;
List<Note> allNotes = new();
List<Note> 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<Note> 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;

View File

@ -46,6 +46,9 @@ namespace UITypes
Game game;
List<NoteElement> activeNoteElements = new();
public void InitGame(Game game)
{
this.game = game;
@ -103,7 +106,7 @@ namespace UITypes
songTime.text = time;
}
public void UpdateNotes(Note[] notes)
public void UpdateNotes(List<Note> 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)

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;
}
.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%;