forked from YARC-Official/YARG
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework new chart loaders (YARC-Official#258)
* Turn IChartLoader into an abstract class * Encapsulate chart property info into ChartLoader * Encapsulate event loading into ChartLoader * Add some protected helper methods to ChartLoader * Implement drums SP activation loading * Create static instances for chart loaders * Use null coalescence to initialize YargChart instrument properties
- Loading branch information
1 parent
83358ed
commit 7f684eb
Showing
11 changed files
with
225 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using MoonscraperChartEditor.Song; | ||
|
||
namespace YARG.Chart { | ||
public static class ChartLoader { | ||
public static readonly GuitarChartLoader GuitarLoader = new(MoonSong.MoonInstrument.Guitar); | ||
public static readonly GuitarChartLoader GuitarCoopLoader = new(MoonSong.MoonInstrument.GuitarCoop); | ||
public static readonly GuitarChartLoader RhythmLoader = new(MoonSong.MoonInstrument.Rhythm); | ||
public static readonly GuitarChartLoader BassLoader = new(MoonSong.MoonInstrument.Bass); | ||
public static readonly GuitarChartLoader KeysLoader = new(MoonSong.MoonInstrument.Keys); | ||
|
||
public static readonly FourLaneDrumsChartLoader DrumsLoader = new(pro: false); | ||
public static readonly FourLaneDrumsChartLoader ProDrumsLoader = new(pro: true); | ||
public static readonly FiveLaneDrumsChartLoader FiveLaneDrumsLoader = new(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...Script/Chart/Loaders/IChartLoader.cs.meta → ...art/Loaders/ChartLoader.Instances.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
using MoonscraperChartEditor.Song; | ||
using YARG.Data; | ||
|
||
namespace YARG.Chart { | ||
public abstract class ChartLoader<T> { | ||
public MoonSong.MoonInstrument Instrument { get; protected set; } | ||
public string InstrumentName { get; protected set; } | ||
public Difficulty MaxDifficulty { get; protected set; } = Difficulty.EXPERT; | ||
|
||
public abstract List<T> GetNotesFromChart(MoonSong song, Difficulty chart); | ||
|
||
public virtual List<EventInfo> GetEventsFromChart(MoonSong song) | ||
{ | ||
var events = new List<EventInfo>(); | ||
var chart = song.GetChart(Instrument, MoonSong.Difficulty.Expert); | ||
|
||
// Star Power | ||
foreach (var sp in chart.starPower) { | ||
if (sp.flags != Starpower.Flags.None) { | ||
continue; | ||
} | ||
|
||
events.Add(new EventInfo($"starpower_{InstrumentName}", (float) sp.time, (float) GetStarpowerLength(song, sp))); | ||
} | ||
|
||
// Solos | ||
for (int i = 0; i < chart.events.Count; i++) { | ||
var chartEvent = chart.events[i]; | ||
if (chartEvent.eventName == "solo") { | ||
for (int k = i; k < chart.events.Count; k++) { | ||
var chartEvent2 = chart.events[k]; | ||
if (chartEvent2.eventName == "soloend") { | ||
events.Add(new EventInfo($"solo_{InstrumentName}", (float) chartEvent.time, (float) (chartEvent2.time - chartEvent.time))); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return events; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
protected double GetLength(MoonSong song, double startTime, uint tick, uint tickLength) { | ||
return song.TickToTime(tick + tickLength, song.resolution) - startTime; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
protected double GetNoteLength(MoonSong song, MoonNote note) { | ||
return GetLength(song, note.time, note.tick, note.length); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
protected double GetStarpowerLength(MoonSong song, Starpower sp) { | ||
return GetLength(song, sp.time, sp.tick, sp.length - 1); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
protected MoonChart GetChart(MoonSong song, Difficulty difficulty) { | ||
if (difficulty > Difficulty.EXPERT) { | ||
difficulty = Difficulty.EXPERT; | ||
} else if (difficulty < Difficulty.EASY) { | ||
difficulty = Difficulty.EASY; | ||
} | ||
|
||
return song.GetChart(Instrument, MoonSong.Difficulty.Easy - (int) difficulty); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.