mirror of
https://github.com/FunkinCrew/Funkin.git
synced 2024-11-22 23:57:50 -05:00
Merge pull request #558 from FunkinCrew/feature/save-favorites
Add freeplay favorites to the save data so they persist between sessions
This commit is contained in:
commit
8a4769e206
4 changed files with 68 additions and 6 deletions
|
@ -715,7 +715,7 @@ class Controls extends FlxActionSet
|
|||
case Control.VOLUME_UP: return [PLUS, NUMPADPLUS];
|
||||
case Control.VOLUME_DOWN: return [MINUS, NUMPADMINUS];
|
||||
case Control.VOLUME_MUTE: return [ZERO, NUMPADZERO];
|
||||
case Control.FULLSCREEN: return [FlxKey.F];
|
||||
case Control.FULLSCREEN: return [FlxKey.F11]; // We use F for other things LOL.
|
||||
|
||||
}
|
||||
case Duo(true):
|
||||
|
|
|
@ -14,8 +14,7 @@ import funkin.util.SerializerUtil;
|
|||
@:nullSafety
|
||||
class Save
|
||||
{
|
||||
// Version 2.0.2 adds attributes to `optionsChartEditor`, that should return default values if they are null.
|
||||
public static final SAVE_DATA_VERSION:thx.semver.Version = "2.0.3";
|
||||
public static final SAVE_DATA_VERSION:thx.semver.Version = "2.0.4";
|
||||
public static final SAVE_DATA_VERSION_RULE:thx.semver.VersionRule = "2.0.x";
|
||||
|
||||
// We load this version's saves from a new save path, to maintain SOME level of backwards compatibility.
|
||||
|
@ -53,7 +52,8 @@ class Save
|
|||
public function new(?data:RawSaveData)
|
||||
{
|
||||
if (data == null) this.data = Save.getDefault();
|
||||
else this.data = data;
|
||||
else
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static function getDefault():RawSaveData
|
||||
|
@ -77,6 +77,9 @@ class Save
|
|||
levels: [],
|
||||
songs: [],
|
||||
},
|
||||
|
||||
favoriteSongs: [],
|
||||
|
||||
options:
|
||||
{
|
||||
// Reasonable defaults.
|
||||
|
@ -554,6 +557,35 @@ class Save
|
|||
return false;
|
||||
}
|
||||
|
||||
public function isSongFavorited(id:String):Bool
|
||||
{
|
||||
if (data.favoriteSongs == null)
|
||||
{
|
||||
data.favoriteSongs = [];
|
||||
flush();
|
||||
};
|
||||
|
||||
return data.favoriteSongs.contains(id);
|
||||
}
|
||||
|
||||
public function favoriteSong(id:String):Void
|
||||
{
|
||||
if (!isSongFavorited(id))
|
||||
{
|
||||
data.favoriteSongs.push(id);
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
public function unfavoriteSong(id:String):Void
|
||||
{
|
||||
if (isSongFavorited(id))
|
||||
{
|
||||
data.favoriteSongs.remove(id);
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
public function getControls(playerId:Int, inputType:Device):Null<SaveControlsData>
|
||||
{
|
||||
switch (inputType)
|
||||
|
@ -740,6 +772,12 @@ typedef RawSaveData =
|
|||
*/
|
||||
var options:SaveDataOptions;
|
||||
|
||||
/**
|
||||
* The user's favorited songs in the Freeplay menu,
|
||||
* as a list of song IDs.
|
||||
*/
|
||||
var favoriteSongs:Array<String>;
|
||||
|
||||
var mods:SaveDataMods;
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [2.0.4] - 2024-05-21
|
||||
### Added
|
||||
- `favoriteSongs:Array<String>` to `Save`
|
||||
|
||||
## [2.0.3] - 2024-01-09
|
||||
### Added
|
||||
|
|
|
@ -699,8 +699,8 @@ class FreeplayState extends MusicBeatSubState
|
|||
if (targetSong != null)
|
||||
{
|
||||
var realShit:Int = curSelected;
|
||||
targetSong.isFav = !targetSong.isFav;
|
||||
if (targetSong.isFav)
|
||||
var isFav = targetSong.toggleFavorite();
|
||||
if (isFav)
|
||||
{
|
||||
FlxTween.tween(grpCapsules.members[realShit], {angle: 360}, 0.4,
|
||||
{
|
||||
|
@ -1412,11 +1412,32 @@ class FreeplaySongData
|
|||
this.levelId = levelId;
|
||||
this.songId = songId;
|
||||
this.song = song;
|
||||
|
||||
this.isFav = Save.instance.isSongFavorited(songId);
|
||||
|
||||
if (displayedVariations != null) this.displayedVariations = displayedVariations;
|
||||
|
||||
updateValues(displayedVariations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle whether or not the song is favorited, then flush to save data.
|
||||
* @return Whether or not the song is now favorited.
|
||||
*/
|
||||
public function toggleFavorite():Bool
|
||||
{
|
||||
isFav = !isFav;
|
||||
if (isFav)
|
||||
{
|
||||
Save.instance.favoriteSong(this.songId);
|
||||
}
|
||||
else
|
||||
{
|
||||
Save.instance.unfavoriteSong(this.songId);
|
||||
}
|
||||
return isFav;
|
||||
}
|
||||
|
||||
function updateValues(variations:Array<String>):Void
|
||||
{
|
||||
this.songDifficulties = song.listDifficulties(variations, false, false);
|
||||
|
|
Loading…
Reference in a new issue