From 3e5dc6f79faf3e24700891ce200b65d35c3908f3 Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Wed, 28 Aug 2024 12:06:47 +0200 Subject: [PATCH 01/15] Fix bug with looping with atlases --- source/funkin/backend/FunkinSprite.hx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/funkin/backend/FunkinSprite.hx b/source/funkin/backend/FunkinSprite.hx index 6a634e1a..0d59650d 100644 --- a/source/funkin/backend/FunkinSprite.hx +++ b/source/funkin/backend/FunkinSprite.hx @@ -94,16 +94,15 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I public override function update(elapsed:Float) { super.update(elapsed); + if (animateAtlas != null) + animateAtlas.update(elapsed); // hate how it looks like but hey at least its optimized and fast - Nex if (!debugMode && isAnimFinished()) { var name = getAnimName() + '-loop'; - if (animation.exists(name)) + if (hasAnimation(name)) playAnim(name, false, lastAnimContext); } - - if (animateAtlas != null) - animateAtlas.update(elapsed); } public function loadSprite(path:String, Unique:Bool = false, Key:String = null) From e749a0e7e32c336b4e3b5f32a8a09be2cfb8693e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=8B=E3=82=B3=E3=83=A9=E3=82=B9=E2=98=85?= <61890175+Nikorasu-d@users.noreply.github.com> Date: Sat, 31 Aug 2024 12:46:51 -0400 Subject: [PATCH 02/15] Added optional Extra Data support to ModState/ModSubState (#374) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added Optional JSON Data to ModStates/ModSubState * Formatting fixes * Wanted changes * small little comment * Enhanced Comments * Duplicated null * Undo delete null setter - sorry * some changes Co-Authored-By: Ne_Eo * merp --------- Co-authored-by: Ne_Eo Co-authored-by: ⍚~Nex <87421482+NexIsDumb@users.noreply.github.com> --- source/funkin/backend/scripting/ModState.hx | 34 +++++++++++++++++-- .../funkin/backend/scripting/ModSubState.hx | 34 +++++++++++++++++-- 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/source/funkin/backend/scripting/ModState.hx b/source/funkin/backend/scripting/ModState.hx index adc0a42c..94a6ac7b 100644 --- a/source/funkin/backend/scripting/ModState.hx +++ b/source/funkin/backend/scripting/ModState.hx @@ -1,10 +1,38 @@ package funkin.backend.scripting; class ModState extends MusicBeatState { + + /** + * Name of HScript file in assets/data/states. + */ public static var lastName:String = null; - public function new(stateName:String) { - if (stateName != null) - lastName = stateName; + /** + * Last Optional extra data. + */ + public static var lastData:Dynamic = null; + + /** + * Optional extra data. + */ + public var data:Dynamic = null; + + /** + * ModState Constructor. + * Inherits from MusicBeatState and allows the execution of an HScript from assets/data/states passed via parameters. + * + * @param _stateName Name or path to a HScript file from assets/data/states. + * @param _data Optional extra Dynamic data passed from a previous state (JSON suggested). + */ + public function new(_stateName:String, ?_data:Dynamic) { + if(_stateName != null && _stateName != lastName) { + lastName = _stateName; + lastData = null; + } + + if(_data != null) + lastData = _data; + + data = lastData; super(true, lastName); } } \ No newline at end of file diff --git a/source/funkin/backend/scripting/ModSubState.hx b/source/funkin/backend/scripting/ModSubState.hx index 5f06072c..acd90f62 100644 --- a/source/funkin/backend/scripting/ModSubState.hx +++ b/source/funkin/backend/scripting/ModSubState.hx @@ -1,10 +1,38 @@ package funkin.backend.scripting; class ModSubState extends MusicBeatSubstate { + + /** + * Name of HScript file in assets/data/states. + */ public static var lastName:String = null; - public function new(stateName:String) { - if (stateName != null) - lastName = stateName; + /** + * Last Optional extra data. + */ + public static var lastData:Dynamic = null; + + /** + * Optional extra data. + */ + public var data:Dynamic = null; + + /** + * ModSubState Constructor. + * Inherits from MusicBeatSubstate and allows the execution of an HScript from assets/data/states passed via parameters. + * + * @param _stateName Name or path to a HScript file from assets/data/states. + * @param _data Optional extra Dynamic data passed from a previous state (JSON suggested). + */ + public function new(_stateName:String, ?_data:Dynamic) { + if(_stateName != null && _stateName != lastName) { + lastName = _stateName; + lastData = null; + } + + if(_data != null) + lastData = _data; + + data = lastData; super(true, lastName); } } \ No newline at end of file From f8d1cf08ad9f6cdda4e971a3d8adff6fce5130d2 Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Sun, 1 Sep 2024 02:31:51 +0200 Subject: [PATCH 03/15] Added runtime feature flags --- .../funkin/backend/scripting/EventManager.hx | 5 +- source/funkin/backend/system/Flags.hx | 73 ++++++++++ source/funkin/backend/system/MainState.hx | 5 + .../system/framerate/CodenameBuildField.hx | 7 +- .../backend/system/framerate/Framerate.hx | 10 ++ .../system/framerate/FramerateCategory.hx | 2 + .../system/framerate/FramerateCounter.hx | 2 + .../backend/system/framerate/MemoryCounter.hx | 2 + .../backend/system/macros/FlagMacro.macro.hx | 125 ++++++++++++++++++ source/funkin/backend/utils/IniUtil.hx | 2 +- 10 files changed, 229 insertions(+), 4 deletions(-) create mode 100644 source/funkin/backend/system/Flags.hx create mode 100644 source/funkin/backend/system/macros/FlagMacro.macro.hx diff --git a/source/funkin/backend/scripting/EventManager.hx b/source/funkin/backend/scripting/EventManager.hx index 84e7d33f..ab47bb5d 100644 --- a/source/funkin/backend/scripting/EventManager.hx +++ b/source/funkin/backend/scripting/EventManager.hx @@ -14,8 +14,9 @@ class EventManager { var index = eventKeys.indexOf(c); if (index < 0) { eventKeys.push(c); - eventValues.push(Type.createInstance(c, [])); - return cast eventValues.last(); + var ret; + eventValues.push(ret = Type.createInstance(c, [])); + return cast ret; } return cast eventValues[index]; diff --git a/source/funkin/backend/system/Flags.hx b/source/funkin/backend/system/Flags.hx new file mode 100644 index 00000000..2311ed1f --- /dev/null +++ b/source/funkin/backend/system/Flags.hx @@ -0,0 +1,73 @@ +package funkin.backend.system; + +import lime.utils.AssetLibrary; +import lime.utils.AssetType; + +import funkin.backend.assets.IModsAssetLibrary; +import funkin.backend.assets.ScriptedAssetLibrary; + +@:build(funkin.backend.system.macros.FlagMacro.build()) +class Flags { + public static var FPS_BUILD_TEXT:String = "Commit ${build} (${commit})"; + + @:bypass public static var customFlags:Map = []; + + public static function load() { + var flags:Map = []; + + final flagsPath = Paths.getPath("flags.ini"); + + 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]; + + 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 index = line.indexOf("="); + if(index == -1) continue; + var name = line.substr(0, index).trim(); + var value = line.substr(index+1).trim(); + + if (value.length > 1 && value.charCodeAt(0) == '"'.code && value.charCodeAt(value.length-1) == '"'.code) + value = value.substr(1, value.length - 2); + + if (value.length == 0 || name.length == 0) + continue; + + if(!flags.exists(name)) + flags[name] = value; + } + } + } + + customFlags = []; + reset(); + for(name=>value in flags) + if(!parse(name, value)) { + customFlags.set(name, value); + } + } + + public static function getCleanLibraryName(e:AssetLibrary) { + var l = e; + if (l is openfl.utils.AssetLibrary) { + var al = cast(l, openfl.utils.AssetLibrary); + @:privateAccess + if (al.__proxy != null) l = al.__proxy; + } + + if (l is ScriptedAssetLibrary) + return '${cast(l, ScriptedAssetLibrary).scriptName} (${cast(l, ScriptedAssetLibrary).modName})'; + else if (l is IModsAssetLibrary) + return '${cast(l, IModsAssetLibrary).modName}'; + else + return Std.string(e); + } +} \ No newline at end of file diff --git a/source/funkin/backend/system/MainState.hx b/source/funkin/backend/system/MainState.hx index adc5ae00..0869fc45 100644 --- a/source/funkin/backend/system/MainState.hx +++ b/source/funkin/backend/system/MainState.hx @@ -8,6 +8,7 @@ import funkin.backend.assets.ModsFolder; import funkin.backend.chart.EventsData; import funkin.menus.BetaWarningState; import funkin.menus.TitleState; +import funkin.backend.system.framerate.Framerate; /** * Simple state used for loading the game @@ -55,10 +56,14 @@ class MainState extends FlxState { Main.refreshAssets(); ModsFolder.onModSwitch.dispatch(ModsFolder.currentModFolder); + Flags.load(); DiscordUtil.init(); EventsData.reloadEvents(); TitleState.initialized = false; + if(Framerate.isLoaded) + Framerate.instance.reload(); + if (betaWarningShown) FlxG.switchState(new TitleState()); else { diff --git a/source/funkin/backend/system/framerate/CodenameBuildField.hx b/source/funkin/backend/system/framerate/CodenameBuildField.hx index 3175a01e..092fc736 100644 --- a/source/funkin/backend/system/framerate/CodenameBuildField.hx +++ b/source/funkin/backend/system/framerate/CodenameBuildField.hx @@ -9,6 +9,11 @@ class CodenameBuildField extends TextField { defaultTextFormat = Framerate.textFormat; autoSize = LEFT; multiline = wordWrap = false; - text = 'Codename Engine ${Main.releaseCycle}\nCommit ${GitCommitMacro.commitNumber} (${GitCommitMacro.commitHash})'; + reload(); + } + + public function reload() { + var buildText = Flags.FPS_BUILD_TEXT.replace("${build}", Std.string(GitCommitMacro.commitNumber)).replace("${commit}", GitCommitMacro.commitHash); + text = 'Codename Engine ${Main.releaseCycle}\n' + buildText; } } diff --git a/source/funkin/backend/system/framerate/Framerate.hx b/source/funkin/backend/system/framerate/Framerate.hx index 8faa09ee..c321b1db 100644 --- a/source/funkin/backend/system/framerate/Framerate.hx +++ b/source/funkin/backend/system/framerate/Framerate.hx @@ -82,6 +82,16 @@ class Framerate extends Sprite { #end } + public function reload() { + for(c in categories) + c.reload(); + #if SHOW_BUILD_ON_FPS + codenameBuildField.reload(); + #end + memoryCounter.reload(); + fpsCounter.reload(); + } + private function __addCategory(category:FramerateCategory) { categories.push(category); __addToList(category); diff --git a/source/funkin/backend/system/framerate/FramerateCategory.hx b/source/funkin/backend/system/framerate/FramerateCategory.hx index f1125eb4..a862505c 100644 --- a/source/funkin/backend/system/framerate/FramerateCategory.hx +++ b/source/funkin/backend/system/framerate/FramerateCategory.hx @@ -39,6 +39,8 @@ class FramerateCategory extends Sprite { this.text.y = this.title.y + this.title.height + 2; } + public function reload() {} + public override function __enterFrame(t:Int) { if (alpha <= 0.05) return; super.__enterFrame(t); diff --git a/source/funkin/backend/system/framerate/FramerateCounter.hx b/source/funkin/backend/system/framerate/FramerateCounter.hx index e07a2e02..5658bd2b 100644 --- a/source/funkin/backend/system/framerate/FramerateCounter.hx +++ b/source/funkin/backend/system/framerate/FramerateCounter.hx @@ -37,6 +37,8 @@ class FramerateCounter extends Sprite { } } + public function reload() {} + public override function __enterFrame(t:Int) { if (alpha <= 0.05) return; super.__enterFrame(t); diff --git a/source/funkin/backend/system/framerate/MemoryCounter.hx b/source/funkin/backend/system/framerate/MemoryCounter.hx index 33efff59..f38de1d8 100644 --- a/source/funkin/backend/system/framerate/MemoryCounter.hx +++ b/source/funkin/backend/system/framerate/MemoryCounter.hx @@ -29,6 +29,8 @@ class MemoryCounter extends Sprite { memoryPeakText.alpha = 0.5; } + public function reload() {} + public override function __enterFrame(t:Int) { if (alpha <= 0.05) return; super.__enterFrame(t); diff --git a/source/funkin/backend/system/macros/FlagMacro.macro.hx b/source/funkin/backend/system/macros/FlagMacro.macro.hx new file mode 100644 index 00000000..21ff7acf --- /dev/null +++ b/source/funkin/backend/system/macros/FlagMacro.macro.hx @@ -0,0 +1,125 @@ +package funkin.backend.system.macros; + +import haxe.macro.Context; +import haxe.macro.Expr; + +using StringTools; + +using haxe.macro.Tools; + +class FlagMacro { + public static function build():Array { + var fields = Context.getBuildFields(); + + var clRef = Context.getLocalClass(); + if (clRef == null) + return fields; + + var cl = clRef.get(); + + var resetExprs:Array = []; + var parserExprs:Array = []; + + for (field in fields) { + var skip = false; + for(meta in field.meta) { + if(meta.name == ":bypass") { + skip = true; + break; + } + } + + if(skip) continue; + + switch (field.kind) { + case FVar(type, expr): + if(expr == null) + Context.error('Flags must be initialized', field.pos); + switch(expr.expr) { + case EConst(CIdent("true")) | EConst(CIdent("false")): + type = macro: Bool; + default: + if(type == null) + Context.error('Flags must have a type', field.pos); + } + + var parser:Expr = null; + + switch(type) { + case macro: Array: + field.kind = FVar(macro: Array, macro expr); + parser = macro value.split(",").map((e) -> e.trim()); + case macro: Array: + parser = macro value.split(","); + case macro: Array: + parser = macro value.split(",").map((e) -> { + e = e.trim(); + e == "true" || e == "t" || e == "1"; + }); + case macro: Int: + parser = macro Std.parseInt(value); + case macro: String: + parser = macro value; + case macro: Bool: + parser = macro value == "true" || value == "t" || value == "1"; + + case TPath({name: "Array", pack: []}): + Context.error('Flags cannot be an Array that isnt a String or Bool or TrimmedString', field.pos); + case TPath({name: "Map", pack: []}): + Context.error('Flags cannot be a Map', field.pos); + default: + Context.error("Flags must be either a Bool, Int, String, Array, Array or Array", field.pos); + } + + if(parser == null) { + Context.error("Flags must be either a Bool, Int, String, Array, Array or Array", field.pos); + continue; + } + + resetExprs.push(macro $i{field.name} = ${expr}); + + // parse(name: String, value: String) + parserExprs.push(macro @:mergeBlock { + if(name == $v{field.name}) { + $i{field.name} = $parser; + return true; + } + }); + default: + // nothing + } + } + + fields.push({ + name: "reset", + access: [APublic, AStatic], + kind: FFun({ + args: [], + expr: macro $b{resetExprs}, + ret: macro: Void + }), + pos: Context.currentPos(), + doc: null, + meta: [] + }); + + fields.push({ + name: "parse", + access: [APublic, AStatic], + kind: FFun({ + args: [{name: "name", type: macro: String}, {name: "value", type: macro: String}], + expr: macro { + @:mergeBlock $b{parserExprs}; + + return false; + }, + ret: macro: Bool + }), + pos: Context.currentPos(), + doc: null, + meta: [] + }); + + return fields; + } +} \ No newline at end of file diff --git a/source/funkin/backend/utils/IniUtil.hx b/source/funkin/backend/utils/IniUtil.hx index d7b5738e..e39d0a23 100644 --- a/source/funkin/backend/utils/IniUtil.hx +++ b/source/funkin/backend/utils/IniUtil.hx @@ -26,7 +26,7 @@ class IniUtil { var name = line.substr(0, index).trim(); var value = line.substr(index+1).trim(); - if (value.startsWith("\"") && value.endsWith("\"")) + if (value.length > 1 && value.charCodeAt(0) == '"'.code && value.charCodeAt(value.length-1) == '"'.code) value = value.substr(1, value.length - 2); if (value.length == 0 || name.length == 0) From abb4cd342791a10c5eb46768e638a761897b6208 Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Sun, 1 Sep 2024 03:28:32 +0200 Subject: [PATCH 04/15] Added Allow<> type --- source/funkin/backend/system/Flags.hx | 2 + .../backend/system/macros/FlagMacro.macro.hx | 85 +++++++++++++++++-- 2 files changed, 80 insertions(+), 7 deletions(-) diff --git a/source/funkin/backend/system/Flags.hx b/source/funkin/backend/system/Flags.hx index 2311ed1f..61422401 100644 --- a/source/funkin/backend/system/Flags.hx +++ b/source/funkin/backend/system/Flags.hx @@ -10,6 +10,8 @@ import funkin.backend.assets.ScriptedAssetLibrary; class Flags { public static var FPS_BUILD_TEXT:String = "Commit ${build} (${commit})"; + // Internal stuff + @:bypass public static var customFlags:Map = []; public static function load() { diff --git a/source/funkin/backend/system/macros/FlagMacro.macro.hx b/source/funkin/backend/system/macros/FlagMacro.macro.hx index 21ff7acf..b1093bd9 100644 --- a/source/funkin/backend/system/macros/FlagMacro.macro.hx +++ b/source/funkin/backend/system/macros/FlagMacro.macro.hx @@ -44,10 +44,11 @@ class FlagMacro { } var parser:Expr = null; + var customCheck:Expr = null; switch(type) { case macro: Array: - field.kind = FVar(macro: Array, macro expr); + field.kind = FVar(macro: Array, expr); parser = macro value.split(",").map((e) -> e.trim()); case macro: Array: parser = macro value.split(","); @@ -62,6 +63,67 @@ class FlagMacro { parser = macro value; case macro: Bool: parser = macro value == "true" || value == "t" || value == "1"; + case TPath({name: "Allow", pack: [], params: params}): + final NONE = 0; + final STRING = 1; + final INT = 2; + var chosenType = NONE; + + var values:Array = []; + + for(param in params) { + switch(param) { + case TPExpr(e): + switch(e.expr) { + case EConst(CString(s, kind)): + if(chosenType != NONE && chosenType != STRING) + Context.error("Flags Allow<> can only have one type", field.pos); + chosenType = STRING; + + values.push(s); + case EConst(CInt(num)): + if(chosenType != NONE && chosenType != INT) + Context.error("Flags Allow<> can only have one type", field.pos); + chosenType = INT; + + values.push(num); + default: + Context.error("Flags Allow<> unknown type", field.pos); + } + default: + Context.error("Flags must be either a Bool, Int, String, Array, Array or Array", field.pos); + } + } + + if(chosenType == NONE) + Context.error("Flags Allow<> must have a type", field.pos); + + var errorMessage = 'Flags ${field.name} must be one of ${values.join(", ")}'; + + var checkExpr = macro value == $v{values.shift()}; + for(v in values) + checkExpr = macro $checkExpr || value == $v{v}; + + if(chosenType == STRING) { + parser = macro value; + field.kind = FVar(macro: String, expr); + } + else if(chosenType == INT) { + parser = macro Std.parseInt(value); + field.kind = FVar(macro: Int, expr); + } else { + field.kind = FVar(macro: Any, expr); + } + + customCheck = macro @:mergeBlock { + if(name == $v{field.name}) { + if($checkExpr) + $i{field.name} = $parser; + else + throw $v{errorMessage}; + return true; + } + } case TPath({name: "Array", pack: []}): Context.error('Flags cannot be an Array that isnt a String or Bool or TrimmedString', field.pos); @@ -79,12 +141,17 @@ class FlagMacro { resetExprs.push(macro $i{field.name} = ${expr}); // parse(name: String, value: String) - parserExprs.push(macro @:mergeBlock { - if(name == $v{field.name}) { - $i{field.name} = $parser; - return true; - } - }); + + if(customCheck != null) { + parserExprs.push(customCheck); + } else { + parserExprs.push(macro @:mergeBlock { + if(name == $v{field.name}) { + $i{field.name} = $parser; + return true; + } + }); + } default: // nothing } @@ -120,6 +187,10 @@ class FlagMacro { meta: [] }); + //var printer = new haxe.macro.Printer(); + //trace(printer.printField(fields[fields.length - 2])); + //trace(printer.printField(fields[fields.length - 1])); + return fields; } } \ No newline at end of file From 67e9e8e22d9a558aaa405cc32706becb57dbe1d3 Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Sun, 1 Sep 2024 03:32:17 +0200 Subject: [PATCH 05/15] Small safety checking --- .../backend/system/macros/FlagMacro.macro.hx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source/funkin/backend/system/macros/FlagMacro.macro.hx b/source/funkin/backend/system/macros/FlagMacro.macro.hx index b1093bd9..607e6e53 100644 --- a/source/funkin/backend/system/macros/FlagMacro.macro.hx +++ b/source/funkin/backend/system/macros/FlagMacro.macro.hx @@ -95,6 +95,21 @@ class FlagMacro { } } + var didFind = false; + for(v in values) { + switch(expr.expr) { + case EConst(CString(s, kind)): + if(v == s) + didFind = true; + case EConst(CInt(num)): + if(v == num) + didFind = true; + default: + } + } + if(!didFind) + Context.error("Flags Allow<> must have a default value that is allowed, " + expr.toString() + " is not allowed", field.pos); + if(chosenType == NONE) Context.error("Flags Allow<> must have a type", field.pos); From 807206e7680d554e3f51844ca0e6545f2805b368 Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Sun, 1 Sep 2024 03:39:57 +0200 Subject: [PATCH 06/15] Fixed grammar --- .../backend/system/macros/FlagMacro.macro.hx | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/source/funkin/backend/system/macros/FlagMacro.macro.hx b/source/funkin/backend/system/macros/FlagMacro.macro.hx index 607e6e53..477512c0 100644 --- a/source/funkin/backend/system/macros/FlagMacro.macro.hx +++ b/source/funkin/backend/system/macros/FlagMacro.macro.hx @@ -34,13 +34,13 @@ class FlagMacro { switch (field.kind) { case FVar(type, expr): if(expr == null) - Context.error('Flags must be initialized', field.pos); + Context.error('Flag ' + field.name + ' must have a default value', field.pos); switch(expr.expr) { case EConst(CIdent("true")) | EConst(CIdent("false")): type = macro: Bool; default: if(type == null) - Context.error('Flags must have a type', field.pos); + Context.error('Flag ' + field.name + ' must have a type', field.pos); } var parser:Expr = null; @@ -77,21 +77,21 @@ class FlagMacro { switch(e.expr) { case EConst(CString(s, kind)): if(chosenType != NONE && chosenType != STRING) - Context.error("Flags Allow<> can only have one type", field.pos); + Context.error("Flag " + field.name + " Allow<> can only have one type", field.pos); chosenType = STRING; values.push(s); case EConst(CInt(num)): if(chosenType != NONE && chosenType != INT) - Context.error("Flags Allow<> can only have one type", field.pos); + Context.error("Flag " + field.name + " Allow<> can only have one type", field.pos); chosenType = INT; values.push(num); default: - Context.error("Flags Allow<> unknown type", field.pos); + Context.error("Flag " + field.name + " Allow<> unknown type", field.pos); } default: - Context.error("Flags must be either a Bool, Int, String, Array, Array or Array", field.pos); + Context.error("Flag " + field.name + " Unknown type when using Allow<>", field.pos); } } @@ -108,12 +108,12 @@ class FlagMacro { } } if(!didFind) - Context.error("Flags Allow<> must have a default value that is allowed, " + expr.toString() + " is not allowed", field.pos); + Context.error("Flag " + field.name + "'s Allow<> must have a default value that is allowed, " + expr.toString() + " is not allowed", field.pos); if(chosenType == NONE) - Context.error("Flags Allow<> must have a type", field.pos); + Context.error("Flag " + field.name + "'s Allow<> must have atleast one value", field.pos); - var errorMessage = 'Flags ${field.name} must be one of ${values.join(", ")}'; + var errorMessage = 'Flag ${field.name} must be one of ${values.join(", ")}'; var checkExpr = macro value == $v{values.shift()}; for(v in values) @@ -141,15 +141,15 @@ class FlagMacro { } case TPath({name: "Array", pack: []}): - Context.error('Flags cannot be an Array that isnt a String or Bool or TrimmedString', field.pos); + Context.error("Flag " + field.name + " cannot be an Array that isnt a String or Bool or TrimmedString", field.pos); case TPath({name: "Map", pack: []}): - Context.error('Flags cannot be a Map', field.pos); + Context.error("Flag " + field.name + " cannot be a Map", field.pos); default: - Context.error("Flags must be either a Bool, Int, String, Array, Array or Array", field.pos); + Context.error("Flag " + field.name + " must be either a Bool, Int, String, Array, Array or Array", field.pos); } if(parser == null) { - Context.error("Flags must be either a Bool, Int, String, Array, Array or Array", field.pos); + Context.error("Flag " + field.name + " must be either a Bool, Int, String, Array, Array or Array", field.pos); continue; } From cb1d6fcacf4ad0e2888ed7e76d16a6f85c09b021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=8D=9A=7ENex?= <87421482+NexIsDumb@users.noreply.github.com> Date: Sun, 1 Sep 2024 03:47:41 +0200 Subject: [PATCH 07/15] songs/weeks list modes flags --- source/funkin/backend/system/Flags.hx | 6 +++++- .../backend/system/framerate/CodenameBuildField.hx | 6 ++---- source/funkin/import.hx | 2 ++ source/funkin/menus/FreeplayState.hx | 13 +++++++++++-- source/funkin/menus/StoryMenuState.hx | 14 ++++++++++++-- 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/source/funkin/backend/system/Flags.hx b/source/funkin/backend/system/Flags.hx index 61422401..804da965 100644 --- a/source/funkin/backend/system/Flags.hx +++ b/source/funkin/backend/system/Flags.hx @@ -6,9 +6,13 @@ import lime.utils.AssetType; import funkin.backend.assets.IModsAssetLibrary; import funkin.backend.assets.ScriptedAssetLibrary; +/** + * A class that reads the `flags.ini` file, allowing to read settable Flags (customs too). + */ @:build(funkin.backend.system.macros.FlagMacro.build()) class Flags { - public static var FPS_BUILD_TEXT:String = "Commit ${build} (${commit})"; + public static var SONGS_LIST_MOD_MODE:Allow<"prepend", "override", "append"> = "override"; + public static var WEEKS_LIST_MOD_MODE:Allow<"prepend", "override", "append"> = "override"; // Internal stuff diff --git a/source/funkin/backend/system/framerate/CodenameBuildField.hx b/source/funkin/backend/system/framerate/CodenameBuildField.hx index 092fc736..5519f4d8 100644 --- a/source/funkin/backend/system/framerate/CodenameBuildField.hx +++ b/source/funkin/backend/system/framerate/CodenameBuildField.hx @@ -12,8 +12,6 @@ class CodenameBuildField extends TextField { reload(); } - public function reload() { - var buildText = Flags.FPS_BUILD_TEXT.replace("${build}", Std.string(GitCommitMacro.commitNumber)).replace("${commit}", GitCommitMacro.commitHash); - text = 'Codename Engine ${Main.releaseCycle}\n' + buildText; - } + public function reload() + text = 'Codename Engine ${Main.releaseCycle}\nCommit ${GitCommitMacro.commitNumber} (${GitCommitMacro.commitHash})'; } diff --git a/source/funkin/import.hx b/source/funkin/import.hx index eca238fd..88a2efdb 100644 --- a/source/funkin/import.hx +++ b/source/funkin/import.hx @@ -22,6 +22,8 @@ import flixel.math.FlxMath; import flixel.tweens.FlxEase; import flixel.util.FlxDestroyUtil; +import funkin.backend.system.Flags; + import funkin.menus.ui.Alphabet; import flixel.group.FlxGroup.FlxTypedGroup; import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup; diff --git a/source/funkin/menus/FreeplayState.hx b/source/funkin/menus/FreeplayState.hx index 3d3a4d15..7c35d53a 100644 --- a/source/funkin/menus/FreeplayState.hx +++ b/source/funkin/menus/FreeplayState.hx @@ -465,8 +465,17 @@ class FreeplaySonglist { public static function get(useTxt:Bool = true) { var songList = new FreeplaySonglist(); - if (songList.getSongsFromSource(MODS, useTxt)) - songList.getSongsFromSource(SOURCE, useTxt); + switch(Flags.SONGS_LIST_MOD_MODE) { + case 'prepend': + songList.getSongsFromSource(MODS, useTxt); + songList.getSongsFromSource(SOURCE, useTxt); + case 'append': + songList.getSongsFromSource(SOURCE, useTxt); + songList.getSongsFromSource(MODS, useTxt); + default /*case 'override'*/: + if (songList.getSongsFromSource(MODS, useTxt)) + songList.getSongsFromSource(SOURCE, useTxt); + } return songList; } diff --git a/source/funkin/menus/StoryMenuState.hx b/source/funkin/menus/StoryMenuState.hx index e8ab5c25..6c30e2c3 100644 --- a/source/funkin/menus/StoryMenuState.hx +++ b/source/funkin/menus/StoryMenuState.hx @@ -205,8 +205,18 @@ class StoryMenuState extends MusicBeatState { public function loadXMLs() { // CoolUtil.coolTextFile(Paths.txt('freeplaySonglist')); var weeks:Array = []; - if (getWeeksFromSource(weeks, MODS)) - getWeeksFromSource(weeks, SOURCE); + + switch(Flags.WEEKS_LIST_MOD_MODE) { + case 'prepend': + getWeeksFromSource(weeks, MODS); + getWeeksFromSource(weeks, SOURCE); + case 'append': + getWeeksFromSource(weeks, SOURCE); + getWeeksFromSource(weeks, MODS); + default /*case 'override'*/: + if (getWeeksFromSource(weeks, MODS)) + getWeeksFromSource(weeks, SOURCE); + } for(k=>weekName in weeks) { var week:Access = null; From 3e27bbb0befe3f10298eb89c3f041a88a135478a Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Sun, 1 Sep 2024 03:59:28 +0200 Subject: [PATCH 08/15] oops --- source/funkin/backend/system/Flags.hx | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/source/funkin/backend/system/Flags.hx b/source/funkin/backend/system/Flags.hx index 804da965..fed62113 100644 --- a/source/funkin/backend/system/Flags.hx +++ b/source/funkin/backend/system/Flags.hx @@ -60,20 +60,4 @@ class Flags { customFlags.set(name, value); } } - - public static function getCleanLibraryName(e:AssetLibrary) { - var l = e; - if (l is openfl.utils.AssetLibrary) { - var al = cast(l, openfl.utils.AssetLibrary); - @:privateAccess - if (al.__proxy != null) l = al.__proxy; - } - - if (l is ScriptedAssetLibrary) - return '${cast(l, ScriptedAssetLibrary).scriptName} (${cast(l, ScriptedAssetLibrary).modName})'; - else if (l is IModsAssetLibrary) - return '${cast(l, IModsAssetLibrary).modName}'; - else - return Std.string(e); - } } \ No newline at end of file From 6021bd36dc9e00edb646089e5d1e26a20765fc1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=8D=9A=7ENex?= <87421482+NexIsDumb@users.noreply.github.com> Date: Sun, 1 Sep 2024 16:06:34 +0200 Subject: [PATCH 09/15] weeks highscore bugfix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit how did no one notice😭 --- source/funkin/game/PlayState.hx | 2 +- source/funkin/menus/StoryMenuState.hx | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index 8e6833b4..225a4275 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -363,7 +363,7 @@ class PlayState extends MusicBeatState * Speed at which the game camera zoom lerps to. */ public var camGameZoomLerp:Float = 0.05; - + /** * Camera zoom at which the hud lerps to. */ diff --git a/source/funkin/menus/StoryMenuState.hx b/source/funkin/menus/StoryMenuState.hx index 384118e5..27d700d7 100644 --- a/source/funkin/menus/StoryMenuState.hx +++ b/source/funkin/menus/StoryMenuState.hx @@ -199,7 +199,7 @@ class StoryMenuState extends MusicBeatState { } } - intendedScore = FunkinSave.getWeekHighscore(weeks[curWeek].name, weeks[curWeek].difficulties[curDifficulty]).score; + intendedScore = FunkinSave.getWeekHighscore(weeks[curWeek].id, weeks[curWeek].difficulties[curDifficulty]).score; } public function loadXMLs() { @@ -344,8 +344,8 @@ class StoryMenuState extends MusicBeatState { } typedef WeekData = { - var name:String; - var id:String; + var name:String; // name SHOULD NOT be used for loading week highscores, its just the name on the right side of the week, remember that next time!! - Nex + var id:String; // id IS instead for saving and loading!! - Nex var sprite:String; var chars:Array; var songs:Array; From 48758c8176fdc531a7831a2d6dbc9f7d751eb809 Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Mon, 2 Sep 2024 19:00:16 +0200 Subject: [PATCH 10/15] Fix camera pausing + Fixes #317 --- assets/data/scripts/pixel.hx | 6 ++++-- assets/data/scripts/week6-pause.hx | 3 ++- source/funkin/backend/utils/FunkinParentDisabler.hx | 9 +++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/assets/data/scripts/pixel.hx b/assets/data/scripts/pixel.hx index cc8239cf..48dfb279 100644 --- a/assets/data/scripts/pixel.hx +++ b/assets/data/scripts/pixel.hx @@ -162,16 +162,18 @@ function postUpdate(elapsed) { if (enableCameraHacks) { for(p in strumLines) p.notes.forEach(function(n) { + if(n.isSustainNote) return; // hacky fix for hold n.y -= n.y % daPixelZoom; n.x -= n.x % daPixelZoom; }); } + var zoom = 1 / daPixelZoom / Math.min(FlxG.scaleMode.scale.x, FlxG.scaleMode.scale.y); for(e in pixellyCameras) { if (!e.exists) continue; - e.zoom = 1 / daPixelZoom / Math.min(FlxG.scaleMode.scale.x, FlxG.scaleMode.scale.y); + e.zoom = zoom; } for(e in pixellyShaders) { - e.pixelZoom = 1 / daPixelZoom / Math.min(FlxG.scaleMode.scale.x, FlxG.scaleMode.scale.y); + e.pixelZoom = zoom; } } \ No newline at end of file diff --git a/assets/data/scripts/week6-pause.hx b/assets/data/scripts/week6-pause.hx index b382af35..6a4455cd 100644 --- a/assets/data/scripts/week6-pause.hx +++ b/assets/data/scripts/week6-pause.hx @@ -73,7 +73,8 @@ function confText(text) { } function destroy() { - FlxG.cameras.remove(pauseCam); + if(FlxG.cameras.list.contains(pauseCam)) + FlxG.cameras.remove(pauseCam); } var canDoShit = true; diff --git a/source/funkin/backend/utils/FunkinParentDisabler.hx b/source/funkin/backend/utils/FunkinParentDisabler.hx index f0617f5d..29e076be 100644 --- a/source/funkin/backend/utils/FunkinParentDisabler.hx +++ b/source/funkin/backend/utils/FunkinParentDisabler.hx @@ -32,8 +32,8 @@ class FunkinParentDisabler extends FlxBasic { FlxTimer.globalManager._timers = []; // cameras - __cameras = [for(c in FlxG.cameras.list) if (c.active) c]; - for(c in __cameras) c.active = false; + __cameras = [for(c in FlxG.cameras.list) if (!c.paused) c]; + for(c in __cameras) c.paused = true; // sounds __sounds = [for(s in FlxG.sound.list) if (s.playing) s]; @@ -41,9 +41,6 @@ class FunkinParentDisabler extends FlxBasic { } } - public override function update(elapsed:Float) { - @:privateAccess for(c in __cameras) c.updateFlashSpritePosition(); - } public override function draw() {} public function reset() { @@ -63,7 +60,7 @@ class FunkinParentDisabler extends FlxBasic { for(t in __tweens) FlxTween.globalManager._tweens.push(t); for(t in __timers) FlxTimer.globalManager._timers.push(t); } - for(c in __cameras) c.active = true; + for(c in __cameras) c.paused = false; for(s in __sounds) s.play(); } } From aa22bd6e1db79fe67d893135353e156036184d78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=8D=9A=7ENex?= <87421482+NexIsDumb@users.noreply.github.com> Date: Mon, 2 Sep 2024 23:47:11 +0200 Subject: [PATCH 11/15] fixing stuff --- .../system/framerate/FramerateCounter.hx | 29 ++----------------- .../editors/charter/SongCreationScreen.hx | 8 +---- 2 files changed, 4 insertions(+), 33 deletions(-) diff --git a/source/funkin/backend/system/framerate/FramerateCounter.hx b/source/funkin/backend/system/framerate/FramerateCounter.hx index 5658bd2b..c5641ee3 100644 --- a/source/funkin/backend/system/framerate/FramerateCounter.hx +++ b/source/funkin/backend/system/framerate/FramerateCounter.hx @@ -1,28 +1,17 @@ package funkin.backend.system.framerate; -import haxe.ds.Vector; import openfl.display.Sprite; import openfl.text.TextField; import openfl.text.TextFormat; -inline final FRAME_TIME_HISTORY = 20; - class FramerateCounter extends Sprite { public var fpsNum:TextField; public var fpsLabel:TextField; - - public var fpsHistoryIndex:Int = 0; - public var fpsHistory:Vector; + public var lastFPS:Float = 0; public function new() { super(); - fpsHistory = new Vector(FRAME_TIME_HISTORY); - // Initialize to 60 FPS, so that the initial estimation until we get enough data is always reasonable. - for(i in 0...FRAME_TIME_HISTORY) { - fpsHistory[i] = 1000.0 / 60.0; - } - fpsNum = new TextField(); fpsLabel = new TextField(); @@ -43,20 +32,8 @@ class FramerateCounter extends Sprite { if (alpha <= 0.05) return; super.__enterFrame(t); - // todo use gpu time - fpsHistory[fpsHistoryIndex] = FlxG.elapsed * 1000; - fpsHistoryIndex = (fpsHistoryIndex + 1) % FRAME_TIME_HISTORY; - - // Calculate average CPU time. - // Code based on Godot's FPS counter. - var cpuTime = 0.0; - for(i in 0...FRAME_TIME_HISTORY) { - cpuTime += fpsHistory[i]; - } - cpuTime /= FRAME_TIME_HISTORY; - cpuTime = Math.max(0.01, cpuTime); // Prevent unrealistically low values. - - fpsNum.text = Std.string(Math.floor(1000.0 / cpuTime)); + lastFPS = CoolUtil.fpsLerp(lastFPS, FlxG.elapsed == 0 ? 0 : (1 / FlxG.elapsed), 0.25); + fpsNum.text = Std.string(Math.floor(lastFPS)); fpsLabel.x = fpsNum.x + fpsNum.width; fpsLabel.y = (fpsNum.y + fpsNum.height) - fpsLabel.height; } diff --git a/source/funkin/editors/charter/SongCreationScreen.hx b/source/funkin/editors/charter/SongCreationScreen.hx index 7915cae0..80549cf7 100644 --- a/source/funkin/editors/charter/SongCreationScreen.hx +++ b/source/funkin/editors/charter/SongCreationScreen.hx @@ -80,8 +80,6 @@ class SongCreationScreen extends UISubstateWindow { stepsPerBeatStepper = new UINumericStepper(beatsPerMeasureStepper.x + 30 + 24, beatsPerMeasureStepper.y, 4, 1, 0, 1, null, 54); songDataGroup.add(stepsPerBeatStepper); - var voicesUIText:UIText = null; - instExplorer = new UIFileExplorer(songNameTextBox.x, songNameTextBox.y + 32 + 36, null, null, Paths.SOUND_EXT, function (res) { var audioPlayer:UIAudioPlayer = new UIAudioPlayer(instExplorer.x + 8, instExplorer.y + 8, res); instExplorer.members.push(audioPlayer); @@ -98,11 +96,7 @@ class SongCreationScreen extends UISubstateWindow { voicesExplorer.uiElement = audioPlayer; }); songDataGroup.add(voicesExplorer); - - voicesUIText = addLabelOn(voicesExplorer, "Vocal Audio File"); - voicesUIText.applyMarkup( - "Vocal Audio File $* Required$", - [new FlxTextFormatMarkerPair(new FlxTextFormat(0xFFAD1212), "$")]); + addLabelOn(voicesExplorer, "Vocal Audio File"); var menuTitle:UIText; menuDataGroup.add(menuTitle = new UIText(windowSpr.x + 20, windowSpr.y + 30 + 16, 0, "Menus Data (Freeplay/Story)", 28)); From 669645ed47fa6f12ab3d507f0bd3acea24ab08f7 Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Tue, 3 Sep 2024 15:28:46 +0200 Subject: [PATCH 12/15] Enabled Optimizations --- project.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/project.xml b/project.xml index 232f6159..f8848e03 100644 --- a/project.xml +++ b/project.xml @@ -150,6 +150,8 @@ + + From 623ac099504758bc4d040eb3e9d435209a476dfd Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Wed, 4 Sep 2024 12:25:19 +0200 Subject: [PATCH 13/15] Better limit --- source/funkin/game/StrumLine.hx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/funkin/game/StrumLine.hx b/source/funkin/game/StrumLine.hx index dd952d19..763210f8 100644 --- a/source/funkin/game/StrumLine.hx +++ b/source/funkin/game/StrumLine.hx @@ -152,7 +152,8 @@ class StrumLine extends FlxTypedGroup { var scrollSpeed = strumLine.scrollSpeed; if(scrollSpeed == null) if (PlayState.instance != null) scrollSpeed = PlayState.instance.scrollSpeed; if(scrollSpeed == null) scrollSpeed = 1; - notes.limit = 1500 / scrollSpeed; + var limit = FlxG.height / 0.45; + notes.limit = limit / scrollSpeed; } public override function update(elapsed:Float) { From b265b0abd54d6f7124151cb2c3c391812d458f49 Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Wed, 4 Sep 2024 14:00:39 +0200 Subject: [PATCH 14/15] Small cleanup --- source/funkin/game/PlayState.hx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index dcc205cd..8699b92e 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -653,10 +653,12 @@ class PlayState extends MusicBeatState chars.push(char); } - var strOffset:Float = strumLine.strumLinePos == null ? (strumLine.type == 1 ? 0.75 : 0.25) : strumLine.strumLinePos; - var startingPos:FlxPoint = strumLine.strumPos == null ? - FlxPoint.get((FlxG.width * strOffset) - ((Note.swagWidth * (strumLine.strumScale == null ? 1 : strumLine.strumScale)) * 2), this.strumLine.y) : - FlxPoint.get(strumLine.strumPos[0] == 0 ? ((FlxG.width * strOffset) - ((Note.swagWidth * (strumLine.strumScale == null ? 1 : strumLine.strumScale)) * 2)) : strumLine.strumPos[0], strumLine.strumPos[1]); + var strOffset:Float = strumLine.strumLinePos != null ? strumLine.strumLinePos : (strumLine.type == 1 ? 0.75 : 0.25); + var strScale:Float = strumLine.strumScale != null ? strumLine.strumScale : 1; + var strXPos:Float = (FlxG.width * strOffset) - (Note.swagWidth * strScale * 2); + var startingPos:FlxPoint = strumLine.strumPos != null ? + FlxPoint.get(strumLine.strumPos[0] == 0 ? strXPos : strumLine.strumPos[0], strumLine.strumPos[1]) : + FlxPoint.get(strXPos, this.strumLine.y); var strLine = new StrumLine(chars, startingPos, strumLine.strumScale == null ? 1 : strumLine.strumScale, From 804a5898027f8b8a58975f70abba3485f8024c5e Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Thu, 5 Sep 2024 17:44:59 +0200 Subject: [PATCH 15/15] Small cleanup --- source/funkin/editors/charter/CharterEvent.hx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/funkin/editors/charter/CharterEvent.hx b/source/funkin/editors/charter/CharterEvent.hx index a1a660f0..3831d99a 100644 --- a/source/funkin/editors/charter/CharterEvent.hx +++ b/source/funkin/editors/charter/CharterEvent.hx @@ -48,10 +48,12 @@ class CharterEvent extends UISliceSprite implements ICharterSelectable { var isBase64:Bool = false; var path:String = Paths.image('editors/charter/event-icons/$name'); if (!Assets.exists(path)) path = Paths.image('editors/charter/event-icons/Unknown'); - if (Assets.exists(Paths.pack('events/$name'))) { - var packimg = Assets.getText(Paths.pack('events/$name')).split('________PACKSEP________')[3]; + var packPath = Paths.pack('events/$name'); + if (Assets.exists(packPath)) { + var packText = Assets.getText(packPath).split('________PACKSEP________'); + var packimg = packText[3]; if (isBase64 = (packimg != null)) - path = Assets.getText(Paths.pack('events/$name')).split('________PACKSEP________')[3]; + path = packText[3]; } var spr = new FlxSprite().loadGraphic(isBase64 ? openfl.display.BitmapData.fromBase64(path.trim(), 'UTF8') : path); return spr;