Notes now move

This commit is contained in:
Thastertyn 2024-06-16 22:07:02 +02:00
parent e1dbbafe99
commit 27082a717c
4 changed files with 19 additions and 12 deletions

View File

@ -51,11 +51,16 @@ public class Game : MonoBehaviour
float timestamp = manager.source.time; float timestamp = manager.source.time;
List<Note> newNotes = allNotes.Where(note => note.t >= timestamp && timestamp + 1f <= note.t).ToList(); List<Note> newNotes = allNotes.Where(note => note.t >= timestamp && timestamp + 1f <= note.t).ToList();
newNotes.ForEach(note => activeNotes.Remove(note));
menu.GameElem.CheckNoteSelf(timestamp); foreach (Note note in newNotes)
menu.GameElem.UpdateMargin(timestamp); {
Debug.Log("Removing note");
Debug.Log(allNotes.Remove(note));
}
menu.GameElem.UpdateNotes(newNotes); menu.GameElem.UpdateNotes(newNotes);
menu.GameElem.CheckNoteLifetime(timestamp);
menu.GameElem.UpdateMargin(timestamp);
} }
IEnumerator GameLoop() IEnumerator GameLoop()
@ -83,7 +88,7 @@ public class Game : MonoBehaviour
{ {
int totalSeconds = (int)manager.source.time; int totalSeconds = (int)manager.source.time;
int h = totalSeconds / 3600; int h = totalSeconds / 3600;
int m = (totalSeconds % 3600) / 60; int m = totalSeconds % 3600 / 60;
int s = totalSeconds % 60; int s = totalSeconds % 60;
string result = $"{h:D2}:{m:D2}:{s:D2} / {totalDuration}"; string result = $"{h:D2}:{m:D2}:{s:D2} / {totalDuration}";

View File

@ -46,7 +46,6 @@ namespace UITypes
Game game; Game game;
List<NoteElement> activeNoteElements = new(); List<NoteElement> activeNoteElements = new();
public void InitGame(Game game) public void InitGame(Game game)
@ -121,7 +120,8 @@ namespace UITypes
foreach (var note in notes) foreach (var note in notes)
{ {
NoteElement el = new(); NoteElement el = new();
el.Init(note); el.Init(note, leftUpcomingColumn.resolvedStyle.height);
activeNoteElements.Add(el);
if (note.a == "left") if (note.a == "left")
{ {
@ -150,9 +150,9 @@ namespace UITypes
} }
} }
public void CheckNoteSelf(float timestamp) public void CheckNoteLifetime(float timestamp)
{ {
foreach (var note in activeNoteElements) foreach (var note in activeNoteElements.ToList())
{ {
if (note.CheckSelf(timestamp)) if (note.CheckSelf(timestamp))
{ {

View File

@ -14,9 +14,11 @@ namespace UITypes
public new class UxmlFactory : UxmlFactory<NoteElement> { } public new class UxmlFactory : UxmlFactory<NoteElement> { }
public Note note; public Note note;
public float ColumnHeight;
public void Init(Note note) public void Init(Note note, float columnHeight)
{ {
this.ColumnHeight = columnHeight;
AddToClassList("NoteElement"); AddToClassList("NoteElement");
AddToClassList(note.a[..1].ToUpper() + note.a[1..] + "Note"); AddToClassList(note.a[..1].ToUpper() + note.a[1..] + "Note");
@ -26,7 +28,7 @@ namespace UITypes
public void UpdateMargin(float timestamp) public void UpdateMargin(float timestamp)
{ {
style.marginTop = new((note.t - timestamp) / 1000f); style.marginTop = new(ColumnHeight - (note.t - timestamp) * 1000 - resolvedStyle.height);
} }
public bool CheckSelf(float timestamp) public bool CheckSelf(float timestamp)

View File

@ -38,8 +38,8 @@
} }
.NoteElement { .NoteElement {
width: 20%; width: 100%;
height: 20%; height: 30%;
margin: auto; margin: auto;
font-size: 32px; font-size: 32px;
border-radius: 45px; border-radius: 45px;