diff --git a/buildnumber.txt b/buildnumber.txt index 6ea72f04..35fb9399 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -1032 \ No newline at end of file +1041 \ No newline at end of file diff --git a/source/funkin/game/Highscore.hx b/source/funkin/game/Highscore.hx index 658f56f6..61719756 100644 --- a/source/funkin/game/Highscore.hx +++ b/source/funkin/game/Highscore.hx @@ -84,11 +84,9 @@ class Highscore } public static function load():Void { - if (FlxG.save.data.songScores != null) - { - songScores = FlxG.save.data.songScores; - weekScores = FlxG.save.data.weekScores; - } + songScores = FlxG.save.data.songScores.getDefault(new Map()); + weekScores = FlxG.save.data.weekScores.getDefault(new Map()); + for(k=>e in songScores) if (e is Int) songScores.remove(k); diff --git a/source/funkin/menus/StoryMenuState.hx b/source/funkin/menus/StoryMenuState.hx index 4717bc55..3d63a0a9 100644 --- a/source/funkin/menus/StoryMenuState.hx +++ b/source/funkin/menus/StoryMenuState.hx @@ -1,7 +1,10 @@ package funkin.menus; +import funkin.game.Highscore; +import flixel.tweens.FlxTween; import openfl.utils.Assets; import flixel.FlxG; +import flixel.math.FlxMath; import flixel.util.FlxColor; import funkin.ui.FunkinText; import haxe.xml.Access; @@ -9,8 +12,6 @@ import flixel.FlxSprite; import flixel.text.FlxText; class StoryMenuState extends MusicBeatState { - public var weekData:Array = []; - public var characters:Map = []; public var weeks:Array = []; @@ -26,6 +27,11 @@ class StoryMenuState extends MusicBeatState { public var leftArrow:FlxSprite; public var rightArrow:FlxSprite; + public var lerpScore:Float = 0; + public var intendedScore:Int = 0; + + public var canSelect:Bool = true; + public override function create() { super.create(); loadXMLs(); @@ -45,12 +51,9 @@ class StoryMenuState extends MusicBeatState { weekBG.setGraphicSize(FlxG.width, 400); weekBG.updateHitbox(); - for(e in [scoreText, weekTitle, weekBG]) - add(e); // DUMBASS ARROWS var assets = Paths.getSparrowAtlas('menus/storymenu/assets'); - var directions = ["left", "right"]; leftArrow = new FlxSprite((FlxG.width + 400) / 2, weekBG.y + weekBG.height + 10 + 10); @@ -65,7 +68,86 @@ class StoryMenuState extends MusicBeatState { add(arrow); } rightArrow.x -= rightArrow.width; + + tracklist = new FunkinText(64, weekBG.y + weekBG.height + 44, Std.int(((FlxG.width - 400) / 2) - 128), "TRACKS", 32); + tracklist.alignment = CENTER; + tracklist.color = 0xFFE55777; + + for(e in [scoreText, weekTitle, weekBG, tracklist]) + add(e); + + for(week in weeks) { + for(e in week.difficulties) { + var le = e.toLowerCase(); + if (difficultySprites[le] == null) { + var diffSprite = new FlxSprite(leftArrow.x + leftArrow.width, leftArrow.y); + diffSprite.loadAnimatedGraphic(Paths.image('menus/storymenu/difficulties/${le}')); + diffSprite.setUnstretchedGraphicSize(Std.int(rightArrow.x - leftArrow.x - leftArrow.width), Std.int(leftArrow.height), false, 1); + diffSprite.antialiasing = true; + add(diffSprite); + + difficultySprites[le] = diffSprite; + } + } + } + changeWeek(0, true); + } + + var __lastDifficultyTween:FlxTween; + public override function update(elapsed:Float) { + super.update(elapsed); + + lerpScore = lerp(lerpScore, intendedScore, 0.5); + scoreText.text = 'WEEK SCORE:${Math.round(lerpScore)}'; + if (canSelect) { + leftArrow.animation.play(controls.LEFT ? 'press' : 'idle'); + rightArrow.animation.play(controls.RIGHT ? 'press' : 'idle'); + + if (controls.BACK) + FlxG.switchState(new MainMenuState()); + + + changeDifficulty((controls.LEFT_P ? -1 : 0) + (controls.RIGHT_P ? 1 : 0)); + changeWeek((controls.UP_P ? -1 : 0) + (controls.DOWN_P ? 1 : 0)); + + if (controls.ACCEPT) { + } + } else { + for(e in [leftArrow, rightArrow]) + e.animation.play('idle'); + } + } + + var __oldDiffName = null; + public function changeDifficulty(change:Int, force:Bool = false) { + if (change == 0 && !force) return; + + curDifficulty = FlxMath.wrap(curDifficulty + change, 0, weeks[curWeek].difficulties.length-1); + + if (__oldDiffName != (__oldDiffName = weeks[curWeek].difficulties[curDifficulty].toLowerCase())) { + for(e in difficultySprites) e.visible = false; + + var diffSprite = difficultySprites[__oldDiffName]; + if (diffSprite != null) { + diffSprite.visible = true; + + if (__lastDifficultyTween != null) + __lastDifficultyTween.cancel(); + diffSprite.alpha = 0; + diffSprite.y = leftArrow.y - 15; + + FlxTween.tween(diffSprite, {y: leftArrow.y + 15, alpha: 1}, 0.07); + } + + intendedScore = Highscore.getWeekScore(weeks[curWeek].name, weeks[curWeek].difficulties[curDifficulty]).score; + } + } + + public function changeWeek(change:Int, force:Bool = false) { + if (change == 0 && !force) return; + + changeDifficulty(0, true); } public function loadXMLs() { @@ -102,7 +184,8 @@ class StoryMenuState extends MusicBeatState { name: week.att.name, sprite: week.getAtt('sprite').getDefault('week${k}'), chars: [null, null, null], - songs: [] + songs: [], + difficulties: ['easy', 'normal', 'hard'] }; if (week.has.chars) { for(k=>e in week.att.chars.split(",")) { @@ -134,16 +217,6 @@ class StoryMenuState extends MusicBeatState { Logs.trace('Failed to parse data/weeks.xml: $e', ERROR); } } - - public override function update(elapsed:Float) { - super.update(elapsed); - leftArrow.animation.play(controls.LEFT ? 'press' : 'idle'); - rightArrow.animation.play(controls.RIGHT ? 'press' : 'idle'); - - if (controls.BACK) { - FlxG.switchState(new MainMenuState()); - } - } } typedef WeekData = { @@ -151,6 +224,7 @@ typedef WeekData = { var sprite:String; var chars:Array; var songs:Array; + var difficulties:Array; } typedef WeekSong = { diff --git a/source/funkin/system/CoolUtil.hx b/source/funkin/system/CoolUtil.hx index 7d544b1e..5c704c40 100644 --- a/source/funkin/system/CoolUtil.hx +++ b/source/funkin/system/CoolUtil.hx @@ -1,5 +1,6 @@ package funkin.system; +import haxe.io.Path; import haxe.xml.Access; import flixel.input.keyboard.FlxKey; import lime.utils.Assets; @@ -157,10 +158,11 @@ class CoolUtil anim2.frames = old; } - public static function setUnstretchedGraphicSize(sprite:FlxSprite, width:Int, height:Int, fill:Bool = true) { + public static function setUnstretchedGraphicSize(sprite:FlxSprite, width:Int, height:Int, fill:Bool = true, maxScale:Float = 0) { sprite.setGraphicSize(width, height); sprite.updateHitbox(); var nScale = (fill ? Math.max : Math.min)(sprite.scale.x, sprite.scale.y); + if (maxScale > 0 && nScale > maxScale) nScale = maxScale; sprite.scale.set(nScale, nScale); } @@ -228,4 +230,13 @@ class CoolUtil public static function last(array:Array):T { return array[array.length-1]; } + + public static function loadAnimatedGraphic(spr:FlxSprite, path:String) { + var noExt = Path.withoutExtension(path); + if (Assets.exists('$noExt.xml')) { + spr.frames = Paths.getSparrowAtlasAlt(noExt); + } else { + spr.loadGraphic(path); + } + } } \ No newline at end of file diff --git a/source/funkin/system/Paths.hx b/source/funkin/system/Paths.hx index dd3158e1..91e76d05 100644 --- a/source/funkin/system/Paths.hx +++ b/source/funkin/system/Paths.hx @@ -155,12 +155,21 @@ class Paths { return FlxAtlasFrames.fromSparrow(image(key, library), file('images/$key.xml', library)); } + inline static public function getSparrowAtlasAlt(key:String) + { + return FlxAtlasFrames.fromSparrow('$key.png', '$key.xml'); + } inline static public function getPackerAtlas(key:String, ?library:String) { return FlxAtlasFrames.fromSpriteSheetPacker(image(key, library), file('images/$key.txt', library)); } + inline static public function getPackerAtlasAlt(key:String) + { + return FlxAtlasFrames.fromSpriteSheetPacker('$key.png', '$key.txt'); + } + static public function getFolderContent(key:String, includeSource:Bool = true, addPath:Bool = false, scanSource:Bool = false):Array { // designed to work both on windows and web