From 8e4907b62d12c58ff0dbc5366ed6f4b008e10f88 Mon Sep 17 00:00:00 2001 From: HackDev <80620538+Hackx2@users.noreply.github.com> Date: Wed, 30 Oct 2024 10:31:54 +0000 Subject: [PATCH] fixed story & freeplay menus with baseassets disabled --- .../images/storymenu/props/Menu_Tracks.png | Bin .../props/campaign_menu_UI_assets.png | Bin .../props/campaign_menu_UI_assets.xml | 0 source/funkin/game/objects/MusicPlayer.hx | 369 +++++++++++ source/funkin/game/states/FreeplayState.hx | 618 ++++++++++-------- source/funkin/game/states/StoryMenuState.hx | 132 ++-- source/funkin/import.hx | 1 + 7 files changed, 784 insertions(+), 336 deletions(-) rename assets/{BASE_GAME => }/shared/images/storymenu/props/Menu_Tracks.png (100%) rename assets/{BASE_GAME => }/shared/images/storymenu/props/campaign_menu_UI_assets.png (100%) rename assets/{BASE_GAME => }/shared/images/storymenu/props/campaign_menu_UI_assets.xml (100%) create mode 100644 source/funkin/game/objects/MusicPlayer.hx diff --git a/assets/BASE_GAME/shared/images/storymenu/props/Menu_Tracks.png b/assets/shared/images/storymenu/props/Menu_Tracks.png similarity index 100% rename from assets/BASE_GAME/shared/images/storymenu/props/Menu_Tracks.png rename to assets/shared/images/storymenu/props/Menu_Tracks.png diff --git a/assets/BASE_GAME/shared/images/storymenu/props/campaign_menu_UI_assets.png b/assets/shared/images/storymenu/props/campaign_menu_UI_assets.png similarity index 100% rename from assets/BASE_GAME/shared/images/storymenu/props/campaign_menu_UI_assets.png rename to assets/shared/images/storymenu/props/campaign_menu_UI_assets.png diff --git a/assets/BASE_GAME/shared/images/storymenu/props/campaign_menu_UI_assets.xml b/assets/shared/images/storymenu/props/campaign_menu_UI_assets.xml similarity index 100% rename from assets/BASE_GAME/shared/images/storymenu/props/campaign_menu_UI_assets.xml rename to assets/shared/images/storymenu/props/campaign_menu_UI_assets.xml diff --git a/source/funkin/game/objects/MusicPlayer.hx b/source/funkin/game/objects/MusicPlayer.hx new file mode 100644 index 00000000..8efb8514 --- /dev/null +++ b/source/funkin/game/objects/MusicPlayer.hx @@ -0,0 +1,369 @@ +package funkin.game.objects; + +import flixel.group.FlxGroup; +import flixel.ui.FlxBar; +import flixel.util.FlxStringUtil; + +/** + * Music player used for Freeplay + */ +@:access(funkin.game.states.FreeplayState) +class MusicPlayer extends FlxGroup +{ + public var instance:FreeplayState; + public var controls:Controls; + + public var playing(get, never):Bool; + + public var playingMusic:Bool = false; + public var curTime:Float; + + var songBG:FlxSprite; + var songTxt:FlxText; + var timeTxt:FlxText; + var progressBar:FlxBar; + var playbackBG:FlxSprite; + var playbackSymbols:Array = []; + var playbackTxt:FlxText; + + var wasPlaying:Bool; + + var holdPitchTime:Float = 0; + var playbackRate(default, set):Float = 1; + + public function new(instance:FreeplayState) + { + super(); + + this.instance = instance; + this.controls = instance.controls; + + var xPos:Float = FlxG.width * 0.7; + + songBG = new FlxSprite(xPos - 6, 0).makeGraphic(1, 100, 0xFF000000); + songBG.alpha = 0.6; + add(songBG); + + playbackBG = new FlxSprite(xPos - 6, 0).makeGraphic(1, 100, 0xFF000000); + playbackBG.alpha = 0.6; + add(playbackBG); + + songTxt = new FlxText(FlxG.width * 0.7, 5, 0, "", 32); + songTxt.setFormat(Paths.font("vcr.ttf"), 32, FlxColor.WHITE, RIGHT); + add(songTxt); + + timeTxt = new FlxText(xPos, songTxt.y + 60, 0, "", 32); + timeTxt.setFormat(Paths.font("vcr.ttf"), 32, FlxColor.WHITE, RIGHT); + add(timeTxt); + + for (i in 0...2) + { + var text:FlxText = new FlxText(); + text.setFormat(Paths.font('vcr.ttf'), 32, FlxColor.WHITE, CENTER); + text.text = '^'; + if (i == 1) + text.flipY = true; + text.visible = false; + playbackSymbols.push(text); + add(text); + } + + progressBar = new FlxBar(timeTxt.x, timeTxt.y + timeTxt.height, LEFT_TO_RIGHT, Std.int(timeTxt.width), 8, null, "", 0, Math.POSITIVE_INFINITY); + progressBar.createFilledBar(FlxColor.WHITE, FlxColor.BLACK); + add(progressBar); + + playbackTxt = new FlxText(FlxG.width * 0.6, 20, 0, "", 32); + playbackTxt.setFormat(Paths.font("vcr.ttf"), 32, FlxColor.WHITE); + add(playbackTxt); + + switchPlayMusic(); + } + + override function update(elapsed:Float) + { + super.update(elapsed); + + if (!playingMusic) + { + return; + } + + var songName:String = instance.songs[FreeplayState.curSelected].songName; + if (playing && !wasPlaying) + songTxt.text = 'PLAYING: $songName'; + else + songTxt.text = 'PLAYING: $songName (PAUSED)'; + + //if(FlxG.keys.justPressed.K) trace('Time: ${FreeplayState.vocals.time}, Playing: ${FreeplayState.vocals.playing}'); + + if (controls.UI_LEFT_P) + { + if (playing) + wasPlaying = true; + + pauseOrResume(); + + curTime = FlxG.sound.music.time - 1000; + instance.holdTime = 0; + + if (curTime < 0) + curTime = 0; + + FlxG.sound.music.time = curTime; + setVocalsTime(curTime); + } + if (controls.UI_RIGHT_P) + { + if (playing) + wasPlaying = true; + + pauseOrResume(); + + curTime = FlxG.sound.music.time + 1000; + instance.holdTime = 0; + + if (curTime > FlxG.sound.music.length) + curTime = FlxG.sound.music.length; + + FlxG.sound.music.time = curTime; + setVocalsTime(curTime); + } + + if(controls.UI_LEFT || controls.UI_RIGHT) + { + instance.holdTime += elapsed; + if(instance.holdTime > 0.5) + { + curTime += 40000 * elapsed * (controls.UI_LEFT ? -1 : 1); + } + + var difference:Float = Math.abs(curTime - FlxG.sound.music.time); + if(curTime + difference > FlxG.sound.music.length) curTime = FlxG.sound.music.length; + else if(curTime - difference < 0) curTime = 0; + + FlxG.sound.music.time = curTime; + setVocalsTime(curTime); + } + + if(controls.UI_LEFT_R || controls.UI_RIGHT_R) + { + FlxG.sound.music.time = curTime; + setVocalsTime(curTime); + + if (wasPlaying) + { + pauseOrResume(true); + wasPlaying = false; + } + } + if (controls.UI_UP_P) + { + holdPitchTime = 0; + playbackRate += 0.05; + setPlaybackRate(); + } + else if (controls.UI_DOWN_P) + { + holdPitchTime = 0; + playbackRate -= 0.05; + setPlaybackRate(); + } + if (controls.UI_DOWN || controls.UI_UP) + { + holdPitchTime += elapsed; + if (holdPitchTime > 0.6) + { + playbackRate += 0.05 * (controls.UI_UP ? 1 : -1); + setPlaybackRate(); + } + } + + if (controls.RESET) + { + playbackRate = 1; + setPlaybackRate(); + + FlxG.sound.music.time = 0; + setVocalsTime(0); + } + + if (playing) + { + if(FreeplayState.vocals != null) + FreeplayState.vocals.volume = (FreeplayState.vocals.length > FlxG.sound.music.time) ? 0.8 : 0; + if(FreeplayState.opponentVocals != null) + FreeplayState.opponentVocals.volume = (FreeplayState.opponentVocals.length > FlxG.sound.music.time) ? 0.8 : 0; + + if((FreeplayState.vocals != null && FreeplayState.vocals.length > FlxG.sound.music.time && Math.abs(FlxG.sound.music.time - FreeplayState.vocals.time) >= 25) || + (FreeplayState.opponentVocals != null && FreeplayState.opponentVocals.length > FlxG.sound.music.time && Math.abs(FlxG.sound.music.time - FreeplayState.opponentVocals.time) >= 25)) + { + pauseOrResume(); + setVocalsTime(FlxG.sound.music.time); + pauseOrResume(true); + } + } + + positionSong(); + updateTimeTxt(); + updatePlaybackTxt(); + } + + function setVocalsTime(time:Float) + { + if (FreeplayState.vocals != null && FreeplayState.vocals.length > time) + FreeplayState.vocals.time = time; + if (FreeplayState.opponentVocals != null && FreeplayState.opponentVocals.length > time) + FreeplayState.opponentVocals.time = time; + } + + public function pauseOrResume(resume:Bool = false) + { + if (resume) + { + if(!FlxG.sound.music.playing) + FlxG.sound.music.resume(); + + if (FreeplayState.vocals != null && FreeplayState.vocals.length > FlxG.sound.music.time && !FreeplayState.vocals.playing) + FreeplayState.vocals.resume(); + if (FreeplayState.opponentVocals != null && FreeplayState.opponentVocals.length > FlxG.sound.music.time && !FreeplayState.opponentVocals.playing) + FreeplayState.opponentVocals.resume(); + } + else + { + FlxG.sound.music.pause(); + + if (FreeplayState.vocals != null) + FreeplayState.vocals.pause(); + if (FreeplayState.opponentVocals != null) + FreeplayState.opponentVocals.pause(); + } + } + + public function switchPlayMusic() + { + //FlxG.autoPause = (!playingMusic && ClientPrefs.data.autoPause); + active = visible = playingMusic; + + instance.scoreBG.visible = instance.diffText.visible = instance.scoreText.visible = !playingMusic; //Hide Freeplay texts and boxes if playingMusic is true + songTxt.visible = timeTxt.visible = songBG.visible = playbackTxt.visible = playbackBG.visible = progressBar.visible = playingMusic; //Show Music Player texts and boxes if playingMusic is true + + for (i in playbackSymbols) + i.visible = playingMusic; + + holdPitchTime = 0; + instance.holdTime = 0; + playbackRate = 1; + updatePlaybackTxt(); + + if (playingMusic) + { + instance.bottomText.text = 'Press SPACE to Pause / Press ESCAPE to Exit / Press R to Reset the Song'; + positionSong(); + + progressBar.setRange(0, FlxG.sound.music.length); + progressBar.setParent(FlxG.sound.music, "time"); + progressBar.numDivisions = 1600; + + updateTimeTxt(); + } + else + { + progressBar.setRange(0, Math.POSITIVE_INFINITY); + progressBar.setParent(null, ""); + progressBar.numDivisions = 0; + + instance.bottomText.text = instance.bottomString; + instance.positionHighscore(); + } + progressBar.updateBar(); + } + + function updatePlaybackTxt() + { + var text = ""; + if (playbackRate is Int) + text = playbackRate + '.00'; + else + { + var playbackRate = Std.string(playbackRate); + if (playbackRate.split('.')[1].length < 2) // Playback rates for like 1.1, 1.2 etc + playbackRate += '0'; + + text = playbackRate; + } + playbackTxt.text = text + 'x'; + } + + function positionSong() + { + var length:Int = instance.songs[FreeplayState.curSelected].songName.length; + var shortName:Bool = length < 5; // Fix for song names like Ugh, Guns + songTxt.x = FlxG.width - songTxt.width - 6; + if (shortName) + songTxt.x -= 10 * length - length; + songBG.scale.x = FlxG.width - songTxt.x + 12; + if (shortName) + songBG.scale.x += 6 * length; + songBG.x = FlxG.width - (songBG.scale.x / 2); + timeTxt.x = Std.int(songBG.x + (songBG.width / 2)); + timeTxt.x -= timeTxt.width / 2; + if (shortName) + timeTxt.x -= length - 5; + + playbackBG.scale.x = playbackTxt.width + 30; + playbackBG.x = songBG.x - (songBG.scale.x / 2); + playbackBG.x -= playbackBG.scale.x; + + playbackTxt.x = playbackBG.x - playbackTxt.width / 2; + playbackTxt.y = playbackTxt.height; + + progressBar.setGraphicSize(Std.int(songTxt.width), 5); + progressBar.y = songTxt.y + songTxt.height + 10; + progressBar.x = songTxt.x + songTxt.width / 2 - 15; + if (shortName) + { + progressBar.scale.x += length / 2; + progressBar.x -= length - 10; + } + + for (i in 0...2) + { + var text = playbackSymbols[i]; + text.x = playbackTxt.x + playbackTxt.width / 2 - 10; + text.y = playbackTxt.y; + + if (i == 0) + text.y -= playbackTxt.height; + else + text.y += playbackTxt.height; + } + } + + function updateTimeTxt() + { + var text = FlxStringUtil.formatTime(FlxG.sound.music.time / 1000, false) + ' / ' + FlxStringUtil.formatTime(FlxG.sound.music.length / 1000, false); + timeTxt.text = '< ' + text + ' >'; + } + + function setPlaybackRate() + { + FlxG.sound.music.pitch = playbackRate; + if (FreeplayState.vocals != null) + FreeplayState.vocals.pitch = playbackRate; + if (FreeplayState.opponentVocals != null) + FreeplayState.opponentVocals.pitch = playbackRate; + } + + function get_playing():Bool + { + return FlxG.sound.music.playing; + } + + function set_playbackRate(value:Float):Float + { + var value = FlxMath.roundDecimal(value, 2); + if (value > 3) value = 3; + else if (value <= 0.25) value = 0.25; + return playbackRate = value; + } +} \ No newline at end of file diff --git a/source/funkin/game/states/FreeplayState.hx b/source/funkin/game/states/FreeplayState.hx index a1b62b15..78d30671 100644 --- a/source/funkin/game/states/FreeplayState.hx +++ b/source/funkin/game/states/FreeplayState.hx @@ -34,7 +34,9 @@ import funkin.backend.system.MusicBeatState; import sys.FileSystem; #end - +import flixel.math.FlxMath; +import flixel.util.FlxDestroyUtil; +import haxe.Json; class FreeplayState extends MusicBeatState { @@ -42,8 +44,9 @@ class FreeplayState extends MusicBeatState var selector:FlxText; private static var curSelected:Int = 0; + var lerpSelected:Float = 0; var curDifficulty:Int = -1; - private static var lastDifficultyName:String = ''; + private static var lastDifficultyName:String = Difficulty.getDefault(); var scoreBG:FlxSprite; var scoreText:FlxText; @@ -53,28 +56,49 @@ class FreeplayState extends MusicBeatState var intendedScore:Int = 0; var intendedRating:Float = 0; - private var grpSongs:FlxTypedGroup; + private var grpSongs:FlxTypedGroup; private var curPlaying:Bool = false; private var iconArray:Array = []; var bg:FlxSprite; var intendedColor:Int; - var colorTween:FlxTween; + + var missingTextBG:FlxSprite; + var missingText:FlxText; + + var bottomString:String; + var bottomText:FlxText; + var bottomBG:FlxSprite; + + var player:MusicPlayer; override function create() { + //Paths.clearStoredMemory(); + //Paths.clearUnusedMemory(); + persistentUpdate = true; PlayState.isStoryMode = false; WeekData.reloadWeekFiles(false); - #if desktop + #if DISCORD_ALLOWED // Updating Discord Rich Presence - DiscordClient.changePresence("Freeplay Menu", null); - WindowUtil.setTitle('Freeplay'); + DiscordClient.changePresence("In the Menus", null); #end - for (i in 0...WeekData.weeksList.length) { + if(WeekData.weeksList.length < 1) + { + FlxTransitionableState.skipNextTransIn = true; + persistentUpdate = false; + MusicBeatState.switchState(new ErrorState("NO WEEKS ADDED FOR FREEPLAY\n\nPress ACCEPT to go to the Week Editor Menu.\nPress BACK to return to Main Menu.", + function() MusicBeatState.switchState(new WeekEditorState()), + function() MusicBeatState.switchState(new MainMenuState()))); + return; + } + + for (i in 0...WeekData.weeksList.length) + { if(weekIsLocked(WeekData.weeksList[i])) continue; var leWeek:WeekData = WeekData.weeksLoaded.get(WeekData.weeksList[i]); @@ -100,44 +124,32 @@ class FreeplayState extends MusicBeatState } Mods.loadTopMod(); - /* //KIND OF BROKEN NOW AND ALSO PRETTY USELESS// - - var initSonglist = CoolUtil.coolTextFile(Paths.txt('freeplaySonglist')); - for (i in 0...initSonglist.length) - { - if(initSonglist[i] != null && initSonglist[i].length > 0) { - var songArray:Array = initSonglist[i].split(":"); - addSong(songArray[0], 0, songArray[1], Std.parseInt(songArray[2])); - } - }*/ - bg = new FlxSprite().loadGraphic(Paths.image('menuDesat')); - bg.antialiasing = funkin.backend.utils.ClientPrefs.data.globalAntialiasing; + bg.antialiasing = ClientPrefs.data.antialiasing; add(bg); bg.screenCenter(); - grpSongs = new FlxTypedGroup(); + grpSongs = new FlxTypedGroup(); add(grpSongs); for (i in 0...songs.length) { - var songText:funkin.game.objects.Alphabet = new funkin.game.objects.Alphabet(90, 320, songs[i].songName, true); - songText.isMenuItem = true; - songText.targetY = i - curSelected; + var songText:Alphabet = new Alphabet(90, 320, songs[i].songName, true); + songText.targetY = i; grpSongs.add(songText); - var maxWidth = 980; - if (songText.width > maxWidth) - { - songText.scaleX = maxWidth / songText.width; - } + songText.scaleX = Math.min(1, 980 / songText.width); songText.snapToPosition(); Mods.currentModDirectory = songs[i].folder; var icon:HealthIcon = new HealthIcon(songs[i].songCharacter); - // icon.animation.curAnim.curFrame = 1; icon.sprTracker = songText; + + // too laggy with a lot of songs, so i had to recode the logic for it + songText.visible = songText.active = songText.isMenuItem = false; + icon.visible = icon.active = false; + // using a FlxGroup is too much fuss! iconArray.push(icon); add(icon); @@ -161,50 +173,47 @@ class FreeplayState extends MusicBeatState add(scoreText); + + missingTextBG = new FlxSprite().makeGraphic(FlxG.width, FlxG.height, FlxColor.BLACK); + missingTextBG.alpha = 0.6; + missingTextBG.visible = false; + add(missingTextBG); + + missingText = new FlxText(50, 0, FlxG.width - 100, '', 24); + missingText.setFormat(Paths.font("vcr.ttf"), 24, FlxColor.WHITE, CENTER, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); + missingText.scrollFactor.set(); + missingText.visible = false; + add(missingText); + if(curSelected >= songs.length) curSelected = 0; bg.color = songs[curSelected].color; intendedColor = bg.color; + lerpSelected = curSelected; - lastDifficultyName = Difficulty.getDefault(); - curDifficulty = Math.round(Math.max(0, Difficulty.defaultList.indexOf(lastDifficultyName))); - changeSelection(); - changeDiff(); - - var swag:funkin.game.objects.Alphabet = new funkin.game.objects.Alphabet(1, 0, "swag"); - - // JUST DOIN THIS SHIT FOR TESTING!!! - /* - var md:String = Markdown.markdownToHtml(Assets.getText('CHANGELOG.md')); - - var texFel:TextField = new TextField(); - texFel.width = FlxG.width; - texFel.height = FlxG.height; - // texFel. - texFel.htmlText = md; - - FlxG.stage.addChild(texFel); - - // scoreText.textField.htmlText = md; - - trace(md); - */ - - var textBG:FlxSprite = new FlxSprite(0, FlxG.height - 26).makeGraphic(FlxG.width, 26, 0xFF000000); - textBG.alpha = 0.6; - add(textBG); + bottomBG = new FlxSprite(0, FlxG.height - 26).makeGraphic(FlxG.width, 26, 0xFF000000); + bottomBG.alpha = 0.6; + add(bottomBG); var leText:String = "Press SPACE to listen to the Song / Press CTRL to open the Gameplay Changers Menu / Press RESET to Reset your Score and Accuracy."; + bottomString = leText; var size:Int = 16; - var text:FlxText = new FlxText(textBG.x, textBG.y + 4, FlxG.width, leText, size); - text.setFormat(Paths.font("vcr.ttf"), size, FlxColor.WHITE, RIGHT); - text.scrollFactor.set(); - add(text); + bottomText = new FlxText(bottomBG.x, bottomBG.y + 4, FlxG.width, leText, size); + bottomText.setFormat(Paths.font("vcr.ttf"), size, FlxColor.WHITE, CENTER); + bottomText.scrollFactor.set(); + add(bottomText); + + player = new MusicPlayer(this); + add(player); + + changeSelection(); + updateTexts(); super.create(); } - override function closeSubState() { + override function closeSubState() + { changeSelection(0, false); persistentUpdate = true; super.closeSubState(); @@ -212,354 +221,406 @@ class FreeplayState extends MusicBeatState public function addSong(songName:String, weekNum:Int, songCharacter:String, color:Int) { - songs.push(new SongMetadata(songName.formatText(), weekNum, songCharacter, color)); + songs.push(new SongMetadata(songName, weekNum, songCharacter, color)); } - function weekIsLocked(name:String):Bool { + function weekIsLocked(name:String):Bool + { var leWeek:WeekData = WeekData.weeksLoaded.get(name); - return (!leWeek.startUnlocked && leWeek.weekBefore.length > 0 && (!funkin.game.states.StoryMenuState.weekCompleted.exists(leWeek.weekBefore) || !funkin.game.states.StoryMenuState.weekCompleted.get(leWeek.weekBefore))); + return (!leWeek.startUnlocked && leWeek.weekBefore.length > 0 && (!StoryMenuState.weekCompleted.exists(leWeek.weekBefore) || !StoryMenuState.weekCompleted.get(leWeek.weekBefore))); } - /*public function addWeek(songs:Array, weekNum:Int, weekColor:Int, ?songCharacters:Array) - { - if (songCharacters == null) - songCharacters = ['bf']; - - var num:Int = 0; - for (song in songs) - { - addSong(song, weekNum, songCharacters[num]); - this.songs[this.songs.length-1].color = weekColor; + public static function destroyFreeplayVocals() { + if(vocals != null) vocals.stop(); + vocals = FlxDestroyUtil.destroy(vocals); - if (songCharacters.length != 1) - num++; - } - }*/ + if(opponentVocals != null) opponentVocals.stop(); + opponentVocals = FlxDestroyUtil.destroy(opponentVocals); + } var instPlaying:Int = -1; public static var vocals:FlxSound = null; + public static var opponentVocals:FlxSound = null; var holdTime:Float = 0; + + var stopMusicPlay:Bool = false; override function update(elapsed:Float) { + if(WeekData.weeksList.length < 1) + return; + if (FlxG.sound.music.volume < 0.7) - { FlxG.sound.music.volume += 0.5 * FlxG.elapsed; - } - lerpScore = Math.floor(FlxMath.lerp(lerpScore, intendedScore, CoolUtil.boundTo(elapsed * 24, 0, 1))); - lerpRating = FlxMath.lerp(lerpRating, intendedRating, CoolUtil.boundTo(elapsed * 12, 0, 1)); + lerpScore = Math.floor(FlxMath.lerp(intendedScore, lerpScore, Math.exp(-elapsed * 24))); + lerpRating = FlxMath.lerp(intendedRating, lerpRating, Math.exp(-elapsed * 12)); if (Math.abs(lerpScore - intendedScore) <= 10) lerpScore = intendedScore; if (Math.abs(lerpRating - intendedRating) <= 0.01) lerpRating = intendedRating; - var ratingSplit:Array = Std.string(Highscore.floorDecimal(lerpRating * 100, 2)).split('.'); - if(ratingSplit.length < 2) { //No decimals, add an empty space + var ratingSplit:Array = Std.string(CoolUtil.floorDecimal(lerpRating * 100, 2)).split('.'); + if(ratingSplit.length < 2) //No decimals, add an empty space ratingSplit.push(''); - } - while(ratingSplit[1].length < 2) { //Less than 2 decimals in it, add decimals then + while(ratingSplit[1].length < 2) //Less than 2 decimals in it, add decimals then ratingSplit[1] += '0'; - } - - scoreText.text = 'PERSONAL BEST: ' + lerpScore + ' (' + ratingSplit.join('.') + '%)'; - positionHighscore(); - - var upP = controls.UI_UP_P; - var downP = controls.UI_DOWN_P; - var accepted = controls.ACCEPT; - var space = FlxG.keys.justPressed.SPACE; - var ctrl = FlxG.keys.justPressed.CONTROL; var shiftMult:Int = 1; if(FlxG.keys.pressed.SHIFT) shiftMult = 3; - if(songs.length > 1) + if (!player.playingMusic) { - if (upP) - { - changeSelection(-shiftMult); - holdTime = 0; - } - if (downP) + scoreText.text = 'PERSONAL BEST: $lerpScore (${ratingSplit.join('.')}%)'; + positionHighscore(); + + if(songs.length > 1) { - changeSelection(shiftMult); - holdTime = 0; - } + if(FlxG.keys.justPressed.HOME) + { + curSelected = 0; + changeSelection(); + holdTime = 0; + } + else if(FlxG.keys.justPressed.END) + { + curSelected = songs.length - 1; + changeSelection(); + holdTime = 0; + } + if (controls.UI_UP_P) + { + changeSelection(-shiftMult); + holdTime = 0; + } + if (controls.UI_DOWN_P) + { + changeSelection(shiftMult); + holdTime = 0; + } - if(controls.UI_DOWN || controls.UI_UP) - { - var checkLastHold:Int = Math.floor((holdTime - 0.5) * 10); - holdTime += elapsed; - var checkNewHold:Int = Math.floor((holdTime - 0.5) * 10); + if(controls.UI_DOWN || controls.UI_UP) + { + var checkLastHold:Int = Math.floor((holdTime - 0.5) * 10); + holdTime += elapsed; + var checkNewHold:Int = Math.floor((holdTime - 0.5) * 10); + + if(holdTime > 0.5 && checkNewHold - checkLastHold > 0) + changeSelection((checkNewHold - checkLastHold) * (controls.UI_UP ? -shiftMult : shiftMult)); + } - if(holdTime > 0.5 && checkNewHold - checkLastHold > 0) + if(FlxG.mouse.wheel != 0) { - changeSelection((checkNewHold - checkLastHold) * (controls.UI_UP ? -shiftMult : shiftMult)); - changeDiff(); + FlxG.sound.play(Paths.sound('scrollMenu'), 0.2); + changeSelection(-shiftMult * FlxG.mouse.wheel, false); } } - if(FlxG.mouse.wheel != 0) + if (controls.UI_LEFT_P) + { + changeDiff(-1); + _updateSongLastDifficulty(); + } + else if (controls.UI_RIGHT_P) { - FlxG.sound.play(Paths.sound('scrollMenu'), 0.2); - changeSelection(-shiftMult * FlxG.mouse.wheel, false); - changeDiff(); + changeDiff(1); + _updateSongLastDifficulty(); } } - if (controls.UI_LEFT_P) - changeDiff(-1); - else if (controls.UI_RIGHT_P) - changeDiff(1); - else if (upP || downP) changeDiff(); - if (controls.BACK) { - persistentUpdate = false; - if(colorTween != null) { - colorTween.cancel(); + if (player.playingMusic) + { + FlxG.sound.music.stop(); + destroyFreeplayVocals(); + FlxG.sound.music.volume = 0; + instPlaying = -1; + + player.playingMusic = false; + player.switchPlayMusic(); + + FlxG.sound.playMusic(Paths.music('freakyMenu'), 0); + FlxTween.tween(FlxG.sound.music, {volume: 1}, 1); + } + else + { + persistentUpdate = false; + FlxG.sound.play(Paths.sound('cancelMenu')); + MusicBeatState.switchState(new MainMenuState()); } - FlxG.sound.play(Paths.sound('cancelMenu')); - MusicBeatState.switchState(new funkin.game.states.MainMenuState()); } - if(ctrl) + if(FlxG.keys.justPressed.CONTROL && !player.playingMusic) { persistentUpdate = false; openSubState(new GameplayChangersSubstate()); } - else if(space) + else if(FlxG.keys.justPressed.SPACE) { - if(instPlaying != curSelected) + if(instPlaying != curSelected && !player.playingMusic) { destroyFreeplayVocals(); FlxG.sound.music.volume = 0; + Mods.currentModDirectory = songs[curSelected].folder; var poop:String = Highscore.formatSong(songs[curSelected].songName.toLowerCase(), curDifficulty); - PlayState.SONG = Song.loadFromJson(poop, songs[curSelected].songName.toLowerCase()); + Song.loadFromJson(poop, songs[curSelected].songName.toLowerCase()); if (PlayState.SONG.needsVoices) - vocals = new FlxSound().loadEmbedded(Paths.voices(PlayState.SONG.song)); - else + { vocals = new FlxSound(); + try + { + var playerVocals:String = getVocalFromCharacter(PlayState.SONG.player1); + var loadedVocals = Paths.voices(PlayState.SONG.song, (playerVocals != null && playerVocals.length > 0) ? playerVocals : 'Player'); + if(loadedVocals == null) loadedVocals = Paths.voices(PlayState.SONG.song); + + if(loadedVocals != null && loadedVocals.length > 0) + { + vocals.loadEmbedded(loadedVocals); + FlxG.sound.list.add(vocals); + vocals.persist = vocals.looped = true; + vocals.volume = 0.8; + vocals.play(); + vocals.pause(); + } + else vocals = FlxDestroyUtil.destroy(vocals); + } + catch(e:Dynamic) + { + vocals = FlxDestroyUtil.destroy(vocals); + } + + opponentVocals = new FlxSound(); + try + { + //trace('please work...'); + var oppVocals:String = getVocalFromCharacter(PlayState.SONG.player2); + var loadedVocals = Paths.voices(PlayState.SONG.song, (oppVocals != null && oppVocals.length > 0) ? oppVocals : 'Opponent'); + + if(loadedVocals != null && loadedVocals.length > 0) + { + opponentVocals.loadEmbedded(loadedVocals); + FlxG.sound.list.add(opponentVocals); + opponentVocals.persist = opponentVocals.looped = true; + opponentVocals.volume = 0.8; + opponentVocals.play(); + opponentVocals.pause(); + //trace('yaaay!!'); + } + else opponentVocals = FlxDestroyUtil.destroy(opponentVocals); + } + catch(e:Dynamic) + { + //trace('FUUUCK'); + opponentVocals = FlxDestroyUtil.destroy(opponentVocals); + } + } - FlxG.sound.list.add(vocals); - FlxG.sound.playMusic(Paths.inst(PlayState.SONG.song), 0.7); - vocals.play(); - vocals.persist = true; - vocals.looped = true; - vocals.volume = 0.7; + FlxG.sound.playMusic(Paths.inst(PlayState.SONG.song), 0.8); + FlxG.sound.music.pause(); instPlaying = curSelected; + + player.playingMusic = true; + player.curTime = 0; + player.switchPlayMusic(); + player.pauseOrResume(true); + } + else if (instPlaying == curSelected && player.playingMusic) + { + player.pauseOrResume(!player.playing); } } - - else if (accepted) + else if (controls.ACCEPT && !player.playingMusic) { persistentUpdate = false; var songLowercase:String = Paths.formatToSongPath(songs[curSelected].songName); var poop:String = Highscore.formatSong(songLowercase, curDifficulty); - /*#if MODS_ALLOWED - if(!sys.FileSystem.exists(Paths.modsJson(songLowercase + '/' + poop)) && !sys.FileSystem.exists(Paths.json(songLowercase + '/' + poop))) { - #else - if(!OpenFlAssets.exists(Paths.json(songLowercase + '/' + poop))) { - #end - poop = songLowercase; - curDifficulty = 1; - trace('Couldnt find file'); - }*/ - trace('Song Name: $poop'); - - PlayState.SONG = Song.loadFromJson(poop, songLowercase); - PlayState.isStoryMode = false; - PlayState.storyDifficulty = curDifficulty; - - trace('Current Week: ' + WeekData.getWeekFileName()); - if(colorTween != null) { - colorTween.cancel(); + + try + { + Song.loadFromJson(poop, songLowercase); + PlayState.isStoryMode = false; + PlayState.storyDifficulty = curDifficulty; + + trace('CURRENT WEEK: ' + WeekData.getWeekFileName()); } - - if (FlxG.keys.pressed.SHIFT){ - LoadingState.loadAndSwitchState(new ChartingState()); - }else{ - LoadingState.prepareToSong(); - LoadingState.loadAndSwitchState(new PlayState()); + catch(e:haxe.Exception) + { + trace('ERROR! ${e.message}'); + + var errorStr:String = e.message; + if(errorStr.contains('There is no TEXT asset with an ID of')) errorStr = 'Missing file: ' + errorStr.substring(errorStr.indexOf(songLowercase), errorStr.length-1); //Missing chart + else errorStr += '\n\n' + e.stack; + + missingText.text = 'ERROR WHILE LOADING CHART:\n$errorStr'; + missingText.screenCenter(Y); + missingText.visible = true; + missingTextBG.visible = true; + FlxG.sound.play(Paths.sound('cancelMenu')); + + updateTexts(elapsed); + super.update(elapsed); + return; } - FlxG.sound.music.volume = 0; - + LoadingState.prepareToSong(); + LoadingState.loadAndSwitchState(new PlayState()); + #if !SHOW_LOADING_SCREEN FlxG.sound.music.stop(); #end + stopMusicPlay = true; + destroyFreeplayVocals(); #if (MODS_ALLOWED && DISCORD_ALLOWED) DiscordClient.loadModRPC(); #end } - else if(controls.RESET) + else if(controls.RESET && !player.playingMusic) { persistentUpdate = false; openSubState(new ResetScoreSubState(songs[curSelected].songName, curDifficulty, songs[curSelected].songCharacter)); - FlxG.sound.play(Paths.sound('scrollMenu')); } + + updateTexts(elapsed); super.update(elapsed); } - - public static function destroyFreeplayVocals() { - if(vocals != null) { - vocals.stop(); - vocals.destroy(); + + + function getVocalFromCharacter(char:String) + { + try + { + var path:String = Paths.getPath('characters/$char.json', TEXT); + #if MODS_ALLOWED + var character:Dynamic = Json.parse(File.getContent(path)); + #else + var character:Dynamic = Json.parse(Assets.getText(path)); + #end + return character.vocals_file; } - vocals = null; + catch (e:Dynamic) {} + return null; } function changeDiff(change:Int = 0) { - curDifficulty += change; - - if (curDifficulty < 0) - curDifficulty = Difficulty.list.length-1; - if (curDifficulty >= Difficulty.list.length) - curDifficulty = 0; - - lastDifficultyName = Difficulty.list[curDifficulty]; + if (player.playingMusic) + return; + curDifficulty = FlxMath.wrap(curDifficulty + change, 0, Difficulty.list.length-1); #if !switch intendedScore = Highscore.getScore(songs[curSelected].songName, curDifficulty); intendedRating = Highscore.getRating(songs[curSelected].songName, curDifficulty); #end - PlayState.storyDifficulty = curDifficulty; + lastDifficultyName = Difficulty.getString(curDifficulty); var displayDiff:String = Difficulty.getString(curDifficulty); if (Difficulty.list.length > 1) diffText.text = '< ' + displayDiff.toUpperCase() + ' >'; else diffText.text = displayDiff.toUpperCase(); - checkHealthIcon(); + positionHighscore(); + missingText.visible = false; + missingTextBG.visible = false; } function changeSelection(change:Int = 0, playSound:Bool = true) { - if(playSound) FlxG.sound.play(Paths.sound('scrollMenu'), 0.4); + if (player.playingMusic) + return; - curSelected += change; + curSelected = FlxMath.wrap(curSelected + change, 0, songs.length-1); + _updateSongLastDifficulty(); + if(playSound) FlxG.sound.play(Paths.sound('scrollMenu'), 0.4); - if (curSelected < 0) - curSelected = songs.length - 1; - if (curSelected >= songs.length) - curSelected = 0; - var newColor:Int = songs[curSelected].color; - if(newColor != intendedColor) { - if(colorTween != null) { - colorTween.cancel(); - } + if(newColor != intendedColor) + { intendedColor = newColor; - colorTween = FlxTween.color(bg, 1, bg.color, intendedColor, { - onComplete: function(twn:FlxTween) { - colorTween = null; - } - }); + FlxTween.cancelTweensOf(bg); + FlxTween.color(bg, 1, bg.color, intendedColor); } - // selector.y = (70 * curSelected) + 30; - - #if !switch - intendedScore = Highscore.getScore(songs[curSelected].songName, curDifficulty); - intendedRating = Highscore.getRating(songs[curSelected].songName, curDifficulty); - #end - - var bullShit:Int = 0; - - checkHealthIcon(); - - FlxG.watch.addQuick('Current Score:', intendedScore); - FlxG.watch.addQuick('Current Rating:', intendedRating); - - for (item in grpSongs.members) + for (num => item in grpSongs.members) { - item.targetY = bullShit - curSelected; - bullShit++; - + var icon:HealthIcon = iconArray[num]; item.alpha = 0.6; - - // item.animation.curAnim.curFrame = 0; - // item.setGraphicSize(Std.int(item.width * 0.8)); - - if (item.targetY == 0) + icon.alpha = 0.6; + if (item.targetY == curSelected) { item.alpha = 1; - // item.setGraphicSize(Std.int(item.width)); + icon.alpha = 1; } } Mods.currentModDirectory = songs[curSelected].folder; PlayState.storyWeek = songs[curSelected].week; Difficulty.loadFromWeek(); - - var diffStr:String = WeekData.getCurrentWeek().difficulties; - if(diffStr != null) diffStr = diffStr.trim(); //Fuck you HTML5 - - if(diffStr != null && diffStr.length > 0) - { - var diffs:Array = diffStr.split(','); - var i:Int = diffs.length - 1; - while (i > 0) - { - if(diffs[i] != null) - { - diffs[i] = diffs[i].trim(); - if(diffs[i].length < 1) diffs.remove(diffs[i]); - } - --i; - } - - if(diffs.length > 0 && diffs[0].length > 0) - { - Difficulty.list = diffs; - } - } - if(Difficulty.list.contains(Difficulty.getDefault())) - { + var savedDiff:String = songs[curSelected].lastDifficulty; + var lastDiff:Int = Difficulty.list.indexOf(lastDifficultyName); + if(savedDiff != null && !Difficulty.list.contains(savedDiff) && Difficulty.list.contains(savedDiff)) + curDifficulty = Math.round(Math.max(0, Difficulty.list.indexOf(savedDiff))); + else if(lastDiff > -1) + curDifficulty = lastDiff; + else if(Difficulty.list.contains(Difficulty.getDefault())) curDifficulty = Math.round(Math.max(0, Difficulty.defaultList.indexOf(Difficulty.getDefault()))); - } else - { curDifficulty = 0; - } - var newPos:Int = Difficulty.list.indexOf(lastDifficultyName); - //trace('Pos of ' + lastDifficultyName + ' is ' + newPos); - if(newPos > -1) - { - curDifficulty = newPos; - } + changeDiff(); + _updateSongLastDifficulty(); } - private function checkHealthIcon() { - for (i in 0...iconArray.length) - { - iconArray[i].alpha = 0.6; - iconArray[i].animation.curAnim.curFrame = 0; - } - iconArray[curSelected].alpha = 1; - - if (intendedScore > 1000) { - iconArray[curSelected].animation.curAnim.curFrame = 1; - iconArray[curSelected].updateHitbox(); - }else - iconArray[curSelected].animation.curAnim.curFrame = 0; - } + inline private function _updateSongLastDifficulty() + songs[curSelected].lastDifficulty = Difficulty.getString(curDifficulty); - private function positionHighscore() { + private function positionHighscore() + { scoreText.x = FlxG.width - scoreText.width - 6; - scoreBG.scale.x = FlxG.width - scoreText.x + 6; scoreBG.x = FlxG.width - (scoreBG.scale.x / 2); diffText.x = Std.int(scoreBG.x + (scoreBG.width / 2)); diffText.x -= diffText.width / 2; } + var _drawDistance:Int = 4; + var _lastVisibles:Array = []; + public function updateTexts(elapsed:Float = 0.0) + { + lerpSelected = FlxMath.lerp(curSelected, lerpSelected, Math.exp(-elapsed * 9.6)); + for (i in _lastVisibles) + { + grpSongs.members[i].visible = grpSongs.members[i].active = false; + iconArray[i].visible = iconArray[i].active = false; + } + _lastVisibles = []; + + var min:Int = Math.round(Math.max(0, Math.min(songs.length, lerpSelected - _drawDistance))); + var max:Int = Math.round(Math.max(0, Math.min(songs.length, lerpSelected + _drawDistance))); + for (i in min...max) + { + var item:Alphabet = grpSongs.members[i]; + item.visible = item.active = true; + item.x = ((item.targetY - lerpSelected) * item.distancePerItem.x) + item.startPosition.x; + item.y = ((item.targetY - lerpSelected) * 1.3 * item.distancePerItem.y) + item.startPosition.y; + + var icon:HealthIcon = iconArray[i]; + icon.visible = icon.active = true; + _lastVisibles.push(i); + } + } + + override function destroy():Void + { + super.destroy(); + + //FlxG.autoPause = ClientPrefs.data.autoPause; + if (!FlxG.sound.music.playing && !stopMusicPlay) + FlxG.sound.playMusic(Paths.music('freakyMenu')); + } } class SongMetadata @@ -569,6 +630,7 @@ class SongMetadata public var songCharacter:String = ""; public var color:Int = -7179779; public var folder:String = ""; + public var lastDifficulty:String = null; public function new(song:String, week:Int, songCharacter:String, color:Int) { diff --git a/source/funkin/game/states/StoryMenuState.hx b/source/funkin/game/states/StoryMenuState.hx index efccb6b2..6b3710af 100644 --- a/source/funkin/game/states/StoryMenuState.hx +++ b/source/funkin/game/states/StoryMenuState.hx @@ -27,11 +27,9 @@ import flixel.util.FlxTimer; import lime.net.curl.CURLCode; import flixel.graphics.FlxGraphic; import funkin.backend.Song; - import funkin.backend.system.MusicBeatSubstate; import funkin.backend.system.MusicBeatState; - class StoryMenuState extends MusicBeatState { public static var weekCompleted:Map = new Map(); @@ -39,6 +37,7 @@ class StoryMenuState extends MusicBeatState var scoreText:FlxText; private static var lastDifficultyName:String = ''; + var curDifficulty:Int = 1; var txtWeekTitle:FlxText; @@ -60,6 +59,8 @@ class StoryMenuState extends MusicBeatState var loadedWeeks:Array = []; + var finishedCheckingState:Bool = false; + override function create() { Paths.clearStoredMemory(); @@ -71,30 +72,30 @@ class StoryMenuState extends MusicBeatState #if DISCORD_ALLOWED // Updating Discord Rich Presence - DiscordClient.changePresence("Story Menu", null); - WindowUtil.setTitle('Story Menu'); + DiscordClient.changePresence("In the Menus", null); #end - if(WeekData.weeksList.length < 1) + if (WeekData.weeksList.length < 1) { FlxTransitionableState.skipNextTransIn = true; persistentUpdate = false; MusicBeatState.switchState(new ErrorState("NO WEEKS ADDED FOR STORY MODE\n\nPress ACCEPT to go to the Week Editor Menu.\nPress BACK to return to Main Menu.", - function() MusicBeatState.switchState(new funkin.game.editors.WeekEditorState()), - function() MusicBeatState.switchState(new MainMenuState()))); + function() MusicBeatState.switchState(new WeekEditorState()), function() MusicBeatState.switchState(new MainMenuState()))); return; } + finishedCheckingState = true; - if(curWeek >= WeekData.weeksList.length) curWeek = 0; + if (curWeek >= WeekData.weeksList.length) + curWeek = 0; - scoreText = new FlxText(10, 10, 0, 'WEEK SCORE: $lerpScore', 36); + scoreText = new FlxText(10, 10, 0, 'WEEK SCORE: $lerpScore'); scoreText.setFormat("VCR OSD Mono", 32); txtWeekTitle = new FlxText(FlxG.width * 0.7, 10, 0, "", 32); txtWeekTitle.setFormat("VCR OSD Mono", 32, FlxColor.WHITE, RIGHT); txtWeekTitle.alpha = 0.7; - var ui_tex = Paths.getSparrowAtlas('storymenu/props/campaign_menu_UI_assets'); + var ui_tex = Paths.getSparrowAtlas('campaign_menu_UI_assets'); var bgYellow:FlxSprite = new FlxSprite(0, 56).makeGraphic(FlxG.width, 386, 0xFFF9CF51); bgSprite = new FlxSprite(0, 56); @@ -115,7 +116,7 @@ class StoryMenuState extends MusicBeatState { var weekFile:WeekData = WeekData.weeksLoaded.get(WeekData.weeksList[i]); var isLocked:Bool = weekIsLocked(WeekData.weeksList[i]); - if(!isLocked || !weekFile.hiddenUntilUnlocked) + if (!isLocked || !weekFile.hiddenUntilUnlocked) { loadedWeeks.push(weekFile); WeekData.setDirectoryFromWeek(weekFile); @@ -165,12 +166,12 @@ class StoryMenuState extends MusicBeatState difficultySelectors.add(leftArrow); Difficulty.resetList(); - if(lastDifficultyName == '') + if (lastDifficultyName == '') { lastDifficultyName = Difficulty.getDefault(); } curDifficulty = Math.round(Math.max(0, Difficulty.defaultList.indexOf(lastDifficultyName))); - + sprDifficulty = new FlxSprite(0, leftArrow.y); sprDifficulty.antialiasing = ClientPrefs.data.antialiasing; difficultySelectors.add(sprDifficulty); @@ -187,9 +188,9 @@ class StoryMenuState extends MusicBeatState add(bgSprite); add(grpWeekCharacters); - var tracksSprite:FlxSprite = new FlxSprite(FlxG.width * 0.07 + 100, bgSprite.y + 425).loadGraphic(Paths.image('storymenu/props/Menu_Tracks')); + var tracksSprite:FlxSprite = new FlxSprite(FlxG.width * 0.07 + 100, bgSprite.y + 425).loadGraphic(Paths.image('Menu_Tracks')); tracksSprite.antialiasing = ClientPrefs.data.antialiasing; - tracksSprite.x -= tracksSprite.width/2; + tracksSprite.x -= tracksSprite.width / 2; add(tracksSprite); txtTracklist = new FlxText(FlxG.width * 0.05, tracksSprite.y + 60, 0, "", 32); @@ -206,7 +207,8 @@ class StoryMenuState extends MusicBeatState super.create(); } - override function closeSubState() { + override function closeSubState() + { persistentUpdate = true; changeWeek(); super.closeSubState(); @@ -214,25 +216,28 @@ class StoryMenuState extends MusicBeatState override function update(elapsed:Float) { - if(grpWeekText.length < 1) - { - if (controls.BACK && !movedBack && !selectedWeek) + if(!finishedCheckingState) return; + if (grpWeekText.length < 1) { - FlxG.sound.play(Paths.sound('cancelMenu')); - movedBack = true; - MusicBeatState.switchState(new MainMenuState()); + if (controls.BACK && !movedBack && !selectedWeek) + { + FlxG.sound.play(Paths.sound('cancelMenu')); + movedBack = true; + MusicBeatState.switchState(new MainMenuState()); + } + super.update(elapsed); + return; } - super.update(elapsed); - return; - } + // scoreText.setFormat('VCR OSD Mono', 32); - if(intendedScore != lerpScore) + if (intendedScore != lerpScore) { lerpScore = Math.floor(FlxMath.lerp(intendedScore, lerpScore, Math.exp(-elapsed * 30))); - if(Math.abs(intendedScore - lerpScore) < 10) lerpScore = intendedScore; - - scoreText.text = 'WEEK SCORE: $lerpScore'; + if (Math.abs(intendedScore - lerpScore) < 10) + lerpScore = intendedScore; + + scoreText.text = 'WEEK SCORE: $lerpScore'; } // FlxG.watch.addQuick('font', scoreText.font); @@ -254,7 +259,7 @@ class StoryMenuState extends MusicBeatState changeDiff = true; } - if(FlxG.mouse.wheel != 0) + if (FlxG.mouse.wheel != 0) { FlxG.sound.play(Paths.sound('scrollMenu'), 0.4); changeWeek(-FlxG.mouse.wheel); @@ -278,16 +283,16 @@ class StoryMenuState extends MusicBeatState else if (changeDiff) changeDifficulty(); - if(FlxG.keys.justPressed.CONTROL) + if (FlxG.keys.justPressed.CONTROL) { persistentUpdate = false; openSubState(new GameplayChangersSubstate()); } - else if(controls.RESET) + else if (controls.RESET) { persistentUpdate = false; openSubState(new ResetScoreSubState('', curDifficulty, '', curWeek)); - //FlxG.sound.play(Paths.sound('scrollMenu')); + // FlxG.sound.play(Paths.sound('scrollMenu')); } else if (controls.ACCEPT) selectWeek(); @@ -301,13 +306,13 @@ class StoryMenuState extends MusicBeatState } super.update(elapsed); - + var offY:Float = grpWeekText.members[curWeek].targetY; for (num => item in grpWeekText.members) item.y = FlxMath.lerp(item.targetY - offY + 480, item.y, Math.exp(-elapsed * 10.2)); for (num => lock in grpLocks.members) - lock.y = grpWeekText.members[lock.ID].y + grpWeekText.members[lock.ID].height/2 - lock.height/2; + lock.y = grpWeekText.members[lock.ID].y + grpWeekText.members[lock.ID].height / 2 - lock.height / 2; } var movedBack:Bool = false; @@ -321,7 +326,8 @@ class StoryMenuState extends MusicBeatState // We can't use Dynamic Array .copy() because that crashes HTML5, here's a workaround. var songArray:Array = []; var leWeek:Array = loadedWeeks[curWeek].songs; - for (i in 0...leWeek.length) { + for (i in 0...leWeek.length) + { songArray.push(leWeek[i][0]); } @@ -331,26 +337,27 @@ class StoryMenuState extends MusicBeatState PlayState.storyPlaylist = songArray; PlayState.isStoryMode = true; selectedWeek = true; - + var diffic = Difficulty.getFilePath(curDifficulty); - if(diffic == null) diffic = ''; - + if (diffic == null) + diffic = ''; + PlayState.storyDifficulty = curDifficulty; - + Song.loadFromJson(PlayState.storyPlaylist[0].toLowerCase() + diffic, PlayState.storyPlaylist[0].toLowerCase()); PlayState.campaignScore = 0; PlayState.campaignMisses = 0; } - catch(e:Dynamic) + catch (e:Dynamic) { trace('ERROR! $e'); return; } - + if (stopspamming == false) { FlxG.sound.play(Paths.sound('confirmMenu')); - + grpWeekText.members[curWeek].isFlashing = true; for (char in grpWeekCharacters.members) { @@ -373,12 +380,13 @@ class StoryMenuState extends MusicBeatState LoadingState.loadAndSwitchState(new PlayState(), true); FreeplayState.destroyFreeplayVocals(); }); - + #if (MODS_ALLOWED && DISCORD_ALLOWED) DiscordClient.loadModRPC(); #end } - else FlxG.sound.play(Paths.sound('cancelMenu')); + else + FlxG.sound.play(Paths.sound('cancelMenu')); } function changeDifficulty(change:Int = 0):Void @@ -386,7 +394,7 @@ class StoryMenuState extends MusicBeatState curDifficulty += change; if (curDifficulty < 0) - curDifficulty = Difficulty.list.length-1; + curDifficulty = Difficulty.list.length - 1; if (curDifficulty >= Difficulty.list.length) curDifficulty = 0; @@ -394,9 +402,9 @@ class StoryMenuState extends MusicBeatState var diff:String = Difficulty.getString(curDifficulty); var newImage:FlxGraphic = Paths.image('menudifficulties/' + Paths.formatToSongPath(diff)); - //trace(Mods.currentModDirectory + ', menudifficulties/' + Paths.formatToSongPath(diff)); + // trace(Mods.currentModDirectory + ', menudifficulties/' + Paths.formatToSongPath(diff)); - if(sprDifficulty.graphic != newImage) + if (sprDifficulty.graphic != newImage) { sprDifficulty.loadGraphic(newImage); sprDifficulty.x = leftArrow.x + 60; @@ -443,9 +451,12 @@ class StoryMenuState extends MusicBeatState bgSprite.visible = true; var assetName:String = leWeek.weekBackground; - if(assetName == null || assetName.length < 1) { + if (assetName == null || assetName.length < 1) + { bgSprite.visible = false; - } else { + } + else + { bgSprite.loadGraphic(Paths.image('menubackgrounds/menu_' + assetName)); } PlayState.storyWeek = curWeek; @@ -453,35 +464,40 @@ class StoryMenuState extends MusicBeatState Difficulty.loadFromWeek(); difficultySelectors.visible = unlocked; - if(Difficulty.list.contains(Difficulty.getDefault())) + if (Difficulty.list.contains(Difficulty.getDefault())) curDifficulty = Math.round(Math.max(0, Difficulty.defaultList.indexOf(Difficulty.getDefault()))); else curDifficulty = 0; var newPos:Int = Difficulty.list.indexOf(lastDifficultyName); - //trace('Pos of ' + lastDifficultyName + ' is ' + newPos); - if(newPos > -1) + // trace('Pos of ' + lastDifficultyName + ' is ' + newPos); + if (newPos > -1) { curDifficulty = newPos; } updateText(); } - function weekIsLocked(name:String):Bool { + function weekIsLocked(name:String):Bool + { var leWeek:WeekData = WeekData.weeksLoaded.get(name); - return (!leWeek.startUnlocked && leWeek.weekBefore.length > 0 && (!weekCompleted.exists(leWeek.weekBefore) || !weekCompleted.get(leWeek.weekBefore))); + return (!leWeek.startUnlocked + && leWeek.weekBefore.length > 0 + && (!weekCompleted.exists(leWeek.weekBefore) || !weekCompleted.get(leWeek.weekBefore))); } function updateText() { var weekArray:Array = loadedWeeks[curWeek].weekCharacters; - for (i in 0...grpWeekCharacters.length) { + for (i in 0...grpWeekCharacters.length) + { grpWeekCharacters.members[i].changeCharacter(weekArray[i]); } var leWeek:WeekData = loadedWeeks[curWeek]; var stringThing:Array = []; - for (i in 0...leWeek.songs.length) { + for (i in 0...leWeek.songs.length) + { stringThing.push(leWeek.songs[i][0]); } @@ -500,4 +516,4 @@ class StoryMenuState extends MusicBeatState intendedScore = Highscore.getWeekScore(loadedWeeks[curWeek].fileName, curDifficulty); #end } -} \ No newline at end of file +} diff --git a/source/funkin/import.hx b/source/funkin/import.hx index 1e9e3422..a3e26f5b 100644 --- a/source/funkin/import.hx +++ b/source/funkin/import.hx @@ -4,6 +4,7 @@ import funkin.game.objects.characters.*; import funkin.game.objects.*; import funkin.game.options.objects.*; import funkin.game.states.*; +import funkin.game.editors.*; import funkin.game.transitions.*; import funkin.game.objects.notes.*; import funkin.game.objects.notes.Note.EventNote;