Skip to content

Commit

Permalink
Use IStepWithBeat for Beat sorting instead of a union type
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamQiufeng committed May 8, 2024
1 parent 1478c33 commit 8bfa0ba
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 45 deletions.
7 changes: 7 additions & 0 deletions Quaver.API/Maps/Parsers/Stepmania/IStepWithBeat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Quaver.API.Maps.Parsers.Stepmania
{
public interface IStepWithBeat
{
float Beat { get; }
}
}
37 changes: 0 additions & 37 deletions Quaver.API/Maps/Parsers/Stepmania/StepBpmOrStop.cs

This file was deleted.

9 changes: 3 additions & 6 deletions Quaver.API/Maps/Parsers/Stepmania/StepFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,7 @@ private Qua ConvertChart(StepFileChart chart)
};

// Combine BPM changes and stops together and order by its beat time
var bpmAndStops = new Queue<StepBpmOrStop>(Bpms.Select(b => new StepBpmOrStop(b))
.Concat(
Stops.Select(s => new StepBpmOrStop(s)))
.OrderBy(s => s.Beat));
var bpmAndStops = new Queue<IStepWithBeat>(Bpms.Cast<IStepWithBeat>().Concat(Stops).OrderBy(s => s.Beat));

// The starting beat time of the current measure
var measureBeats = 0;
Expand Down Expand Up @@ -307,6 +304,7 @@ private Qua ConvertChart(StepFileChart chart)
{
var bpmOrStop = bpmAndStops.Dequeue();
if (bpmOrStop.IsBpm)
if (bpmOrStop is StepFileBPM bpm)
{
var bpm = bpmOrStop.Bpm;
// Fraction of row before the timing point is placed
Expand Down Expand Up @@ -334,9 +332,8 @@ private Qua ConvertChart(StepFileChart chart)
measureTime = lastBpmChangeMeasureTime;
currentTime = measureTime + rowIndex * millisecondsPerRow;
}
else
else if (bpmOrStop is StepFileStop stop)
{
var stop = bpmOrStop.Stop;
var stopMilliseconds = stop.Seconds * 1000;
qua.SliderVelocities.Add(new SliderVelocityInfo
{
Expand Down
2 changes: 1 addition & 1 deletion Quaver.API/Maps/Parsers/Stepmania/StepFileBPM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Quaver.API.Maps.Parsers.Stepmania
{
public class StepFileBPM
public class StepFileBPM : IStepWithBeat
{
/// <summary>
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Quaver.API/Maps/Parsers/Stepmania/StepFileStop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Quaver.API.Maps.Parsers.Stepmania
{
public class StepFileStop
public class StepFileStop : IStepWithBeat
{
/// <summary>
/// </summary>
Expand Down

0 comments on commit 8bfa0ba

Please sign in to comment.