This commit is contained in:
Yoshman29
2022-12-04 18:59:11 +01:00
parent 6980e5720a
commit e0a132ebaa
7 changed files with 92 additions and 38 deletions
+20 -5
View File
@@ -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<Float> = 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
+41
View File
@@ -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<String, String>)
return parseString(Assets.getText(assetPath), defaultVariables);
public static function parseString(data:String, ?defaultVariables:Map<String, String>) {
var trimmed:String;
var splitContent = [for(e in data.split("\n")) if ((trimmed = e.trim()) != "") trimmed];
var finalMap:Map<String, String> = [];
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;
}
}