diff --git a/source/funkin/backend/scripting/GlobalScript.hx b/source/funkin/backend/scripting/GlobalScript.hx index ecd52be7..887aea76 100644 --- a/source/funkin/backend/scripting/GlobalScript.hx +++ b/source/funkin/backend/scripting/GlobalScript.hx @@ -79,7 +79,8 @@ class GlobalScript { call("update", [FlxG.elapsed]); }); - onModSwitch(#if MOD_SUPPORT ModsFolder.currentModFolder #else null #end); + // Commented this out, because it might be the cause why global runs twice - Neo + //onModSwitch(#if MOD_SUPPORT ModsFolder.currentModFolder #else null #end); } public static function event(name:String, event:T):T { diff --git a/source/funkin/backend/system/Flags.hx b/source/funkin/backend/system/Flags.hx index bfec5e81..56ae3e92 100644 --- a/source/funkin/backend/system/Flags.hx +++ b/source/funkin/backend/system/Flags.hx @@ -1,6 +1,6 @@ package funkin.backend.system; -import lime.utils.AssetLibrary; +import lime.utils.AssetLibrary as LimeAssetLibrary; import lime.utils.AssetType; import flixel.util.FlxColor; @@ -19,7 +19,7 @@ class Flags { public static var COMMIT_HASH:String = GitCommitMacro.commitHash; public static var COMMIT_MESSAGE:String = 'Commit $COMMIT_NUMBER ($COMMIT_HASH)'; - @:lazy public static var TITLE:String = Application.current.meta.get('title'); + @:lazy public static var TITLE:String = Application.current.meta.get('name'); @:lazy public static var VERSION:String = Application.current.meta.get('version'); @:lazy public static var VERSION_MESSAGE:String = 'Codename Engine v$VERSION'; @@ -161,45 +161,64 @@ class Flags { */ @:bypass public static var customFlags:Map = []; - public static function load() { - var flags:Map = []; + public static function loadFromData(flags:Map, data:String) { + var trimmed:String; + var splitContent = [for(e in data.split("\n")) if ((trimmed = e.trim()) != "") trimmed]; - final flagsPath = Paths.getPath("flags.ini"); + for(line in splitContent) { + if(line.startsWith(";")) continue; + if(line.startsWith("#")) continue; + if(line.startsWith("//")) continue; + if(line.length == 0) continue; + if(line.charAt(0) == "[" && line.charAt(line.length-1) == "]") continue; - for(lib in Paths.assetsTree.libraries) { - if(lib.exists(flagsPath, AssetType.TEXT)) { - var data:String = lib.getAsset(flagsPath, AssetType.TEXT); - var trimmed:String; - var splitContent = [for(e in data.split("\n")) if ((trimmed = e.trim()) != "") trimmed]; + var index = line.indexOf("="); + if(index == -1) continue; + var name = line.substr(0, index).trim(); + var value = line.substr(index+1).trim(); - for(line in splitContent) { - if(line.startsWith(";")) continue; - if(line.startsWith("#")) continue; - if(line.startsWith("//")) continue; - if(line.length == 0) continue; - if(line.charAt(0) == "[" && line.charAt(line.length-1) == "]") continue; + var wasQuoted = value.length > 1 && value.charCodeAt(0) == '"'.code && value.charCodeAt(value.length-1) == '"'.code; + if(wasQuoted) value = value.substr(1, value.length - 2); + if((!wasQuoted && value.length == 0) || name.length == 0) + continue; - var index = line.indexOf("="); - if(index == -1) continue; - var name = line.substr(0, index).trim(); - var value = line.substr(index+1).trim(); - - var wasQuoted = value.length > 1 && value.charCodeAt(0) == '"'.code && value.charCodeAt(value.length-1) == '"'.code; - if(wasQuoted) value = value.substr(1, value.length - 2); - if((!wasQuoted && value.length == 0) || name.length == 0) - continue; - - if(!flags.exists(name)) - flags[name] = value; - } - } + if(!flags.exists(name)) + flags[name] = value; } + } + public static function loadFromDatas(files:Array) { + var flags:Map = []; + for(file in files) { + var data:String = Assets.getText(file); + if(data != null) + loadFromData(flags, data); + } + return flags; + } + + public static function parseFlags(flags:Map) { customFlags = []; reset(); for(name=>value in flags) - if(!parse(name, value)) { + if(!parse(name, value)) customFlags.set(name, value); - } + } + + /** + * Loads the flags from the assets. + **/ + public static function load(?libs:Array = null) { + if (libs == null) + libs = Paths.assetsTree.libraries; + final flagsPath = Paths.getPath("flags.ini"); + var datas:Array = [ + for(lib in libs) + if(lib.exists(flagsPath, AssetType.TEXT)) + lib.getAsset(flagsPath, AssetType.TEXT) + ]; + + var flags:Map = loadFromDatas(datas); + parseFlags(flags); } } \ No newline at end of file diff --git a/source/funkin/backend/system/macros/FlagMacro.macro.hx b/source/funkin/backend/system/macros/FlagMacro.macro.hx index b1e6b68d..622bada9 100644 --- a/source/funkin/backend/system/macros/FlagMacro.macro.hx +++ b/source/funkin/backend/system/macros/FlagMacro.macro.hx @@ -92,10 +92,7 @@ class FlagMacro { case macro: Array: parser = macro value.split(",").map((e) -> Std.parseFloat(e)); case macro: Array: - parser = macro value.split(",").map((e) -> { - e = e.trim(); - e == "true" || e == "t" || e == "1"; - }); + parser = macro value.split(",").map(parseBool); case macro: TrimmedString: field.kind = FVar(macro: String, expr); parser = macro value.trim(); @@ -106,7 +103,7 @@ class FlagMacro { case macro: Float: parser = macro Std.parseFloat(value); case macro: Bool: - parser = macro value == "true" || value == "t" || value == "1"; + parser = macro parseBool(value); case TPath({name: "Allow", pack: [], params: params}): final NONE = 0; final STRING = 1; @@ -276,6 +273,22 @@ class FlagMacro { meta: [] }); + fields.push({ + name: "parseBool", + access: [APrivate, AStatic], + kind: FFun({ + args: [{name: "e", type: macro: String}], + expr: macro { + e = e.trim(); + return e == "true" || e == "t" || e == "1"; + }, + ret: macro: Bool + }), + pos: Context.currentPos(), + doc: null, + meta: [] + }); + //var printer = new haxe.macro.Printer(); //for(field in fields) { // trace(printer.printField(field)); diff --git a/source/funkin/backend/utils/WindowUtils.hx b/source/funkin/backend/utils/WindowUtils.hx index c88b0d38..3a9f39ce 100644 --- a/source/funkin/backend/utils/WindowUtils.hx +++ b/source/funkin/backend/utils/WindowUtils.hx @@ -45,7 +45,7 @@ class WindowUtils { * Resets the window title to the application name and resets the prefix and suffix. **/ public static inline function resetTitle() { - title = Flags.TITLE; + title = Flags.TITLE == null ? Lib.application.meta.get('name') : Flags.TITLE; resetAffixes(); } @@ -65,18 +65,18 @@ class WindowUtils { // backwards compat @:noCompletion public static var endfix(get, set):String; - @:noCompletion private static function set_endfix(value:String):String { + @:noCompletion private inline static function set_endfix(value:String):String { return suffix = value; } - @:noCompletion private static function get_endfix():String { + @:noCompletion private inline static function get_endfix():String { return suffix; } @:noCompletion public static var winTitle(get, set):String; - @:noCompletion private static function get_winTitle():String { + @:noCompletion private inline static function get_winTitle():String { return title; } - @:noCompletion private static function set_winTitle(value:String):String { + @:noCompletion private inline static function set_winTitle(value:String):String { return title = value; } } \ No newline at end of file