diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 76adeded..758cd50f 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -31,7 +31,7 @@ jobs: sudo apt-get install libvlc-dev libvlccore-dev - name: Installing/Updating libraries run: | - haxe -cp commandline -D analyzer-optimize --run Main setup + haxe -cp commandline -D analyzer-optimize --run Main setup -s - name: Building the game run: | haxelib run lime build linux diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index e6646418..9ae13a76 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -28,7 +28,7 @@ jobs: cache-build-mac - name: Installing/Updating libraries run: | - haxe -cp commandline -D analyzer-optimize --run Main setup + haxe -cp commandline -D analyzer-optimize --run Main setup -s - name: Building the game run: | haxelib run lime build mac diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index d89c1687..3ec71f90 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -28,7 +28,7 @@ jobs: cache-build-windows - name: Installing/Updating libraries run: | - haxe -cp commandline -D analyzer-optimize --run Main setup + haxe -cp commandline -D analyzer-optimize --run Main setup -s --no-vscheck - name: Building the game run: | haxelib run lime build windows diff --git a/assets/data/characters/bf-car.xml b/assets/data/characters/bf-car.xml index 9bfefe90..b4c9b24c 100644 --- a/assets/data/characters/bf-car.xml +++ b/assets/data/characters/bf-car.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/bf-christmas.xml b/assets/data/characters/bf-christmas.xml index 94a30701..88feb049 100644 --- a/assets/data/characters/bf-christmas.xml +++ b/assets/data/characters/bf-christmas.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/bf-dead.xml b/assets/data/characters/bf-dead.xml index 4843f873..4cd9acd3 100644 --- a/assets/data/characters/bf-dead.xml +++ b/assets/data/characters/bf-dead.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/bf-holding-gf-dead.xml b/assets/data/characters/bf-holding-gf-dead.xml index cc80ef1a..52fa52eb 100644 --- a/assets/data/characters/bf-holding-gf-dead.xml +++ b/assets/data/characters/bf-holding-gf-dead.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/bf-holding-gf.xml b/assets/data/characters/bf-holding-gf.xml index 555c83be..390504bc 100644 --- a/assets/data/characters/bf-holding-gf.xml +++ b/assets/data/characters/bf-holding-gf.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/bf-pixel-dead.xml b/assets/data/characters/bf-pixel-dead.xml index 807b834e..52aedd58 100644 --- a/assets/data/characters/bf-pixel-dead.xml +++ b/assets/data/characters/bf-pixel-dead.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/bf-pixel.xml b/assets/data/characters/bf-pixel.xml index 5658389c..b1c668a3 100644 --- a/assets/data/characters/bf-pixel.xml +++ b/assets/data/characters/bf-pixel.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/bf.xml b/assets/data/characters/bf.xml index bec2f424..04e2b3c5 100644 --- a/assets/data/characters/bf.xml +++ b/assets/data/characters/bf.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/da.xml b/assets/data/characters/da.xml index 8643cb7b..2ef057ba 100644 --- a/assets/data/characters/da.xml +++ b/assets/data/characters/da.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/dad.xml b/assets/data/characters/dad.xml index 989c4320..1b1e0f04 100644 --- a/assets/data/characters/dad.xml +++ b/assets/data/characters/dad.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/gf-car.xml b/assets/data/characters/gf-car.xml index 54062e72..72ca5814 100644 --- a/assets/data/characters/gf-car.xml +++ b/assets/data/characters/gf-car.xml @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/assets/data/characters/gf-christmas.xml b/assets/data/characters/gf-christmas.xml index f293b7f4..1a995a2a 100644 --- a/assets/data/characters/gf-christmas.xml +++ b/assets/data/characters/gf-christmas.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/gf-pixel.xml b/assets/data/characters/gf-pixel.xml index 9d4901d9..73aa39e9 100644 --- a/assets/data/characters/gf-pixel.xml +++ b/assets/data/characters/gf-pixel.xml @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/assets/data/characters/gf-tankmen.xml b/assets/data/characters/gf-tankmen.xml index 47b8fa92..7ba7df0a 100644 --- a/assets/data/characters/gf-tankmen.xml +++ b/assets/data/characters/gf-tankmen.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/gf.xml b/assets/data/characters/gf.xml index e9ac6776..911d2073 100644 --- a/assets/data/characters/gf.xml +++ b/assets/data/characters/gf.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/mom-car.xml b/assets/data/characters/mom-car.xml index 49af99e8..fa7c18dd 100644 --- a/assets/data/characters/mom-car.xml +++ b/assets/data/characters/mom-car.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/mom.xml b/assets/data/characters/mom.xml index a75304e9..4781ede4 100644 --- a/assets/data/characters/mom.xml +++ b/assets/data/characters/mom.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/monster-christmas.xml b/assets/data/characters/monster-christmas.xml index 015a00f8..61bae9ee 100644 --- a/assets/data/characters/monster-christmas.xml +++ b/assets/data/characters/monster-christmas.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/monster.xml b/assets/data/characters/monster.xml index e2ae7262..df8d70bd 100644 --- a/assets/data/characters/monster.xml +++ b/assets/data/characters/monster.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/parents-christmas.xml b/assets/data/characters/parents-christmas.xml index 71093d11..991fff09 100644 --- a/assets/data/characters/parents-christmas.xml +++ b/assets/data/characters/parents-christmas.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/pico-speakers.xml b/assets/data/characters/pico-speakers.xml index 519b5bf9..ffb35177 100644 --- a/assets/data/characters/pico-speakers.xml +++ b/assets/data/characters/pico-speakers.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/pico.xml b/assets/data/characters/pico.xml index 9dba4fea..74e9baed 100644 --- a/assets/data/characters/pico.xml +++ b/assets/data/characters/pico.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/senpai-angry.xml b/assets/data/characters/senpai-angry.xml index d0cd24fb..c1203449 100644 --- a/assets/data/characters/senpai-angry.xml +++ b/assets/data/characters/senpai-angry.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/senpai.xml b/assets/data/characters/senpai.xml index eb9419f6..f243b2e5 100644 --- a/assets/data/characters/senpai.xml +++ b/assets/data/characters/senpai.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/spirit.xml b/assets/data/characters/spirit.xml index 632ee939..d1ee5dc9 100644 --- a/assets/data/characters/spirit.xml +++ b/assets/data/characters/spirit.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/spooky.xml b/assets/data/characters/spooky.xml index 70e55d63..2a434f21 100644 --- a/assets/data/characters/spooky.xml +++ b/assets/data/characters/spooky.xml @@ -1,5 +1,5 @@ - + diff --git a/assets/data/characters/tankman.xml b/assets/data/characters/tankman.xml index c9b194ff..092e0368 100644 --- a/assets/data/characters/tankman.xml +++ b/assets/data/characters/tankman.xml @@ -1,5 +1,5 @@ - + diff --git a/commandline/ArgParser.hx b/commandline/ArgParser.hx new file mode 100644 index 00000000..61ff15b8 --- /dev/null +++ b/commandline/ArgParser.hx @@ -0,0 +1,81 @@ +package; + +using StringTools; + +class ArgParser { + public static function parse(args:Array, ?renameMap:Map = null):ArgParser { + return new ArgParser(args, renameMap); + } + + private function new(args:Array, ?renameMap:Map) { + if (renameMap == null) { + renameMap = new Map(); + } + function rename(name:String) { + return renameMap.exists(name) ? renameMap.get(name) : name; + } + this.args = args; + + this.options = new Map(); + var copy = args.copy(); + var i = 0; + while(copy.length > 0) { + var arg = copy.shift(); + // this parses the -NAME=VALUE + if (arg.startsWith("-")) { + var key = arg.substr(1); + var isLongKey = key.startsWith("-"); + if (isLongKey) { + key = key.substr(1); + } + var split = key.split("="); + var longName = split.shift(); + if(!isLongKey) { + // Allow -ABC to be parsed as -A -B -C + // Values will only work for the last one + while(longName.length > 1) { + var name = rename(longName.charAt(0)); + options.set(name, null); + longName = longName.substr(1); + } + + longName = longName.charAt(0); + // Parse the last option with value support + } + + var name = rename(longName); + var value = (split.length > 0) ? split.join("=") : null; + options.set(name, value); + + args.splice(i, 1); + i--; + } + + i++; + } + } + + /** + * Options are arguments that start with a "-", if they are followed by an "=" they are a key/value pair. + * otherwise they are stored as a key with an null value. + **/ + public var options(default, null):Map; + public var args(default, null):Array; + + public var length(get, never):Int; + inline function get_length():Int { + return args.length; + } + + public function get(index:Int):String { + return args[index]; + } + + public function existsOption(name:String):Bool { + return options.exists(name); + } + + public function getOption(name:String):String { + return options.get(name); + } +} \ No newline at end of file diff --git a/commandline/Main.hx b/commandline/Main.hx index 6d628cf3..8c2f9301 100644 --- a/commandline/Main.hx +++ b/commandline/Main.hx @@ -5,57 +5,108 @@ import commands.*; class Main { public static var commands:Array = []; + public static var curCommand:Command; + public static function initCommands() { commands = [ { names: ["setup"], doc: "Setups (or updates) all libraries required for the engine.", func: Update.main, - dDoc: "This command runs through all libraries in libs.xml, and install them.\nIf they're already installed, they will be updated." + dDoc: [ + "Usage: setup", + "", + "This command runs through all libraries in libs.xml, and install them.", + "If they're already installed, they will be updated.", + "", + "--all : Reinstall all libraries.", + "--no-vscheck : Don't check if Visual Studio is installed.", + "-s | --silent | --silent-progress : Don't show download progress." + ].join("\n") }, { names: ["help", null], doc: "Shows help. Pass a command name to get additional help.", func: help, - dDoc: "Usage: help \n\nFor example, use \"cne help test\" to get additional help on the test command." + dDoc: [ + "Usage: help ", + "", + "For example, use \"cne help test\" to get additional help on the test command." + ].join("\n") }, { names: ["test"], doc: "Creates a non final test build, then runs it.", func: Compiler.test, - dDoc: "Usage: test \n" + - "\nThis will create a quick debug build binded to the source then run it, which means:" + - "\n- The assets WON'T be copied over - Assets will be read from the game's source." + - "\n- This build WON'T be ready for release - Running anywhere else than in the bin folder will result in a crash from missing assets" + - "\n- This build will also use the mods folder from the source directory." + - "\n\nIf you want a full build which contains all assets, run \"cne release\" or \"cne test-release\"" + - "\nAdditional arguments will be sent to the lime compiler." + dDoc: [ + "Usage: test ", + "", + "This will create a quick debug build binded to the source then run it, which means:", + "- The assets WON'T be copied over - Assets will be read from the game's source.", + "- This build WON'T be ready for release - Running anywhere else than in the bin folder will result in a crash from missing assets", + "- This build will also use the mods folder from the source directory.", + "", + "If you want a full build which contains all assets, run \"cne release\" or \"cne test-release\"", + "Additional arguments will be sent to the lime compiler.", + "", + "-debug : Builds a debug build." + ].join("\n") }, { names: ["build"], doc: "Creates a non final test build, without running it.", func: Compiler.build, - dDoc: "Usage: build \n" + - "\nThis will create a quick debug build binded to the source then run it, which means:" + - "\n- The assets WON'T be copied over - Assets will be read from the game's source." + - "\n- This build WON'T be ready for release - Running anywhere else than in the bin folder will result in a crash from missing assets" + - "\n- This build will also use the mods folder from the source directory." + - "\n\nIf you want a full build which contains all assets, run \"cne release\" or \"cne test-release\"" + - "\nAdditional arguments will be sent to the lime compiler." + dDoc: [ + "Usage: build ", + "", + "This will create a quick debug build binded to the source then run it, which means:", + "- The assets WON'T be copied over - Assets will be read from the game's source.", + "- This build WON'T be ready for release - Running anywhere else than in the bin folder will result in a crash from missing assets", + "- This build will also use the mods folder from the source directory.", + "", + "If you want a full build which contains all assets, run \"cne release\" or \"cne test-release\"", + "Additional arguments will be sent to the lime compiler.", + "", + "-debug : Builds a debug build." + ].join("\n") }, { names: ["release"], doc: "Creates a final non debug build, containing all assets.", func: Compiler.release, - dDoc: "Usage: release \n" + - "\nThis will create a final ready-for-release build, which means this build will be able to be release on websites such as GameBanana without worrying about source-dependant stuff." + dDoc: [ + "Usage: release ", + "", + "This will create and run a final ready-for-release build,", + "which means this build will be able to be release on websites such as GameBanana without worrying about source-dependant stuff.", + "Additional arguments will be sent to the lime compiler." + ].join("\n") }, { names: ["test-release"], doc: "Creates a final non debug build, containing all assets.", func: Compiler.testRelease, - dDoc: "Usage: release \n" + - "\nThis will create and run a final ready-for-release build, which means this build will be able to be release on websites such as GameBanana without worrying about source-dependant stuff." + dDoc: [ + "Usage: test-release ", + "", + "This will create and run a final ready-for-release build,", + "which means this build will be able to be release on websites such as GameBanana without worrying about source-dependant stuff.", + "Additional arguments will be sent to the lime compiler." + ].join("\n") + }, + { + names: ["optimize"], + doc: "Optimizes a JSON file.", + func: Optimizer.main, + dDoc: [ + "Usage: optimize ", + "", + "This will optimize a JSON file, which means it will remove all unnecessary spacing from the file.", + "WARNING: Order might be lost.", + "WARNING: Comments arent supported.", + "", + "-O | --no-old : No Old file will be created.", + ].join("\n") } ]; } @@ -66,8 +117,12 @@ class Main { var commandName = args.shift(); if (commandName != null) commandName = commandName.toLowerCase(); + else + commandName = "help"; + for(c in commands) { if (c.names.contains(commandName)) { + curCommand = c; c.func(args); return; } @@ -90,7 +145,7 @@ class Main { return; } - Sys.println('${matchingCommand.names.join(", ")}'); + Sys.println('Command: ${matchingCommand.names.filter(v->v != null).join(", ")}'); Sys.println("---"); Sys.println(matchingCommand.dDoc); diff --git a/commandline/commands/Compiler.hx b/commandline/commands/Compiler.hx index fe64c198..6d09f5aa 100644 --- a/commandline/commands/Compiler.hx +++ b/commandline/commands/Compiler.hx @@ -2,10 +2,10 @@ package commands; class Compiler { public static function test(args:Array) { - __build(args, ["test", getBuildTarget(), "-D", "TEST_BUILD"]); + __build(args, ["test", getBuildTarget(), "-DTEST_BUILD"]); } public static function build(args:Array) { - __build(args, ["build", getBuildTarget(), "-D", "TEST_BUILD"]); + __build(args, ["build", getBuildTarget(), "-DTEST_BUILD"]); } public static function release(args:Array) { __build(args, ["build", getBuildTarget()]); diff --git a/commandline/commands/Optimizer.hx b/commandline/commands/Optimizer.hx new file mode 100644 index 00000000..b82d9182 --- /dev/null +++ b/commandline/commands/Optimizer.hx @@ -0,0 +1,31 @@ +package commands; + +import sys.io.File; + +class Optimizer { + public static function main(args:Array) { + var args = ArgParser.parse(args); + var saveOld = args.existsOption("no-old"); + + if(args.length == 0) { + Sys.println(Main.curCommand.dDoc); + return; + } + + var filename = args.get(0); + + var data = File.getContent(filename); + var json = null; + try { + json = haxe.Json.parse(data); + } catch(e:Dynamic) { + Sys.println("Error parsing JSON file."); + Sys.println(e); + return; + } + + if(saveOld) + File.saveContent(filename + ".old", data); + File.saveContent(filename, haxe.Json.stringify(json)); + } +} \ No newline at end of file diff --git a/commandline/commands/Update.hx b/commandline/commands/Update.hx index f96a12db..b877d32e 100644 --- a/commandline/commands/Update.hx +++ b/commandline/commands/Update.hx @@ -10,10 +10,20 @@ class Update { public static function main(args:Array) { prettyPrint("Preparing installation..."); + var args = ArgParser.parse(args, ["S" => "silent-progress", "silent" => "silent-progress"]); + var CHECK_VSTUDIO = !args.existsOption("no-vscheck"); + var REINSTALL_ALL = args.existsOption("all"); + var SILENT = args.existsOption("silent-progress"); + // to prevent messing with currently installed libs if (!FileSystem.exists('.haxelib')) FileSystem.createDirectory('.haxelib'); + if (REINSTALL_ALL) { + FileSystem.deleteDirectory('.haxelib'); + FileSystem.createDirectory('.haxelib'); + } + var libs:Array = []; var libsXML:Access = new Access(Xml.parse(File.getContent('./libs.xml')).firstElement()); @@ -33,18 +43,21 @@ class Update { libs.push(lib); } + var commandSuffix = " --always"; + if (SILENT) commandSuffix += " --silent"; + for(lib in libs) { var globalism:Null = lib.global == "true" ? "--global" : null; + var globalSuffix = globalism != null ? ' $globalism' : ''; switch(lib.type) { case "lib": prettyPrint((lib.global == "true" ? "Globally installing" : "Locally installing") + ' "${lib.name}"...'); - Sys.command('haxelib install ${lib.name} ${lib.version != null ? " " + lib.version : " "}${globalism != null ? ' $globalism' : ''} --always'); + Sys.command('haxelib install ${lib.name} ${lib.version != null ? " " + lib.version : " "}$globalSuffix$commandSuffix'); case "git": prettyPrint((lib.global == "true" ? "Globally installing" : "Locally installing") + ' "${lib.name}" from git url "${lib.url}"'); - Sys.command('haxelib git ${lib.name} ${lib.url}${lib.ref != null ? ' ${lib.ref}' : ''}${globalism != null ? ' $globalism' : ''} --always'); + Sys.command('haxelib git ${lib.name} ${lib.url}${lib.ref != null ? ' ${lib.ref}' : ''}$globalSuffix$commandSuffix'); case "custom": Sys.command('haxelib dev ${lib.name} "./libraries/${lib.name}"'); - default: prettyPrint('Cannot resolve library of type "${lib.type}"'); } @@ -76,7 +89,7 @@ class Update { } // vswhere.exe its used to find any visual studio related installations on the system, including full visual studio ide installations, visual studio build tools installations, and other related components - Nex - if (Compiler.getBuildTarget().toLowerCase() == "windows" && new Process('"C:/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe" -property catalog_productDisplayVersion').exitCode(true) == 1) { + if (CHECK_VSTUDIO && Compiler.getBuildTarget().toLowerCase() == "windows" && new Process('"C:/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe" -property catalog_productDisplayVersion').exitCode(true) == 1) { prettyPrint("Installing Microsoft Visual Studio Community (Dependency)"); // thanks to @crowplexus for these two lines! - Nex diff --git a/source/funkin/backend/FunkinSprite.hx b/source/funkin/backend/FunkinSprite.hx index 51a322c0..e4672c6f 100644 --- a/source/funkin/backend/FunkinSprite.hx +++ b/source/funkin/backend/FunkinSprite.hx @@ -33,6 +33,8 @@ enum abstract XMLAnimType(Int) class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements IOffsetCompatible implements IXMLEvents { + public var extra:Map = []; + public var spriteAnimType:XMLAnimType = NONE; public var beatAnims:Array = []; public var name:String; @@ -225,7 +227,7 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I for (key in animOffsets.keys()) { final point = animOffsets[key]; animOffsets.remove(key); - if(point != null) + if (point != null) point.put(); } animOffsets = null; @@ -320,19 +322,8 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I return animateAtlas != null ? (animateAtlas.anim.animsMap.exists(AnimName) || animateAtlas.anim.symbolDictionary.exists(AnimName)) : animation.exists(AnimName); - public inline function getAnimName() - { - var name = null; - if (animateAtlas != null) - { - name = atlasPlayingAnim; - } - else - { - if (animation.curAnim != null) - name = animation.curAnim.name; - } - return name; + public inline function getAnimName() { + return (animateAtlas != null) ? atlasPlayingAnim : animation.name; } public inline function removeAnimation(name:String) { @@ -356,8 +347,7 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I animation.stop(); } - public inline function isAnimFinished() - { + public inline function isAnimFinished() { return animateAtlas != null ? (animateAtlas.anim.finished) : (animation.curAnim != null ? animation.curAnim.finished : true); } #end diff --git a/source/funkin/backend/chart/Chart.hx b/source/funkin/backend/chart/Chart.hx index e519c000..57cb9b62 100644 --- a/source/funkin/backend/chart/Chart.hx +++ b/source/funkin/backend/chart/Chart.hx @@ -230,7 +230,7 @@ class Chart { if(data.meta != null && Reflect.hasField(data.meta, "parsedColor")) Reflect.deleteField(data.meta, "parsedColor"); } - data.events = saveEventsInChart != true ? null : Reflect.copy(chart.events); // same here once again + data.events = saveEventsInChart != true ? null : Reflect.copy(chart.events); // same here once again data.fromMods = null; var sortedData:Dynamic = {}; diff --git a/source/funkin/backend/chart/FNFLegacyParser.hx b/source/funkin/backend/chart/FNFLegacyParser.hx index ddf1588c..59cae28a 100644 --- a/source/funkin/backend/chart/FNFLegacyParser.hx +++ b/source/funkin/backend/chart/FNFLegacyParser.hx @@ -131,7 +131,7 @@ class FNFLegacyParser { if ((swagSection.mustHitSection && strumLine.type == OPPONENT) || (!swagSection.mustHitSection && strumLine.type == PLAYER)) - sectionNote[1] += 4; + sectionNote[1] += 4; swagSection.sectionNotes.push(note); } } diff --git a/source/funkin/backend/scripting/events/FreeplayAlphaUpdateEvent.hx b/source/funkin/backend/scripting/events/FreeplayAlphaUpdateEvent.hx index 5862f280..639645c2 100644 --- a/source/funkin/backend/scripting/events/FreeplayAlphaUpdateEvent.hx +++ b/source/funkin/backend/scripting/events/FreeplayAlphaUpdateEvent.hx @@ -14,8 +14,8 @@ final class FreeplayAlphaUpdateEvent extends CancellableEvent { */ public var selectedAlpha:Float; /** - * The alpha when something is playing and selected - */ + * The alpha when something is playing and selected + */ public var selectedPlayingAlpha:Float; /** * The lerp of the alpha diff --git a/source/funkin/backend/shaders/FunkinShader.hx b/source/funkin/backend/shaders/FunkinShader.hx index ef91d128..8002d9fd 100644 --- a/source/funkin/backend/shaders/FunkinShader.hx +++ b/source/funkin/backend/shaders/FunkinShader.hx @@ -363,12 +363,12 @@ class FunkinShader extends FlxShader implements IHScriptCustomBehaviour { } public function hget(name:String):Dynamic { - if (__instanceFields.contains(name) || __instanceFields.contains('get_${name}')) { + if (__instanceFields.contains(name) || __instanceFields.contains('get_${name}')) return Reflect.getProperty(this, name); - } - if (!Reflect.hasField(data, name)) return null; - var field = Reflect.field(data, name); - var cl = Type.getClassName(Type.getClass(field)); + if (!Reflect.hasField(data, name)) + return null; + var field:Dynamic = Reflect.field(data, name); + var cl:String = Type.getClassName(Type.getClass(field)); // little problem we are facing boys... @@ -394,45 +394,37 @@ class FunkinShader extends FlxShader implements IHScriptCustomBehaviour { if (!Reflect.hasField(data, name)) { Reflect.setField(data, name, val); return val; - } else { - var field = Reflect.field(data, name); - var cl = Type.getClassName(Type.getClass(field)); - // cant do "field is ShaderInput" for some reason - if (cl.startsWith("openfl.display.ShaderParameter")) { - @:privateAccess - if (field.__length <= 1) { - // that means we wait for a single number, instead of an array - @:privateAccess - if (field.__isInt && !(val is Int)) { - throw new ShaderTypeException(name, Type.getClass(val), 'Int'); - return null; - } else - @:privateAccess - if (field.__isBool && !(val is Bool)) { - throw new ShaderTypeException(name, Type.getClass(val), 'Bool'); - return null; - } else - @:privateAccess - if (field.__isFloat && !(val is Float)) { - throw new ShaderTypeException(name, Type.getClass(val), 'Float'); - return null; - } - return field.value = [val]; - } else { - if (!(val is Array)) { - throw new ShaderTypeException(name, Type.getClass(val), Array); - return null; - } + } + + var field:Dynamic = Reflect.field(data, name); + var cl:String = Type.getClassName(Type.getClass(field)); + // cant do "field is ShaderInput" for some reason + if (cl.startsWith("openfl.display.ShaderParameter")) { + @:privateAccess + if (field.__length <= 1) { + if ((val is Array)) return field.value = val; - } - } else if (cl.startsWith("openfl.display.ShaderInput")) { - // shader input!! - if (!(val is BitmapData)) { - throw new ShaderTypeException(name, Type.getClass(val), BitmapData); - return null; - } - field.input = cast val; + // that means we wait for a single number, instead of an array + if (field.__isInt && !(val is Int)) + throw new ShaderTypeException(name, Type.getClass(val), 'Int'); + else if (field.__isBool && !(val is Bool)) + throw new ShaderTypeException(name, Type.getClass(val), 'Bool'); + else if (field.__isFloat && !(val is Float)) + throw new ShaderTypeException(name, Type.getClass(val), 'Float'); + + return field.value = [val]; + } else { + if (!(val is Array)) + throw new ShaderTypeException(name, Type.getClass(val), Array); + + return field.value = val; } + } else if (cl.startsWith("openfl.display.ShaderInput")) { + // shader input!! + if (!(val is BitmapData)) { + throw new ShaderTypeException(name, Type.getClass(val), BitmapData); + } + field.input = cast val; } return val; diff --git a/source/funkin/backend/system/CommandLineHandler.hx b/source/funkin/backend/system/CommandLineHandler.hx index 4050b049..3690b6a2 100644 --- a/source/funkin/backend/system/CommandLineHandler.hx +++ b/source/funkin/backend/system/CommandLineHandler.hx @@ -19,6 +19,7 @@ class CommandLineHandler { #end Sys.println("-nocolor | Disables colors in the terminal"); Sys.println("-nogpubitmap | Forces GPU only bitmaps off"); + Sys.println("-nocwdfix | Turns off automatic working directory fix"); Sys.exit(0); #if MOD_SUPPORT case "-m" | "-mod" | "-currentmod": @@ -59,6 +60,8 @@ class CommandLineHandler { Main.noTerminalColor = true; case "-nogpubitmap": Main.forceGPUOnlyBitmapsOff = true; + case "-nocwdfix": + Main.noCwdFix = true; case "-livereload": // do nothing default: diff --git a/source/funkin/backend/system/Controls.hx b/source/funkin/backend/system/Controls.hx index 9dbae1f1..76c50d14 100644 --- a/source/funkin/backend/system/Controls.hx +++ b/source/funkin/backend/system/Controls.hx @@ -585,7 +585,7 @@ class Controls extends FlxActionSet #else for (gamepad in controls.gamepadsAdded) if (gamepadsAdded.indexOf(gamepad) == -1) - gamepadsAdded.push(gamepad); + gamepadsAdded.push(gamepad); #end mergeKeyboardScheme(controls.keyboardScheme); diff --git a/source/funkin/backend/system/Logs.hx b/source/funkin/backend/system/Logs.hx index 73060bba..ab317835 100644 --- a/source/funkin/backend/system/Logs.hx +++ b/source/funkin/backend/system/Logs.hx @@ -32,11 +32,11 @@ class Logs { var prefix = "[FLIXEL]"; var color:ConsoleColor = LIGHTGRAY; var level:Level = INFO; - if (Style == LogStyle.CONSOLE) {prefix = "> "; color = WHITE; level = INFO; } else - if (Style == LogStyle.ERROR) {prefix = "[FLIXEL]"; color = RED; level = ERROR; } else - if (Style == LogStyle.NORMAL) {prefix = "[FLIXEL]"; color = WHITE; level = INFO; } else - if (Style == LogStyle.NOTICE) {prefix = "[FLIXEL]"; color = GREEN; level = VERBOSE;} else - if (Style == LogStyle.WARNING) {prefix = "[FLIXEL]"; color = YELLOW; level = WARNING;} + if (Style == LogStyle.CONSOLE) {prefix = "> "; color = WHITE; level = INFO; } else + if (Style == LogStyle.ERROR) {prefix = "[FLIXEL]"; color = RED; level = ERROR; } else + if (Style == LogStyle.NORMAL) {prefix = "[FLIXEL]"; color = WHITE; level = INFO; } else + if (Style == LogStyle.NOTICE) {prefix = "[FLIXEL]"; color = GREEN; level = VERBOSE;} else + if (Style == LogStyle.WARNING) {prefix = "[FLIXEL]"; color = YELLOW; level = WARNING;} var d:Dynamic = Data; if (!(d is Array)) @@ -56,11 +56,11 @@ class Logs { logText('${Std.string(time.getHours()).addZeros(2)}:${Std.string(time.getMinutes()).addZeros(2)}:${Std.string(time.getSeconds()).addZeros(2)}', DARKMAGENTA), logText(' |'), switch(level) { - case WARNING: logText(' WARNING ', DARKYELLOW); - case ERROR: logText(' ERROR ', DARKRED); - case TRACE: logText(' TRACE ', GRAY); - case VERBOSE: logText(' VERBOSE ', DARKMAGENTA); - default: logText(' INFORMATION ', CYAN); + case WARNING: logText(' WARNING ', DARKYELLOW); + case ERROR: logText(' ERROR ', DARKRED); + case TRACE: logText(' TRACE ', GRAY); + case VERBOSE: logText(' VERBOSE ', DARKMAGENTA); + default: logText(' INFORMATION ', CYAN); }, logText('] ') ]; diff --git a/source/funkin/backend/system/Main.hx b/source/funkin/backend/system/Main.hx index c1203721..0ec8a7b7 100644 --- a/source/funkin/backend/system/Main.hx +++ b/source/funkin/backend/system/Main.hx @@ -24,6 +24,10 @@ import sys.thread.Thread; import sys.io.File; #end import funkin.backend.assets.ModsFolder; +#if android +import android.content.Context; +import android.os.Build; +#end class Main extends Sprite { @@ -198,9 +202,23 @@ class Main extends Sprite for(b in pool.clear()) b.destroy(); } + openfl.display3D.utils.UInt8Buff._pools.clear(); } MemoryUtil.clearMajor(); } + + public static var noCwdFix:Bool = false; + public static function fixWorkingDirectory() { + #if windows + if (!noCwdFix && !sys.FileSystem.exists('manifest/default.json')) { + Sys.setCwd(haxe.io.Path.directory(Sys.programPath())); + } + #elseif android + Sys.setCwd(Path.addTrailingSlash(VERSION.SDK_INT > 30 ? Context.getObbDir() : Context.getExternalFilesDir())); + #elseif (ios || switch) + Sys.setCwd(Path.addTrailingSlash(openfl.filesystem.File.applicationStorageDirectory.nativePath)); + #end + } } diff --git a/source/funkin/backend/system/macros/NewHaxeWarning.hx b/source/funkin/backend/system/macros/NewHaxeWarning.hx index ee467955..e6a98991 100644 --- a/source/funkin/backend/system/macros/NewHaxeWarning.hx +++ b/source/funkin/backend/system/macros/NewHaxeWarning.hx @@ -3,7 +3,7 @@ package funkin.backend.system.macros; #if macro class NewHaxeWarning { public static function warn() { - #if (haxe >= "4.3.0") + #if (haxe >= "4.3.0" && !display) Sys.println("===================="); Sys.println("[ WARNING ]"); Sys.println("Compiling with Haxe 4.3.0 isnt fully recommended yet, but it does work."); diff --git a/source/funkin/backend/system/updating/AsyncUpdater.hx b/source/funkin/backend/system/updating/AsyncUpdater.hx index af7cfff5..04dbafe8 100644 --- a/source/funkin/backend/system/updating/AsyncUpdater.hx +++ b/source/funkin/backend/system/updating/AsyncUpdater.hx @@ -101,7 +101,7 @@ class AsyncUpdater { progress.files = files.length; progress.step = DOWNLOADING_ASSETS; trace('starting assets download'); - doFile([for(e in files) e], [for(e in fileNames) e], function() { + doFile([for(e in files) e], fileNames.copy(), function() { progress.curFile = -1; progress.curFileName = null; progress.files = 1; diff --git a/source/funkin/backend/utils/CoolUtil.hx b/source/funkin/backend/utils/CoolUtil.hx index 4817bf5d..58bf7bae 100644 --- a/source/funkin/backend/utils/CoolUtil.hx +++ b/source/funkin/backend/utils/CoolUtil.hx @@ -207,7 +207,7 @@ class CoolUtil * @return String Result without any kind of IP */ public static inline function removeIP(msg:String):String { - return ~/\d+.\d+.\d+.\d+/.replace(msg, "[Your IP]"); // For now its just IPs but who knows in the future.. - Nex + return ~/\d+.\d+.\d+.\d+/.replace(msg, "[Your IP]"); // For now its just IPs but who knows in the future.. - Nex } /** diff --git a/source/funkin/backend/utils/MemoryUtil.hx b/source/funkin/backend/utils/MemoryUtil.hx index 842c7d71..cc8fb9d2 100644 --- a/source/funkin/backend/utils/MemoryUtil.hx +++ b/source/funkin/backend/utils/MemoryUtil.hx @@ -134,7 +134,7 @@ class MemoryUtil { if (process.exitCode() != 0) return "Unknown"; var lines = process.stdout.readAll().toString().split("\n"); for (line in lines) { - if (line.indexOf("Type:") == 0) { + if (line.startsWith("Type:")) { return line.substring("Type:".length).trim(); } } diff --git a/source/funkin/backend/utils/XMLUtil.hx b/source/funkin/backend/utils/XMLUtil.hx index 23ed0516..2f314e78 100644 --- a/source/funkin/backend/utils/XMLUtil.hx +++ b/source/funkin/backend/utils/XMLUtil.hx @@ -285,10 +285,12 @@ class XMLUtil { } /** + * Trims and removes spacing from the nodeValue in the XML + * * WARNING: will edit directly the node! */ public static function fixSpacingInNode(node:Access):Access { - var arr = [for(x in node.x) x]; + var arr = Lambda.array(node.x); for(i => n in arr) { if(n.nodeType == PCData) { if(i == 0) n.nodeValue = n.nodeValue.ltrim(); diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx index 1071763a..c20382d8 100644 --- a/source/funkin/editors/charter/Charter.hx +++ b/source/funkin/editors/charter/Charter.hx @@ -1811,7 +1811,7 @@ class Charter extends UIState { public inline function __fixSelection(selection:Selection):Selection { var newSelection:Selection = new Selection(); - for (s in selection) if (newSelection.indexOf(s) == -1) newSelection.push(s); + for (s in selection) if (!newSelection.contains(s)) newSelection.push(s); return newSelection.filter((s:ICharterSelectable) -> {return s != null;}); } diff --git a/source/funkin/editors/charter/CharterAutoSaveUI.hx b/source/funkin/editors/charter/CharterAutoSaveUI.hx index d412bc16..5f3ed9b8 100644 --- a/source/funkin/editors/charter/CharterAutoSaveUI.hx +++ b/source/funkin/editors/charter/CharterAutoSaveUI.hx @@ -31,7 +31,7 @@ class CharterAutoSaveUI extends UISliceSprite { progressBarBack = new FlxSprite(x + 10, y + bHeight - 20).makeGraphic(Std.int(bWidth-20), 10, 0x00000000, true); progressBarBack.drawRoundRect(0, 0, progressBarBack.width, progressBarBack.height, 4, 6, 0xFF727272, null, {smoothing: false}); progressBarBack.drawRoundRect(1, 1, progressBarBack.width-2, progressBarBack.height-2, 4, 6, 0xFF0D0D0D, null, {smoothing: false}); - members.push(progressBarBack); progressBarBack.antialiasing = false; + members.push(progressBarBack); progressBarBack.antialiasing = false; progressBar = new FlxSprite(x + 10, y + bHeight - 20).makeGraphic(Std.int(bWidth-20), 10, 0x00000000, true); progressBar.drawRoundRect(0, 0, progressBar.width, progressBar.height, 4, 6, 0xFF727272, null, {smoothing: false}); @@ -65,7 +65,7 @@ class CharterAutoSaveUI extends UISliceSprite { public function startAutoSave(time:Float, sucessText:String) { appearAnimation(); - + __tween = FlxTween.num(0, 1, time, null, (v:Float) -> { if ((progress = v) < .95) { autosavingText.text = 'Autosaving in ${Math.min(Math.round(time), 1+Math.floor(Math.abs(time-(progress*time))))} seconds'; @@ -100,7 +100,7 @@ class CharterAutoSaveUI extends UISliceSprite { autosavingText.follow(this, 12+10+4, 8); autosavingText.alpha = alpha; - + for (bar in [progressBar, progressBarBack]) { bar.follow(this, 10, bHeight-20); bar.alpha = alpha; diff --git a/source/funkin/editors/charter/CharterBackdropGroup.hx b/source/funkin/editors/charter/CharterBackdropGroup.hx index e9240ad1..21eeb90f 100644 --- a/source/funkin/editors/charter/CharterBackdropGroup.hx +++ b/source/funkin/editors/charter/CharterBackdropGroup.hx @@ -253,7 +253,7 @@ class CharterBackdropDummy extends UISprite { public override function draw() { @:privateAccess - __lastDrawCameras = [for(c in cameras) c]; + __lastDrawCameras = cameras.copy(); } } diff --git a/source/funkin/editors/ui/UISprite.hx b/source/funkin/editors/ui/UISprite.hx index 5a41cec3..1246e6de 100644 --- a/source/funkin/editors/ui/UISprite.hx +++ b/source/funkin/editors/ui/UISprite.hx @@ -69,7 +69,7 @@ class UISprite extends FlxSprite { public function drawSuper() { super.draw(); - __lastDrawCameras = [for(c in cameras) c]; + __lastDrawCameras = cameras.copy(); } public function drawMembers() { diff --git a/source/funkin/game/Character.hx b/source/funkin/game/Character.hx index 38d43b63..2f6d0a7e 100644 --- a/source/funkin/game/Character.hx +++ b/source/funkin/game/Character.hx @@ -25,8 +25,6 @@ using StringTools; @:allow(funkin.game.PlayState) class Character extends FunkinSprite implements IBeatReceiver implements IOffsetCompatible { - public var extra:Map = []; - private var __stunnedTime:Float = 0; private var __lockAnimThisFrame:Bool = false; @@ -407,11 +405,10 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset if (hasInterval) beatInterval = Std.parseInt(xml.x.get("interval")); var tempList = ["isPlayer", "isGF", "x", "y", "gameOverChar", "camx", "camy", "holdTime", "flipX", "icon", "color", "scale", "antialiasing", "sprite", "interval"]; - var atts = [for (i in xml.x.attributes()) i]; + var atts = xml.x.attributes(); for (i in atts) - if (!tempList.contains(i)) { + if (!tempList.contains(i)) extra[i] = xml.x.get(i); - } loadSprite(Paths.image('characters/$sprite')); @@ -453,7 +450,7 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset for (name in animsOrder) if (animDatas.exists(name)) anims.push(animDatas.get(name)); } else - anims = [for (anim in animDatas) anim]; + anims = Lambda.array(animDatas); for (anim in anims) { diff --git a/source/funkin/game/Note.hx b/source/funkin/game/Note.hx index b8baf48e..d541015d 100644 --- a/source/funkin/game/Note.hx +++ b/source/funkin/game/Note.hx @@ -27,7 +27,7 @@ class Note extends FlxSprite return strumLine = strLine; } - private function get_mustPress():Bool { + private inline function get_mustPress():Bool { return false; } public var noteData:Int = 0; @@ -191,7 +191,6 @@ class Note extends FlxSprite } public var lastScrollSpeed:Null = null; - public var angleOffsets:Bool = true; public var gapFix:Single = 0; public var useAntialiasingFix(get, set):Bool; inline function set_useAntialiasingFix(v:Bool) { @@ -290,7 +289,7 @@ class Note extends FlxSprite setClipRect(swagRect); } - public function setClipRect(rect:FlxRect) { + public inline function setClipRect(rect:FlxRect) { this.clipRect = rect; } diff --git a/source/funkin/game/NoteGroup.hx b/source/funkin/game/NoteGroup.hx index 0d45a41f..98b6477e 100644 --- a/source/funkin/game/NoteGroup.hx +++ b/source/funkin/game/NoteGroup.hx @@ -106,8 +106,7 @@ class NoteGroup extends FlxTypedGroup { if (members == null) return null; - // TODO: maybe lastIndexOf - var index:Int = members.indexOfFromLast(Object); + var index:Int = members.lastIndexOf(Object); if (index < 0) return null; diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index f735fad0..e213ae11 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -967,7 +967,7 @@ class PlayState extends MusicBeatState { if (songData == null) songData = SONG; - events = songData.events != null ? [for(e in songData.events) e] : []; + events = songData.events != null ? songData.events.copy() : []; // get first camera focus for(e in events) { if (e.time > 10) break; @@ -1678,8 +1678,9 @@ class PlayState extends MusicBeatState } public function displayRating(myRating:String, ?evt:NoteHitEvent = null):Void { - var pre:String = evt != null ? evt.ratingPrefix : ""; - var suf:String = evt != null ? evt.ratingSuffix : ""; + var hasEvent = evt != null; + var pre:String = hasEvent ? evt.ratingPrefix : ""; + var suf:String = hasEvent ? evt.ratingSuffix : ""; var rating:FlxSprite = comboGroup.recycleLoop(FlxSprite); rating.resetSprite(comboGroup.x + -40, comboGroup.y + -60); @@ -1687,7 +1688,7 @@ class PlayState extends MusicBeatState rating.acceleration.y = 550; rating.velocity.y -= FlxG.random.int(140, 175); rating.velocity.x -= FlxG.random.int(0, 10); - if (evt != null) { + if (hasEvent) { rating.scale.set(evt.ratingScale, evt.ratingScale); rating.antialiasing = evt.ratingAntialiasing; } @@ -1702,8 +1703,9 @@ class PlayState extends MusicBeatState } public function displayCombo(?evt:NoteHitEvent = null):Void { - var pre:String = evt != null ? evt.ratingPrefix : ""; - var suf:String = evt != null ? evt.ratingSuffix : ""; + var hasEvent = evt != null; + var pre:String = hasEvent ? evt.ratingPrefix : ""; + var suf:String = hasEvent ? evt.ratingSuffix : ""; var separatedScore:String = Std.string(combo).addZeros(3); @@ -1715,7 +1717,7 @@ class PlayState extends MusicBeatState comboSpr.velocity.y -= 150; comboSpr.velocity.x += FlxG.random.int(1, 10); - if (evt != null) { + if (hasEvent) { comboSpr.scale.set(evt.ratingScale, evt.ratingScale); comboSpr.antialiasing = evt.ratingAntialiasing; } @@ -1734,7 +1736,7 @@ class PlayState extends MusicBeatState { var numScore:FlxSprite = comboGroup.recycleLoop(FlxSprite).loadAnimatedGraphic(Paths.image('${pre}num${separatedScore.charAt(i)}${suf}')); numScore.resetSprite(comboGroup.x + (43 * i) - 90, comboGroup.y + 80); - if (evt != null) { + if (hasEvent) { numScore.antialiasing = evt.numAntialiasing; numScore.scale.set(evt.numScale, evt.numScale); } diff --git a/source/funkin/game/Strum.hx b/source/funkin/game/Strum.hx index e2b6ccd0..0e179f71 100644 --- a/source/funkin/game/Strum.hx +++ b/source/funkin/game/Strum.hx @@ -74,7 +74,7 @@ class Strum extends FlxSprite { } public override function draw() { - lastDrawCameras = [for(c in cameras) c]; + lastDrawCameras = cameras.copy(); super.draw(); } @@ -159,7 +159,7 @@ class Strum extends FlxSprite { centerOffsets(); centerOrigin(); } - public function getAnim() { + public inline function getAnim() { return animation.name; } } \ No newline at end of file diff --git a/source/lime/system/System.hx b/source/lime/system/System.hx index 34599615..59b71a83 100644 --- a/source/lime/system/System.hx +++ b/source/lime/system/System.hx @@ -536,6 +536,7 @@ class System #if (sys && !macro) funkin.backend.utils.NativeAPI.registerAsDPICompatible(); funkin.backend.system.CommandLineHandler.parseCommandLine(Sys.args()); + funkin.backend.system.Main.fixWorkingDirectory(); #end if (__applicationEntryPoint == null)