1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-05 14:24:28 +00:00

Merge pull request #454 from FunkinCrew/feature/erect-filter-freeplay

Freeplay menu now filters to supported songs when you change difficulty
This commit is contained in:
Cameron Taylor 2024-04-01 22:08:25 -04:00 committed by GitHub
commit 8a60115df6
2 changed files with 60 additions and 16 deletions

View file

@ -536,21 +536,18 @@ class FreeplayState extends MusicBeatSubState
}); });
} }
var currentFilter:SongFilter = null;
var currentFilteredSongs:Array<FreeplaySongData> = [];
/** /**
* Given the current filter, rebuild the current song list. * Given the current filter, rebuild the current song list.
* *
* @param filterStuff A filter to apply to the song list (regex, startswith, all, favorite) * @param filterStuff A filter to apply to the song list (regex, startswith, all, favorite)
* @param force * @param force
* @param onlyIfChanged Only apply the filter if the song list has changed
*/ */
public function generateSongList(?filterStuff:SongFilter, force:Bool = false):Void public function generateSongList(filterStuff:Null<SongFilter>, force:Bool = false, onlyIfChanged:Bool = true):Void
{ {
curSelected = 1;
for (cap in grpCapsules.members)
{
cap.kill();
}
var tempSongs:Array<FreeplaySongData> = songs; var tempSongs:Array<FreeplaySongData> = songs;
if (filterStuff != null) if (filterStuff != null)
@ -582,6 +579,35 @@ class FreeplayState extends MusicBeatSubState
} }
} }
// Filter further by current selected difficulty.
if (currentDifficulty != null)
{
tempSongs = tempSongs.filter(song -> {
if (song == null) return true; // Random
return song.songDifficulties.contains(currentDifficulty);
});
}
if (onlyIfChanged)
{
// == performs equality by reference
if (tempSongs.isEqualUnordered(currentFilteredSongs)) return;
}
// Only now do we know that the filter is actually changing.
rememberedSongId = grpCapsules.members[curSelected]?.songData?.songId;
for (cap in grpCapsules.members)
{
cap.kill();
}
currentFilter = filterStuff;
currentFilteredSongs = tempSongs;
curSelected = 0;
var hsvShader:HSVShader = new HSVShader(); var hsvShader:HSVShader = new HSVShader();
var randomCapsule:SongMenuItem = grpCapsules.recycle(SongMenuItem); var randomCapsule:SongMenuItem = grpCapsules.recycle(SongMenuItem);
@ -658,11 +684,12 @@ class FreeplayState extends MusicBeatSubState
if (FlxG.keys.justPressed.F) if (FlxG.keys.justPressed.F)
{ {
if (songs[curSelected] != null) var targetSong = grpCapsules.members[curSelected]?.songData;
if (targetSong != null)
{ {
var realShit:Int = curSelected; var realShit:Int = curSelected;
songs[curSelected].isFav = !songs[curSelected].isFav; targetSong.isFav = !targetSong.isFav;
if (songs[curSelected].isFav) if (targetSong.isFav)
{ {
FlxTween.tween(grpCapsules.members[realShit], {angle: 360}, 0.4, FlxTween.tween(grpCapsules.members[realShit], {angle: 360}, 0.4,
{ {
@ -854,11 +881,13 @@ class FreeplayState extends MusicBeatSubState
{ {
dj.resetAFKTimer(); dj.resetAFKTimer();
changeDiff(-1); changeDiff(-1);
generateSongList(currentFilter, true);
} }
if (controls.UI_RIGHT_P && !FlxG.keys.pressed.CONTROL) if (controls.UI_RIGHT_P && !FlxG.keys.pressed.CONTROL)
{ {
dj.resetAFKTimer(); dj.resetAFKTimer();
changeDiff(1); changeDiff(1);
generateSongList(currentFilter, true);
} }
if (controls.BACK && !typing.hasFocus) if (controls.BACK && !typing.hasFocus)
@ -926,7 +955,7 @@ class FreeplayState extends MusicBeatSubState
public override function destroy():Void public override function destroy():Void
{ {
super.destroy(); super.destroy();
var daSong:Null<FreeplaySongData> = songs[curSelected]; var daSong:Null<FreeplaySongData> = grpCapsules.members[curSelected]?.songData;
if (daSong != null) if (daSong != null)
{ {
clearDaCache(daSong.songName); clearDaCache(daSong.songName);
@ -948,10 +977,10 @@ class FreeplayState extends MusicBeatSubState
currentDifficulty = diffIdsCurrent[currentDifficultyIndex]; currentDifficulty = diffIdsCurrent[currentDifficultyIndex];
var daSong:Null<FreeplaySongData> = songs[curSelected]; var daSong:Null<FreeplaySongData> = grpCapsules.members[curSelected].songData;
if (daSong != null) if (daSong != null)
{ {
var songScore:SaveScoreData = Save.instance.getSongScore(songs[curSelected].songId, currentDifficulty); var songScore:SaveScoreData = Save.instance.getSongScore(grpCapsules.members[curSelected].songData.songId, currentDifficulty);
intendedScore = songScore?.score ?? 0; intendedScore = songScore?.score ?? 0;
intendedCompletion = songScore?.accuracy ?? 0.0; intendedCompletion = songScore?.accuracy ?? 0.0;
rememberedDifficulty = currentDifficulty; rememberedDifficulty = currentDifficulty;
@ -1103,6 +1132,12 @@ class FreeplayState extends MusicBeatSubState
targetVariation: targetVariation, targetVariation: targetVariation,
practiceMode: false, practiceMode: false,
minimalMode: false, minimalMode: false,
#if (debug || FORCE_DEBUG_VERSION)
botPlayMode: FlxG.keys.pressed.SHIFT,
#else
botPlayMode: false,
#end
// TODO: Make these an option! It's currently only accessible via chart editor. // TODO: Make these an option! It's currently only accessible via chart editor.
// startTimestamp: 0.0, // startTimestamp: 0.0,
// playbackRate: 0.5, // playbackRate: 0.5,
@ -1115,10 +1150,12 @@ class FreeplayState extends MusicBeatSubState
{ {
if (rememberedSongId != null) if (rememberedSongId != null)
{ {
curSelected = songs.findIndex(function(song) { curSelected = currentFilteredSongs.findIndex(function(song) {
if (song == null) return false; if (song == null) return false;
return song.songId == rememberedSongId; return song.songId == rememberedSongId;
}); });
if (curSelected == -1) curSelected = 0;
} }
if (rememberedDifficulty != null) if (rememberedDifficulty != null)
@ -1127,7 +1164,7 @@ class FreeplayState extends MusicBeatSubState
} }
// Set the difficulty star count on the right. // Set the difficulty star count on the right.
var daSong:Null<FreeplaySongData> = songs[curSelected]; var daSong:Null<FreeplaySongData> = grpCapsules.members[curSelected]?.songData;
albumRoll.setDifficultyStars(daSong?.songRating ?? 0); albumRoll.setDifficultyStars(daSong?.songRating ?? 0);
} }
@ -1156,6 +1193,7 @@ class FreeplayState extends MusicBeatSubState
{ {
intendedScore = 0; intendedScore = 0;
intendedCompletion = 0.0; intendedCompletion = 0.0;
diffIdsCurrent = diffIdsTotal;
rememberedSongId = null; rememberedSongId = null;
rememberedDifficulty = null; rememberedDifficulty = null;
} }

View file

@ -186,6 +186,12 @@ class Constants
*/ */
public static final DEFAULT_DIFFICULTY_LIST:Array<String> = ['easy', 'normal', 'hard']; public static final DEFAULT_DIFFICULTY_LIST:Array<String> = ['easy', 'normal', 'hard'];
/**
* List of all difficulties used by the base game.
* Includes Erect and Nightmare.
*/
public static final DEFAULT_DIFFICULTY_LIST_FULL:Array<String> = ['easy', 'normal', 'hard', 'erect', 'nightmare'];
/** /**
* Default player character for charts. * Default player character for charts.
*/ */