2022-03-08 03:13:53 -05:00
|
|
|
package funkin;
|
2020-11-06 21:17:27 -05:00
|
|
|
|
|
|
|
class Highscore
|
|
|
|
{
|
2020-11-10 12:52:49 -05:00
|
|
|
#if (haxe >= "4.0.0")
|
2020-11-06 21:17:27 -05:00
|
|
|
public static var songScores:Map<String, Int> = new Map();
|
2020-11-10 12:52:49 -05:00
|
|
|
#else
|
|
|
|
public static var songScores:Map<String, Int> = new Map<String, Int>();
|
|
|
|
#end
|
2020-11-06 21:17:27 -05:00
|
|
|
|
2022-12-16 17:10:22 -05:00
|
|
|
#if (haxe >= "4.0.0")
|
|
|
|
public static var songCompletion:Map<String, Float> = new Map();
|
|
|
|
#else
|
|
|
|
public static var songCompletion:Map<String, Float> = new Map<String, Float>();
|
|
|
|
#end
|
|
|
|
|
2022-09-20 02:16:12 -04:00
|
|
|
public static var tallies:Tallies = new Tallies();
|
|
|
|
|
2022-09-23 16:12:18 -04:00
|
|
|
public static function saveScore(song:String, score:Int = 0, ?diff:Int = 0):Bool
|
2020-11-06 21:17:27 -05:00
|
|
|
{
|
2021-02-19 21:11:33 -05:00
|
|
|
var formattedSong:String = formatSong(song, diff);
|
2020-11-06 21:17:27 -05:00
|
|
|
|
2021-02-19 21:11:33 -05:00
|
|
|
#if newgrounds
|
2020-11-06 21:17:27 -05:00
|
|
|
NGio.postScore(score, song);
|
2020-11-06 21:59:51 -05:00
|
|
|
#end
|
2020-11-06 21:17:27 -05:00
|
|
|
|
2021-02-19 21:11:33 -05:00
|
|
|
if (songScores.exists(formattedSong))
|
2020-11-06 21:17:27 -05:00
|
|
|
{
|
2021-02-19 21:11:33 -05:00
|
|
|
if (songScores.get(formattedSong) < score)
|
2022-09-23 16:12:18 -04:00
|
|
|
{
|
2021-02-19 21:11:33 -05:00
|
|
|
setScore(formattedSong, score);
|
2022-09-23 16:12:18 -04:00
|
|
|
return true;
|
|
|
|
// new highscore
|
|
|
|
}
|
2020-11-06 21:17:27 -05:00
|
|
|
}
|
|
|
|
else
|
2021-02-19 21:11:33 -05:00
|
|
|
setScore(formattedSong, score);
|
2022-09-23 16:12:18 -04:00
|
|
|
|
|
|
|
return false;
|
2020-11-06 21:17:27 -05:00
|
|
|
}
|
|
|
|
|
2022-12-16 17:10:22 -05:00
|
|
|
public static function saveCompletion(song:String, completion:Float, ?diff:Int = 0):Bool
|
|
|
|
{
|
|
|
|
var formattedSong:String = formatSong(song, diff);
|
|
|
|
|
|
|
|
if (songCompletion.exists(formattedSong))
|
|
|
|
{
|
|
|
|
if (songCompletion.get(formattedSong) < completion)
|
|
|
|
{
|
|
|
|
setCompletion(formattedSong, completion);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
setCompletion(formattedSong, completion);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-11-06 21:17:27 -05:00
|
|
|
public static function saveWeekScore(week:Int = 1, score:Int = 0, ?diff:Int = 0):Void
|
|
|
|
{
|
2021-02-19 21:11:33 -05:00
|
|
|
#if newgrounds
|
2020-11-06 21:17:27 -05:00
|
|
|
NGio.postScore(score, "Week " + week);
|
2020-11-06 21:59:51 -05:00
|
|
|
#end
|
2020-11-06 21:17:27 -05:00
|
|
|
|
2021-02-19 21:11:33 -05:00
|
|
|
var formattedSong:String = formatSong('week' + week, diff);
|
2020-11-06 05:56:45 -05:00
|
|
|
|
2021-02-19 21:11:33 -05:00
|
|
|
if (songScores.exists(formattedSong))
|
2020-11-06 21:17:27 -05:00
|
|
|
{
|
2021-02-19 21:11:33 -05:00
|
|
|
if (songScores.get(formattedSong) < score)
|
|
|
|
setScore(formattedSong, score);
|
2020-11-06 21:17:27 -05:00
|
|
|
}
|
|
|
|
else
|
2021-02-19 21:11:33 -05:00
|
|
|
setScore(formattedSong, score);
|
2020-11-06 21:17:27 -05:00
|
|
|
}
|
|
|
|
|
2022-12-16 17:10:22 -05:00
|
|
|
static function setCompletion(formattedSong:String, completion:Float):Void
|
|
|
|
{
|
|
|
|
songCompletion.set(formattedSong, completion);
|
|
|
|
FlxG.save.data.songCompletion = songCompletion;
|
|
|
|
FlxG.save.flush();
|
|
|
|
}
|
|
|
|
|
2020-11-06 21:17:27 -05:00
|
|
|
/**
|
|
|
|
* YOU SHOULD FORMAT SONG WITH formatSong() BEFORE TOSSING IN SONG VARIABLE
|
|
|
|
*/
|
2021-02-19 21:11:33 -05:00
|
|
|
static function setScore(formattedSong:String, score:Int):Void
|
2020-11-06 21:17:27 -05:00
|
|
|
{
|
2021-02-19 21:11:33 -05: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-06 21:17:27 -05:00
|
|
|
// Reminder that I don't need to format this song, it should come formatted!
|
2021-02-19 21:11:33 -05:00
|
|
|
songScores.set(formattedSong, score);
|
2020-11-06 21:17:27 -05:00
|
|
|
FlxG.save.data.songScores = songScores;
|
|
|
|
FlxG.save.flush();
|
2021-02-19 21:11:33 -05:00
|
|
|
#end
|
2020-11-06 21:17:27 -05: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));
|
|
|
|
}
|
|
|
|
|
2022-12-16 17:10:22 -05:00
|
|
|
public static function getCompletion(song, diff):Float
|
|
|
|
{
|
|
|
|
if (!songCompletion.exists(formatSong(song, diff)))
|
|
|
|
setCompletion(formatSong(song, diff), 0);
|
|
|
|
|
|
|
|
return songCompletion.get(formatSong(song, diff));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getAllScores()
|
|
|
|
{
|
|
|
|
trace(songScores.toString());
|
|
|
|
}
|
|
|
|
|
2020-11-06 21:17:27 -05:00
|
|
|
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;
|
|
|
|
}
|
2022-12-16 17:10:22 -05:00
|
|
|
|
|
|
|
if (FlxG.save.data.songCompletion != null)
|
|
|
|
songCompletion = FlxG.save.data.songCompletion;
|
2020-11-06 21:17:27 -05:00
|
|
|
}
|
|
|
|
}
|
2022-09-20 02:16:12 -04:00
|
|
|
|
|
|
|
// i only do forward metadata cuz george did!
|
|
|
|
|
|
|
|
@:forward
|
|
|
|
abstract Tallies(RawTallies)
|
|
|
|
{
|
|
|
|
public function new()
|
|
|
|
{
|
|
|
|
this = {
|
|
|
|
combo: 0,
|
|
|
|
missed: 0,
|
|
|
|
shit: 0,
|
|
|
|
bad: 0,
|
|
|
|
good: 0,
|
|
|
|
sick: 0,
|
|
|
|
totalNotes: 0,
|
2022-12-16 17:10:22 -05:00
|
|
|
totalNotesHit: 0,
|
2022-09-23 16:12:18 -04:00
|
|
|
maxCombo: 0,
|
|
|
|
isNewHighscore: false
|
2022-09-20 02:16:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef RawTallies =
|
|
|
|
{
|
|
|
|
var combo:Int;
|
2022-09-20 02:37:43 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* How many notes you let scroll by.
|
|
|
|
*/
|
2022-09-20 02:16:12 -04:00
|
|
|
var missed:Int;
|
2022-09-20 02:37:43 -04:00
|
|
|
|
2022-09-20 02:16:12 -04:00
|
|
|
var shit:Int;
|
|
|
|
var bad:Int;
|
|
|
|
var good:Int;
|
|
|
|
var sick:Int;
|
|
|
|
var maxCombo:Int;
|
2022-09-23 16:12:18 -04:00
|
|
|
var isNewHighscore:Bool;
|
2022-09-20 02:37:43 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* How many notes total that you hit. (NOT how many notes total in the song!)
|
|
|
|
*/
|
2022-12-16 17:10:22 -05:00
|
|
|
var totalNotesHit:Int;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* How many notes PASSED BY AND/OR HIT!!!
|
|
|
|
*/
|
2022-09-20 02:16:12 -04:00
|
|
|
var totalNotes:Int;
|
|
|
|
}
|