1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-01 12:24:27 +00:00
Funkin/source/Highscore.hx

103 lines
2.3 KiB
Haxe
Raw Normal View History

2020-11-07 02:17:27 +00:00
package;
import flixel.FlxG;
class Highscore
{
2020-11-10 17:52:49 +00:00
#if (haxe >= "4.0.0")
2020-11-07 02:17:27 +00:00
public static var songScores:Map<String, Int> = new Map();
2020-11-10 17:52:49 +00:00
#else
public static var songScores:Map<String, Int> = new Map<String, Int>();
#end
2020-11-07 02:17:27 +00:00
2020-11-07 02:17:27 +00:00
public static function saveScore(song:String, score:Int = 0, ?diff:Int = 0):Void
{
2021-02-20 02:11:33 +00:00
var formattedSong:String = formatSong(song, diff);
2020-11-07 02:17:27 +00:00
2021-02-20 02:11:33 +00:00
#if newgrounds
2020-11-07 02:17:27 +00:00
NGio.postScore(score, song);
2020-11-07 02:59:51 +00:00
#end
2020-11-07 02:17:27 +00:00
2021-02-20 02:11:33 +00:00
if (songScores.exists(formattedSong))
2020-11-07 02:17:27 +00:00
{
2021-02-20 02:11:33 +00:00
if (songScores.get(formattedSong) < score)
setScore(formattedSong, score);
2020-11-07 02:17:27 +00:00
}
else
2021-02-20 02:11:33 +00:00
setScore(formattedSong, score);
2020-11-07 02:17:27 +00:00
}
public static function saveWeekScore(week:Int = 1, score:Int = 0, ?diff:Int = 0):Void
{
2021-02-20 02:11:33 +00:00
#if newgrounds
2020-11-07 02:17:27 +00:00
NGio.postScore(score, "Week " + week);
2020-11-07 02:59:51 +00:00
#end
2020-11-07 02:17:27 +00:00
2021-02-20 02:11:33 +00:00
var formattedSong:String = formatSong('week' + week, diff);
2020-11-06 10:56:45 +00:00
2021-02-20 02:11:33 +00:00
if (songScores.exists(formattedSong))
2020-11-07 02:17:27 +00:00
{
2021-02-20 02:11:33 +00:00
if (songScores.get(formattedSong) < score)
setScore(formattedSong, score);
2020-11-07 02:17:27 +00:00
}
else
2021-02-20 02:11:33 +00:00
setScore(formattedSong, score);
2020-11-07 02:17:27 +00:00
}
/**
* YOU SHOULD FORMAT SONG WITH formatSong() BEFORE TOSSING IN SONG VARIABLE
*/
2021-02-20 02:11:33 +00:00
static function setScore(formattedSong:String, score:Int):Void
2020-11-07 02:17:27 +00:00
{
2021-02-20 02:11:33 +00:00
/** GeoKureli
* References to Highscore were wrapped in `#if !switch` blocks. I wasn't sure if this
* is because switch doesn't use NGio, or because switch has a different saving method.
* I moved the compiler flag here, rather than using it everywhere else.
*/
#if !switch
2020-11-07 02:17:27 +00:00
// Reminder that I don't need to format this song, it should come formatted!
2021-02-20 02:11:33 +00:00
songScores.set(formattedSong, score);
2020-11-07 02:17:27 +00:00
FlxG.save.data.songScores = songScores;
FlxG.save.flush();
2021-02-20 02:11:33 +00:00
#end
2020-11-07 02:17:27 +00:00
}
public static function formatSong(song:String, diff:Int):String
{
var daSong:String = song;
if (diff == 0)
daSong += '-easy';
else if (diff == 2)
daSong += '-hard';
return daSong;
}
public static function getScore(song:String, diff:Int):Int
{
if (!songScores.exists(formatSong(song, diff)))
setScore(formatSong(song, diff), 0);
return songScores.get(formatSong(song, diff));
}
public static function getWeekScore(week:Int, diff:Int):Int
{
if (!songScores.exists(formatSong('week' + week, diff)))
setScore(formatSong('week' + week, diff), 0);
return songScores.get(formatSong('week' + week, diff));
}
public static function load():Void
{
if (FlxG.save.data.songScores != null)
{
songScores = FlxG.save.data.songScores;
}
}
}