Skip to content

Commit d2e2987

Browse files
committed
fix: Song.getFirstValidVariation() now properly takes into account multiple variations/difficulty input
freeplay implement for NEW song stuff w/ assets submod save data crap and crud rank icon fixes for fixed pico menu
1 parent 4fa9a0d commit d2e2987

File tree

4 files changed

+45
-13
lines changed

4 files changed

+45
-13
lines changed

source/funkin/play/song/Song.hx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class Song implements IPlayStateScriptedClass implements IRegistryEntry<SongMeta
9898
}
9999

100100
// this returns false so that any new song can override this and return true when needed
101-
public function isSongNew(currentDifficulty:String):Bool
101+
public function isSongNew(currentDifficulty:String, currentVariation:String):Bool
102102
{
103103
return false;
104104
}
@@ -434,17 +434,25 @@ class Song implements IPlayStateScriptedClass implements IRegistryEntry<SongMeta
434434
return null;
435435
}
436436

437+
/**
438+
* Returns the first valid variation that matches both the difficulty id, and the current character / possible input variations
439+
* @param diffId
440+
* @param currentCharacter
441+
* @param possibleVariations
442+
* @return Null<String>
443+
*/
437444
public function getFirstValidVariation(?diffId:String, ?currentCharacter:PlayableCharacter, ?possibleVariations:Array<String>):Null<String>
438445
{
439446
if (possibleVariations == null)
440447
{
441448
possibleVariations = getVariationsByCharacter(currentCharacter);
442449
}
450+
443451
if (diffId == null) diffId = listDifficulties(null, possibleVariations)[0];
444452

445453
for (variationId in possibleVariations)
446454
{
447-
if (difficulties.exists('$variationId')) return variationId;
455+
if (difficulties.get('$variationId')?.exists(diffId) ?? false) return variationId;
448456
}
449457

450458
return null;

source/funkin/save/Save.hx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,22 +543,34 @@ class Save
543543
*
544544
* @param songId The ID of the song.
545545
* @param difficultyId The difficulty to check.
546+
* @param variation The variation to check. Defaults to empty string. Appended to difficulty with `-`, e.g. `easy-pico`.
546547
* @return A data structure containing score, judgement counts, and accuracy. Returns `null` if no score is saved.
547548
*/
548-
public function getSongScore(songId:String, difficultyId:String = 'normal'):Null<SaveScoreData>
549+
public function getSongScore(songId:String, difficultyId:String = 'normal', ?variation:String):Null<SaveScoreData>
549550
{
550551
var song = data.scores.songs.get(songId);
552+
trace('Getting song score for $songId $difficultyId $variation');
551553
if (song == null)
552554
{
555+
trace('Could not find song data for $songId $difficultyId $variation');
553556
song = [];
554557
data.scores.songs.set(songId, song);
555558
}
559+
560+
// 'default' variations are left with no suffix ('easy', 'normal', 'hard'),
561+
// along with 'erect' variations ('erect', 'nightmare')
562+
// otherwise, we want to add a suffix of our current variation to get the save data.
563+
if (variation != null && variation != '' && variation != 'default' && variation != 'erect')
564+
{
565+
difficultyId = '${difficultyId}-${variation}';
566+
}
567+
556568
return song.get(difficultyId);
557569
}
558570

559-
public function getSongRank(songId:String, difficultyId:String = 'normal'):Null<ScoringRank>
571+
public function getSongRank(songId:String, difficultyId:String = 'normal', ?variation:String):Null<ScoringRank>
560572
{
561-
return Scoring.calculateRank(getSongScore(songId, difficultyId));
573+
return Scoring.calculateRank(getSongScore(songId, difficultyId, variation));
562574
}
563575

564576
/**

source/funkin/ui/freeplay/FreeplayState.hx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,8 +1717,6 @@ class FreeplayState extends MusicBeatSubState
17171717
}
17181718
}
17191719

1720-
trace('CURRENT VARIATION OF SONG: ${currentVariation}');
1721-
17221720
var daSong:Null<FreeplaySongData> = grpCapsules.members[curSelected].freeplayData;
17231721
if (daSong != null)
17241722
{
@@ -1729,7 +1727,7 @@ class FreeplayState extends MusicBeatSubState
17291727
return;
17301728
}
17311729

1732-
var songScore:Null<SaveScoreData> = Save.instance.getSongScore(daSong.data.id, currentDifficulty);
1730+
var songScore:Null<SaveScoreData> = Save.instance.getSongScore(daSong.data.id, currentDifficulty, currentVariation);
17331731
intendedScore = songScore?.score ?? 0;
17341732
intendedCompletion = songScore == null ? 0.0 : ((songScore.tallies.sick + songScore.tallies.good) / songScore.tallies.totalNotes);
17351733
rememberedDifficulty = currentDifficulty;
@@ -2025,7 +2023,7 @@ class FreeplayState extends MusicBeatSubState
20252023
var daSongCapsule:SongMenuItem = grpCapsules.members[curSelected];
20262024
if (daSongCapsule.freeplayData != null)
20272025
{
2028-
var songScore:Null<SaveScoreData> = Save.instance.getSongScore(daSongCapsule.freeplayData.data.id, currentDifficulty);
2026+
var songScore:Null<SaveScoreData> = Save.instance.getSongScore(daSongCapsule.freeplayData.data.id, currentDifficulty, currentVariation);
20292027
intendedScore = songScore?.score ?? 0;
20302028
intendedCompletion = songScore == null ? 0.0 : ((songScore.tallies.sick + songScore.tallies.good) / songScore.tallies.totalNotes);
20312029
rememberedSongId = daSongCapsule.freeplayData.data.id;
@@ -2260,7 +2258,7 @@ class FreeplaySongData
22602258
/**
22612259
* Whether the player has seen/played this song before within freeplay
22622260
*/
2263-
public var isNew:Bool = false;
2261+
public var isNew(get, never):Bool;
22642262

22652263
/**
22662264
* The default opponent for the song.
@@ -2312,6 +2310,18 @@ class FreeplaySongData
23122310
// this.isNew = song.isSongNew(suffixedDifficulty);
23132311
}
23142312

2313+
function get_isNew():Bool
2314+
{
2315+
// We use a slightly different manner to get the new status of a song than the other getters here
2316+
// `isSongNew()` only takes a single variation, and it's data that isn't accessible via the Song data/metadata
2317+
// it's stored in the song .hxc script in a function that overrides `isSongNew()`
2318+
// and is only accessible with the correct valid variation inputs
2319+
2320+
var variations:Array<String> = data.getVariationsByCharacterId(FreeplayState.rememberedCharacterId);
2321+
var variation:String = data.getFirstValidVariation(FreeplayState.rememberedDifficulty, null, variations);
2322+
return data.isSongNew(FreeplayState.rememberedDifficulty, variation);
2323+
}
2324+
23152325
function get_songCharacter():String
23162326
{
23172327
var variations:Array<String> = data.getVariationsByCharacterId(FreeplayState.rememberedCharacterId);
@@ -2340,8 +2350,10 @@ class FreeplaySongData
23402350

23412351
function get_scoringRank():Null<ScoringRank>
23422352
{
2343-
// TODO: Properly get/migrate the save data from the suffixed difficulty version to our new unsuffixed version
2344-
return Save.instance.getSongRank(data.songName, FreeplayState.rememberedDifficulty);
2353+
var variations:Array<String> = data.getVariationsByCharacterId(FreeplayState.rememberedCharacterId);
2354+
var variation:String = data.getFirstValidVariation(FreeplayState.rememberedDifficulty, null, variations);
2355+
2356+
return Save.instance.getSongRank(data.id, FreeplayState.rememberedDifficulty, variation);
23452357
}
23462358
}
23472359

0 commit comments

Comments
 (0)