fix chart parsing

This commit is contained in:
muskit
2023-09-15 12:00:12 -07:00
parent 002ff7b1ff
commit 41d2576e58
4 changed files with 35 additions and 12 deletions
+24 -7
View File
@@ -21,15 +21,31 @@ namespace WacK.Data.Chart
public SortedList<float, NoteEvent<float>> tempoChgs { get; private set; }
public SortedList<float, NoteEvent<int>> events { get; private set; }
public Chart()
public Chart(string chartPath)
{
doneLoading = false;
var file = FileAccess.Open(chartPath, FileAccess.ModeFlags.Read);
if (file == null)
{
GD.PrintErr("Couldn't load chart in play!");
return;
}
var str = file.GetAsText();
file.Close();
var mer = new Mer.Mer(str);
Load(mer);
doneLoading = true;
}
// place notes and events relative to the previous
public void Load(Mer.Mer chart)
private void Load(Mer.Mer chart)
{
playNotes = new SortedList<float, List<NotePlay>>();
playNotes = new();
timeSigChgs = new();
tempoChgs = new();
events = new();
List<float> tempo = new List<float>();
List<int> tempoChangeMeasures = new List<int>();
@@ -56,8 +72,8 @@ namespace WacK.Data.Chart
Note prevNote = null;
Note curNote = null;
var prevHoldPoint = new System.Collections.Generic.Dictionary<int, NotePlay>(); // <note idx, previous point of hold>
var curHoldNote = new System.Collections.Generic.Dictionary<int, NoteHold>(); // <next hold idx, HoldStart>
var prevHoldPoint = new Dictionary<int, NotePlay>(); // <note idx, previous point of hold>
var curHoldNote = new Dictionary<int, NoteHold>(); // <next hold idx, HoldStart>
// Notes and Events //
foreach (var measure in chart.notes) // `measure` = measure: List
@@ -112,7 +128,8 @@ namespace WacK.Data.Chart
var de = int.Parse(words[1]);
if (beatsPerMeasure.Count == 1)
{
beatsPerMeasure.Add(int.Parse(chartNote.Item2.value));
// TODO: handle denominator (note that gets the beat)
beatsPerMeasure.Add(nu);
bpmChangeMeasures.Add(measure.Key);
}
else
@@ -327,7 +344,7 @@ namespace WacK.Data.Chart
// }
// }
doneLoading = true;
GD.Print("Finished forming Chart!");
}
}
}
+1
View File
@@ -15,6 +15,7 @@ namespace WacK.Data.Chart
: base(time, measureBeat, position, size,holdIndex, holdNext, type: NotePlayType.HoldStart, bonus: false)
{
// points = (SortedList<float, Note>)holdPoints.Skip(1);
points = new();
}
}
}
+3 -1
View File
@@ -8,6 +8,7 @@
using System;
using System.Collections.Generic;
using Godot;
namespace WacK.Data.Mer
{
@@ -133,7 +134,8 @@ namespace WacK.Data.Mer
notes[currentMeasure].Add((currentBeat, new MerNote(value: tokens[3], type: MerType.Tempo)));
break;
case "3": // beats per measure
notes[currentMeasure].Add((currentBeat, new MerNote(value: $"{tokens[3]} {tokens[4]}", type: MerType.TimeSignature)));
string de = tokens.Count >= 5 ? tokens[4] : "4"; // TODO: use previously-estbalished denominator?
notes[currentMeasure].Add((currentBeat, new MerNote(value: $"{tokens[3]} {de}", type: MerType.TimeSignature)));
break;
}
}
+6 -3
View File
@@ -1,4 +1,6 @@
using Godot;
using WacK.Data.Chart;
using WacK.Data.Mer;
namespace WacK.Scenes
{
@@ -22,11 +24,12 @@ namespace WacK.Scenes
// initialized by another scene, BEFORE loading this one!
public static PlayParameters playParams;
private void Start()
private Chart chart;
public override void _Ready()
{
chart = new(playParams.chartPath);
}
private void OnDestroy()
{
playParams = null;