fix chart reading, scroll chart notes!

This commit is contained in:
muskit
2023-09-16 00:40:36 -07:00
parent 6a98acce67
commit c8bd5c16c8
9 changed files with 126 additions and 29 deletions
-4
View File
@@ -13,7 +13,6 @@ namespace WacK.Data.Chart
/// </summary>
public class Chart
{
public static bool doneLoading { get; private set; } = false;
// Key of dictionaries are in milliseconds
// List is for chords
public SortedList<float, List<NotePlay>> playNotes { get; private set; }
@@ -23,7 +22,6 @@ namespace WacK.Data.Chart
public Chart(string chartPath)
{
doneLoading = false;
var file = FileAccess.Open(chartPath, FileAccess.ModeFlags.Read);
if (file == null)
{
@@ -35,8 +33,6 @@ namespace WacK.Data.Chart
var mer = new Mer.Mer(str);
Load(mer);
doneLoading = true;
}
// place notes and events relative to the previous
+46 -2
View File
@@ -1,6 +1,8 @@
using System.Reflection.PortableExecutable;
using Godot;
using WacK.Data.Chart;
using WacK.Data.Mer;
using WacK.Things.TunnelObjects;
namespace WacK.Scenes
{
@@ -24,13 +26,55 @@ namespace WacK.Scenes
// initialized by another scene, BEFORE loading this one!
public static PlayParameters playParams;
// TunnelObjects we can instantiate
public static PackedScene notePlay = GD.Load<PackedScene>("res://Things/TunnelObjects/Notes/NoteTouch.tscn");
[Export]
public Control noteDisplay;
private Chart chart;
public override void _Ready()
{
// parse mer and create chart for current play
chart = new(playParams.chartPath);
}
private void OnDestroy()
RealizeChart();
}
/// <summary>
/// Instantiates necessary notes onto the noteDisplay for the player to see.
/// </summary>
private void RealizeChart()
{
foreach (var msNote in chart.playNotes)
{
GD.Print(msNote.Key);
foreach (var note in msNote.Value)
{
THNotePlay nNote;
switch (note)
{
default: // tap note
nNote = notePlay.Instantiate<THNotePlay>();
break;
}
nNote.Init(note);
var nPos = nNote.Position;
nPos.Y = msNote.Key * -1000;
nNote.Position = nPos;
noteDisplay.AddChild(nNote);
}
}
}
public override void _Process(double delta)
{
var nPos = noteDisplay.Position;
nPos.Y += (float)delta * 1000;
noteDisplay.Position = nPos;
}
private void OnDestroy()
{
playParams = null;
}
@@ -0,0 +1,16 @@
using Godot;
using WacK.Data.Chart;
namespace WacK.Things.TunnelObjects
{
public partial class THNoteHold : THNotePlay
{
public new NoteHold noteData;
public void Init(NoteHold noteData)
{
base.Init(noteData);
this.noteData = noteData;
}
}
}
@@ -0,0 +1,28 @@
using Godot;
using WacK.Data.Chart;
namespace WacK.Things.TunnelObjects
{
public partial class THNotePlay : Control
{
public NotePlay noteData;
public void Init(NotePlay noteData)
{
this.noteData = noteData;
SetSizePos((int)noteData.position, (int)noteData.size);
}
public void SetSizePos(int pos, int size)
{
// TODO: pos + size >= 60
var nPos = Position;
nPos.X = pos * (1920f/60) - 12;
Position = nPos;
var nSize = Size;
nSize.X = size * (1920f/60) + 24;
Size = nSize;
}
}
}