From e0a132ebaa08af7537059df910ae3148ec439863 Mon Sep 17 00:00:00 2001 From: Yoshman29 <81191621+YoshiCrafter29@users.noreply.github.com> Date: Sun, 4 Dec 2022 18:59:11 +0100 Subject: [PATCH] inis --- assets/music/freakyMenu.ini | 4 ++ assets/music/gameOver.ini | 3 ++ buildnumber.txt | 2 +- source/funkin/game/GameOverSubstate.hx | 53 +++++++++++--------------- source/funkin/game/PlayState.hx | 2 +- source/funkin/system/CoolUtil.hx | 25 +++++++++--- source/funkin/system/IniUtils.hx | 41 ++++++++++++++++++++ 7 files changed, 92 insertions(+), 38 deletions(-) create mode 100644 assets/music/freakyMenu.ini create mode 100644 assets/music/gameOver.ini create mode 100644 source/funkin/system/IniUtils.hx diff --git a/assets/music/freakyMenu.ini b/assets/music/freakyMenu.ini new file mode 100644 index 00000000..2928bc08 --- /dev/null +++ b/assets/music/freakyMenu.ini @@ -0,0 +1,4 @@ +; SONG INFO such as BPM, etc... +; Use CoolUtil.playMusic() instead of FlxG.sound.playMusic() +; for this file to have effect. +BPM = 102 \ No newline at end of file diff --git a/assets/music/gameOver.ini b/assets/music/gameOver.ini new file mode 100644 index 00000000..f7535c61 --- /dev/null +++ b/assets/music/gameOver.ini @@ -0,0 +1,3 @@ +; SONG INFO such as BPM, etc... +; Use CoolUtil.playMusic() instead of FlxG.sound.playMusic() for this file to have effect. +BPM = 102 \ No newline at end of file diff --git a/buildnumber.txt b/buildnumber.txt index a570a3f2..8f5b98b4 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -1374 \ No newline at end of file +1377 \ No newline at end of file diff --git a/source/funkin/game/GameOverSubstate.hx b/source/funkin/game/GameOverSubstate.hx index 93cef62b..c467c04b 100644 --- a/source/funkin/game/GameOverSubstate.hx +++ b/source/funkin/game/GameOverSubstate.hx @@ -1,5 +1,7 @@ package funkin.game; +import flixel.addons.transition.FlxTransitionableState; +import flixel.system.FlxSound; import flixel.FlxG; import flixel.FlxObject; import flixel.FlxSubState; @@ -13,6 +15,8 @@ import funkin.system.Conductor; class GameOverSubstate extends MusicBeatSubstate { var bf:Character; + public var character:String; + public var gameOverSong:String; var camFollow:FlxObject; var stageSuffix:String = ""; @@ -20,43 +24,33 @@ class GameOverSubstate extends MusicBeatSubstate var x:Float = 0; var y:Float = 0; - public function new(x:Float, y:Float) { + public var lossSFX:FlxSound; + + public function new(x:Float, y:Float, character:String = "bf", gameOverSong:String = "gameOver") { super(); this.x = x; this.y = y; + this.character = character; + this.gameOverSong = gameOverSong; } public override function create() { super.create(); - var daStage = PlayState.instance.curStage; - var daBf:String = ''; - switch (daStage) - { - case 'school': - stageSuffix = '-pixel'; - daBf = 'bf-pixel-dead'; - case 'schoolEvil': - stageSuffix = '-pixel'; - daBf = 'bf-pixel-dead'; - default: - daBf = 'bf'; - } + if (FlxG.sound.music != null) + FlxG.sound.music.stop(); - bf = new Character(x, y, daBf, true); + bf = new Character(x, y, character, true); add(bf); camFollow = new FlxObject(bf.getGraphicMidpoint().x, bf.getGraphicMidpoint().y, 1, 1); add(camFollow); + FlxG.camera.target = camFollow; - FlxG.sound.play(Paths.sound('fnf_loss_sfx' + stageSuffix)); + lossSFX = FlxG.sound.play(Paths.sound('fnf_loss_sfx' + stageSuffix)); Conductor.changeBPM(100); - // FlxG.camera.followLerp = 1; - // FlxG.camera.focusOn(FlxPoint.get(FlxG.width / 2, FlxG.height / 2)); - FlxG.camera.scroll.set(); - FlxG.camera.target = null; - + bf.danceOnBeat = false; bf.playAnim('firstDeath'); } @@ -71,7 +65,8 @@ class GameOverSubstate extends MusicBeatSubstate if (controls.BACK) { - FlxG.sound.music.stop(); + if (FlxG.sound.music != null) + FlxG.sound.music.stop(); if (PlayState.isStoryMode) FlxG.switchState(new StoryMenuState()); @@ -79,20 +74,15 @@ class GameOverSubstate extends MusicBeatSubstate FlxG.switchState(new FreeplayState()); } - if (bf.animation.curAnim.name == 'firstDeath' && bf.animation.curAnim.curFrame == 12) - { - FlxG.camera.follow(camFollow, LOCKON, 0.01); - } - - if (bf.animation.curAnim.name == 'firstDeath' && bf.animation.curAnim.finished) - { - FlxG.sound.playMusic(Paths.music('gameOver' + stageSuffix)); - } + if (!lossSFX.playing && (FlxG.sound.music == null || !FlxG.sound.music.playing)) + CoolUtil.playMusic(Paths.music(gameOverSong), 100); } override function beatHit(curBeat:Int) { super.beatHit(curBeat); + if (!lossSFX.playing) + bf.playAnim("deathLoop", DANCE); } var isEnding:Bool = false; @@ -109,6 +99,7 @@ class GameOverSubstate extends MusicBeatSubstate { FlxG.camera.fade(FlxColor.BLACK, 2, false, function() { + FlxTransitionableState.skipNextTransOut = true; FlxG.switchState(new PlayState()); }); }); diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index ce4354a3..3c417c45 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -1015,7 +1015,7 @@ class PlayState extends MusicBeatState vocals.stop(); FlxG.sound.music.stop(); - openSubState(new GameOverSubstate(boyfriend.getScreenPosition().x, boyfriend.getScreenPosition().y)); + openSubState(new GameOverSubstate(boyfriend.x, boyfriend.y)); // FlxG.switchState(new GameOverState(boyfriend.getScreenPosition().x, boyfriend.getScreenPosition().y)); diff --git a/source/funkin/system/CoolUtil.hx b/source/funkin/system/CoolUtil.hx index c8e2ebcf..f24d24c3 100644 --- a/source/funkin/system/CoolUtil.hx +++ b/source/funkin/system/CoolUtil.hx @@ -1,5 +1,6 @@ package funkin.system; +import flixel.system.FlxSoundGroup; import animateatlas.AtlasFrameMaker; import haxe.Json; import funkin.menus.StoryMenuState.WeekData; @@ -138,15 +139,29 @@ class CoolUtil public static function playMenuSong(fadeIn:Bool = false) { if (FlxG.sound.music == null || !FlxG.sound.music.playing) { - Conductor.reset(); - - // TODO: bpm from config - Conductor.changeBPM(102); - FlxG.sound.playMusic(Paths.music('freakyMenu'), fadeIn ? 0 : 1); + playMusic(Paths.music('freakyMenu'), 102, fadeIn ? 0 : 1); if (fadeIn) FlxG.sound.music.fadeIn(4, 0, 0.7); } } + + public static function playMusic(path:String, DefaultBPM:Int = 102, Volume:Int = 1, Looped:Bool = true, ?Group:FlxSoundGroup) { + Conductor.reset(); + FlxG.sound.playMusic(path, Volume, Looped, Group); + + var infoPath = '${Path.withoutExtension(path)}.ini'; + if (Assets.exists(infoPath)) { + var musicInfo = IniUtils.parseAsset(infoPath, [ + "BPM" => Std.string(DefaultBPM) + ]); + var parsedBPM:Null = Std.parseFloat(musicInfo["BPM"]); + if (parsedBPM == null) + Conductor.changeBPM(102); + else + Conductor.changeBPM(parsedBPM); + } else + Conductor.changeBPM(102); + } /** * Plays a specified Menu SFX. * @param menuSFX Menu SFX to play diff --git a/source/funkin/system/IniUtils.hx b/source/funkin/system/IniUtils.hx new file mode 100644 index 00000000..0184a595 --- /dev/null +++ b/source/funkin/system/IniUtils.hx @@ -0,0 +1,41 @@ +package funkin.system; + +import openfl.utils.Assets; + +/** + * DOESNT SUPPORT CATEGORIES YET!! + */ +class IniUtils { + public static inline function parseAsset(assetPath:String, ?defaultVariables:Map) + return parseString(Assets.getText(assetPath), defaultVariables); + + public static function parseString(data:String, ?defaultVariables:Map) { + var trimmed:String; + var splitContent = [for(e in data.split("\n")) if ((trimmed = e.trim()) != "") trimmed]; + + var finalMap:Map = []; + if (defaultVariables != null) + for(k=>e in defaultVariables) + finalMap[k] = e; + + for(line in splitContent) { + // comment + if (line.startsWith(";")) continue; + // categories; not supported yet + if (line.startsWith("[") && line.endsWith("]")) continue; + + var index = line.indexOf("="); + var name = line.substr(0, index).trim(); + var value = line.substr(index+1).trim(); + + if (value.startsWith("\"") && value.endsWith("\"")) + value = value.substr(1, value.length - 2); + + if (value.length == 0 || name.length == 0) + continue; + + finalMap[name] = value; + } + return finalMap; + } +} \ No newline at end of file