From 686f6c7911f2c8f7b34f35cc1918ccf8f953de45 Mon Sep 17 00:00:00 2001 From: Yoshman29 <81191621+YoshiCrafter29@users.noreply.github.com> Date: Thu, 3 Nov 2022 14:16:24 +0100 Subject: [PATCH] score saving!!!!!!!!!! --- buildnumber.txt | 2 +- source/funkin/game/Highscore.hx | 4 ++-- source/funkin/game/PlayState.hx | 1 + source/funkin/menus/FreeplayState.hx | 31 +++++++++++++++++++++------- source/funkin/system/CoolUtil.hx | 4 ++-- 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/buildnumber.txt b/buildnumber.txt index 9dce352d..a0ce7199 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -1009 \ No newline at end of file +1016 \ No newline at end of file diff --git a/source/funkin/game/Highscore.hx b/source/funkin/game/Highscore.hx index 2df7675c..658f56f6 100644 --- a/source/funkin/game/Highscore.hx +++ b/source/funkin/game/Highscore.hx @@ -47,7 +47,7 @@ class Highscore public static function formatSong(song:String, diff:String):String { - var daSong:String = song; + var daSong:String = song.toLowerCase(); diff = diff.toLowerCase(); if (diff != "normal") daSong += '-$diff'; @@ -60,7 +60,7 @@ class Highscore if (!songScores.exists(daSong)) setScore(daSong, {}); - return prepareScore(songScores.get(formatSong(song, diff))); + return prepareScore(songScores.get(daSong)); } public static function getWeekScore(week:String, diff:String):SongScore diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index e0a996ff..d66953e0 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -306,6 +306,7 @@ class PlayState extends MusicBeatState for(text in [scoreTxt, missesTxt, accuracyTxt]) { text.scrollFactor.set(); + add(text); } scoreTxt.alignment = RIGHT; missesTxt.alignment = CENTER; diff --git a/source/funkin/menus/FreeplayState.hx b/source/funkin/menus/FreeplayState.hx index 646be90f..6398bc36 100644 --- a/source/funkin/menus/FreeplayState.hx +++ b/source/funkin/menus/FreeplayState.hx @@ -1,5 +1,6 @@ package funkin.menus; +import haxe.io.Path; #if desktop import funkin.system.Discord.DiscordClient; #end @@ -170,11 +171,15 @@ class FreeplayState extends MusicBeatState if (Math.abs(lerpScore - intendedScore) <= 10) lerpScore = intendedScore; + changeSelection((controls.UP_P ? -1 : 0) + (controls.DOWN_P ? 1 : 0)); + changeDiff((controls.LEFT_P ? -1 : 0) + (controls.RIGHT_P ? 1 : 0)); + scoreText.text = "PERSONAL BEST:" + lerpScore; - scoreText.x = FlxG.width - scoreText.width - 4; - scoreBG.scale.set(scoreText.width + 8, 66); + scoreBG.scale.set(Math.max(diffText.width, scoreText.width) + 8, 66); scoreBG.updateHitbox(); scoreBG.x = FlxG.width - scoreBG.width; + + scoreText.x = scoreBG.x + 4; diffText.x = Std.int(scoreBG.x + ((scoreBG.width - diffText.width) / 2)); bg.color = CoolUtil.lerpColor(bg.color, songs[curSelected].color, 0.0625); @@ -192,8 +197,6 @@ class FreeplayState extends MusicBeatState } #end - changeSelection((controls.UP_P ? -1 : 0) + (controls.DOWN_P ? 1 : 0)); - changeDiff((controls.LEFT_P ? -1 : 0) + (controls.RIGHT_P ? 1 : 0)); if (controls.BACK) { @@ -238,9 +241,6 @@ class FreeplayState extends MusicBeatState curSelected = FlxMath.wrap(curSelected + change, 0, songs.length-1); changeDiff(0, true); - #if !switch - intendedScore = Highscore.getScore(songs[curSelected].songName, songs[curSelected].difficulties[curDifficulty]).score; - #end #if PRELOAD_ALL autoplayElapsed = 0; @@ -339,6 +339,23 @@ class SongMetadata this.songCharacter = songCharacter; if (difficulties != null && difficulties.length > 0) { this.difficulties = difficulties; + } else { + this.difficulties = difficulties = [for(f in Paths.getFolderContent('data/charts/${song}/')) if (Path.extension(f = f.toUpperCase()) == "JSON") Path.withoutExtension(f)]; + if (difficulties.length == 3) { + var hasHard = false, hasNormal = false, hasEasy = false; + for(d in difficulties) { + switch(d) { + case "EASY": hasEasy = true; + case "NORMAL": hasNormal = true; + case "HARD": hasHard = true; + } + } + if (hasHard && hasNormal && hasEasy) { + difficulties[0] = "EASY"; + difficulties[1] = "NORMAL"; + difficulties[2] = "HARD"; + } + } } } } diff --git a/source/funkin/system/CoolUtil.hx b/source/funkin/system/CoolUtil.hx index 8878981c..7d544b1e 100644 --- a/source/funkin/system/CoolUtil.hx +++ b/source/funkin/system/CoolUtil.hx @@ -30,8 +30,8 @@ class CoolUtil public static function setFieldDefault(v:Dynamic, name:String, defaultValue:T):T { if (Reflect.hasField(v, name)) { - var f = Reflect.field(v, name); - if (f != null && Std.isOfType(f, T)) + var f:Null = Reflect.field(v, name); + if (f != null) return cast f; } Reflect.setField(v, name, defaultValue);