Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement basic .chart drums loading #252

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Implement basic drums ChartLoaders
  • Loading branch information
TheNathannator committed May 5, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 076947be2fbf25acbecee8b7cfe9b2db88cba4b5
55 changes: 55 additions & 0 deletions Assets/Script/Chart/Loaders/FiveLaneDrumsChartLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Collections.Generic;
using MoonscraperChartEditor.Song;
using YARG.Data;

namespace YARG.Chart {
public class FiveLaneDrumsChartLoader : IChartLoader<NoteInfo> {
public List<NoteInfo> GetNotesFromChart(MoonSong song, Difficulty difficulty) {
var notes = new List<NoteInfo>();
bool doubleBass = false;
if (difficulty == Difficulty.EXPERT_PLUS) {
difficulty = Difficulty.EXPERT;
doubleBass = true;
}
var chart = song.GetChart(MoonSong.MoonInstrument.Drums, MoonSong.Difficulty.Easy - (int) difficulty);

foreach (var moonNote in chart.notes) {
// Ignore double-kicks if not Expert+
if (!doubleBass && (moonNote.flags & MoonNote.Flags.DoubleKick) != 0)
continue;

// Convert note value
int pad = MoonDrumNoteToPad(moonNote);
if (pad == -1)
continue;

// Length of the note in realtime
double timeLength = song.TickToTime(moonNote.tick + moonNote.length, song.resolution) - moonNote.time;

var note = new NoteInfo {
time = (float) moonNote.time,
length = (float) timeLength,
fret = pad,
hopo = moonNote.type == MoonNote.MoonNoteType.Cymbal
};

notes.Add(note);
}

// TODO: Need to handle playing 4-lane charts on 5-lane
return notes;
}

private int MoonDrumNoteToPad(MoonNote note) {
return note.drumPad switch {
MoonNote.DrumPad.Kick => 5,
MoonNote.DrumPad.Red => 0,
MoonNote.DrumPad.Yellow => 1,
MoonNote.DrumPad.Blue => 2,
MoonNote.DrumPad.Orange => 3,
MoonNote.DrumPad.Green => 4,
_ => -1
};
}
}
}
11 changes: 11 additions & 0 deletions Assets/Script/Chart/Loaders/FiveLaneDrumsChartLoader.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions Assets/Script/Chart/Loaders/FourLaneDrumsChartLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Collections.Generic;
using MoonscraperChartEditor.Song;
using YARG.Data;

namespace YARG.Chart {
public class FourLaneDrumsChartLoader : IChartLoader<NoteInfo> {
private bool _proDrums;

public FourLaneDrumsChartLoader(bool pro) {
_proDrums = pro;
}

public List<NoteInfo> GetNotesFromChart(MoonSong song, Difficulty difficulty) {
var notes = new List<NoteInfo>();
bool doubleBass = false;
if (difficulty == Difficulty.EXPERT_PLUS) {
difficulty = Difficulty.EXPERT;
doubleBass = true;
}
var chart = song.GetChart(MoonSong.MoonInstrument.Drums, MoonSong.Difficulty.Easy - (int) difficulty);

foreach (var moonNote in chart.notes) {
// Ignore double-kicks if not Expert+
if (!doubleBass && (moonNote.flags & MoonNote.Flags.DoubleKick) != 0)
continue;

// Convert note value
int pad = MoonDrumNoteToPad(moonNote);
if (pad == -1)
continue;

// Length of the note in realtime
double timeLength = song.TickToTime(moonNote.tick + moonNote.length, song.resolution) - moonNote.time;

var note = new NoteInfo {
time = (float) moonNote.time,
length = (float) timeLength,
fret = pad,
hopo = _proDrums && moonNote.type == MoonNote.MoonNoteType.Cymbal
};

notes.Add(note);
}

// TODO: Need to handle playing 5-lane charts on 4-lane
return notes;
}

private int MoonDrumNoteToPad(MoonNote note) {
return note.drumPad switch {
MoonNote.DrumPad.Kick => 4,
MoonNote.DrumPad.Red => 0,
MoonNote.DrumPad.Yellow => 1,
MoonNote.DrumPad.Blue => 2,
MoonNote.DrumPad.Orange => 3, // Moonscraper internally uses Orange for 4-lane green
MoonNote.DrumPad.Green => 3, // Turn 5-lane green into 4-lane green
_ => -1
};
}
}
}
11 changes: 11 additions & 0 deletions Assets/Script/Chart/Loaders/FourLaneDrumsChartLoader.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions Assets/Script/Data/YargChart.cs
Original file line number Diff line number Diff line change
@@ -47,18 +47,19 @@ public List<NoteInfo>[] Keys {

private List<NoteInfo>[] drums;
public List<NoteInfo>[] Drums {
get => drums;// ?? LoadArray(new DrumsChartLoader(false), MoonSong.MoonInstrument.Drums, 4);
get => drums ?? LoadArray(ref drums, new FourLaneDrumsChartLoader(pro: false), MoonSong.MoonInstrument.Drums, Difficulty.EXPERT_PLUS);
set => drums = value;
}

private List<NoteInfo>[] realDrums;
public List<NoteInfo>[] RealDrums {
get => realDrums;// ?? LoadArray(new DrumsChartLoader(true), MoonSong.MoonInstrument.Drums, 4);
get => realDrums ?? LoadArray(ref realDrums, new FourLaneDrumsChartLoader(pro: true), MoonSong.MoonInstrument.Drums, Difficulty.EXPERT_PLUS, isPro: true);
set => realDrums = value;
}

private List<NoteInfo>[] ghDrums;
public List<NoteInfo>[] GhDrums {
get => ghDrums;// ?? LoadArray(new DrumsChartLoader(false), MoonSong.MoonInstrument.Drums, 4);
get => ghDrums ?? LoadArray(ref ghDrums, new FiveLaneDrumsChartLoader(), MoonSong.MoonInstrument.Drums, Difficulty.EXPERT_PLUS, isGh: true);
set => ghDrums = value;
}