2023-09-16 00:40:36 -07:00
|
|
|
using System.Reflection.PortableExecutable;
|
2023-07-30 00:22:03 -07:00
|
|
|
using Godot;
|
2023-09-15 12:00:12 -07:00
|
|
|
using WacK.Data.Chart;
|
|
|
|
|
using WacK.Data.Mer;
|
2023-09-16 00:40:36 -07:00
|
|
|
using WacK.Things.TunnelObjects;
|
2023-07-30 00:22:03 -07:00
|
|
|
|
|
|
|
|
namespace WacK.Scenes
|
|
|
|
|
{
|
|
|
|
|
public class PlayParameters
|
|
|
|
|
{
|
|
|
|
|
/* TODO: store song ID from internal database
|
|
|
|
|
public string songID;
|
|
|
|
|
public Difficulty diff;
|
|
|
|
|
*/
|
|
|
|
|
public string chartPath;
|
|
|
|
|
public string soundPath;
|
|
|
|
|
|
|
|
|
|
public PlayParameters(string chPath, string snPath)
|
|
|
|
|
{
|
|
|
|
|
chartPath = chPath;
|
|
|
|
|
soundPath = snPath;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public partial class Play : Node
|
|
|
|
|
{
|
|
|
|
|
// initialized by another scene, BEFORE loading this one!
|
|
|
|
|
public static PlayParameters playParams;
|
|
|
|
|
|
2023-09-16 00:40:36 -07:00
|
|
|
// TunnelObjects we can instantiate
|
2023-09-16 18:54:35 -07:00
|
|
|
public static PackedScene noteTouch = GD.Load<PackedScene>("res://Things/TunnelObjects/Notes/NoteTouch.tscn");
|
|
|
|
|
public static PackedScene noteHold = GD.Load<PackedScene>("res://Things/TunnelObjects/Notes/NoteHold.tscn");
|
2023-09-16 00:40:36 -07:00
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
|
public Control noteDisplay;
|
2023-09-16 18:54:35 -07:00
|
|
|
[Export]
|
|
|
|
|
public Control scrollDisplay;
|
2023-09-16 00:40:36 -07:00
|
|
|
|
2023-09-17 00:12:09 -07:00
|
|
|
[Export]
|
|
|
|
|
public Viewport mainViewport;
|
|
|
|
|
[Export]
|
|
|
|
|
public Viewport leftViewport;
|
|
|
|
|
[Export]
|
|
|
|
|
public Viewport rightViewport;
|
|
|
|
|
|
2023-09-15 12:00:12 -07:00
|
|
|
private Chart chart;
|
2023-07-30 00:22:03 -07:00
|
|
|
|
2023-09-16 18:54:35 -07:00
|
|
|
// scroll speed
|
|
|
|
|
private const float PIXELS_PER_SECOND = 2000;
|
|
|
|
|
|
2023-09-15 12:00:12 -07:00
|
|
|
public override void _Ready()
|
2023-09-17 00:12:09 -07:00
|
|
|
{
|
|
|
|
|
// so we can see objects outside of the 0-60min. region
|
|
|
|
|
leftViewport.World2D = mainViewport.World2D;
|
|
|
|
|
rightViewport.World2D = mainViewport.World2D;
|
|
|
|
|
|
2023-09-16 00:40:36 -07:00
|
|
|
// parse mer and create chart for current play
|
2023-09-15 12:00:12 -07:00
|
|
|
chart = new(playParams.chartPath);
|
2023-09-16 00:40:36 -07:00
|
|
|
RealizeChart();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-09-16 18:54:35 -07:00
|
|
|
/// Instantiates necessary notes onto noteDisplay for the player to see.
|
2023-09-16 00:40:36 -07:00
|
|
|
/// </summary>
|
|
|
|
|
private void RealizeChart()
|
|
|
|
|
{
|
|
|
|
|
foreach (var msNote in chart.playNotes)
|
|
|
|
|
{
|
|
|
|
|
foreach (var note in msNote.Value)
|
|
|
|
|
{
|
|
|
|
|
THNotePlay nNote;
|
2023-09-16 18:54:35 -07:00
|
|
|
switch (note.type)
|
2023-09-16 00:40:36 -07:00
|
|
|
{
|
2023-09-16 18:54:35 -07:00
|
|
|
case NotePlayType.HoldStart:
|
|
|
|
|
nNote = noteHold.Instantiate<THNoteHold>();
|
|
|
|
|
break;
|
|
|
|
|
case NotePlayType.Touch:
|
|
|
|
|
nNote = noteTouch.Instantiate<THNotePlay>();
|
2023-09-16 00:40:36 -07:00
|
|
|
break;
|
2023-09-16 18:54:35 -07:00
|
|
|
default:
|
|
|
|
|
continue;
|
2023-09-16 00:40:36 -07:00
|
|
|
}
|
|
|
|
|
nNote.Init(note);
|
|
|
|
|
var nPos = nNote.Position;
|
2023-09-16 18:54:35 -07:00
|
|
|
nPos.Y = msNote.Key * -PIXELS_PER_SECOND;
|
2023-09-16 00:40:36 -07:00
|
|
|
nNote.Position = nPos;
|
|
|
|
|
noteDisplay.AddChild(nNote);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void _Process(double delta)
|
|
|
|
|
{
|
|
|
|
|
var nPos = noteDisplay.Position;
|
2023-09-16 18:54:35 -07:00
|
|
|
nPos.Y += (float)delta * PIXELS_PER_SECOND;
|
2023-09-16 00:40:36 -07:00
|
|
|
noteDisplay.Position = nPos;
|
2023-09-17 00:12:09 -07:00
|
|
|
scrollDisplay.Position = nPos;
|
2023-09-16 00:40:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDestroy()
|
2023-07-30 00:22:03 -07:00
|
|
|
{
|
|
|
|
|
playParams = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|