From cbbb598f52b3f7c0f156cf72cd03e165aa38a4f1 Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Fri, 24 Jan 2025 01:51:25 +0100 Subject: [PATCH] Added some more flags --- source/funkin/backend/scripting/Script.hx | 2 +- source/funkin/backend/shaders/CustomShader.hx | 3 +- source/funkin/backend/shaders/FunkinShader.hx | 5 ++- .../backend/system/CommandLineHandler.hx | 2 + source/funkin/backend/system/Flags.hx | 14 +++++- source/funkin/backend/system/Main.hx | 2 - source/funkin/backend/system/MainState.hx | 1 + .../backend/system/framerate/MemoryCounter.hx | 2 +- .../backend/system/macros/GitCommitMacro.hx | 43 +++++++++++++++++++ .../backend/system/macros/HashLinkFixer.hx | 3 -- .../backend/system/updating/UpdateUtil.hx | 7 +-- source/funkin/backend/utils/HttpUtil.hx | 2 +- source/funkin/backend/utils/WindowUtils.hx | 2 +- source/funkin/editors/EditorPicker.hx | 4 +- source/funkin/menus/credits/CreditsMain.hx | 2 +- 15 files changed, 73 insertions(+), 21 deletions(-) diff --git a/source/funkin/backend/scripting/Script.hx b/source/funkin/backend/scripting/Script.hx index f77f17d3..be62b4ad 100644 --- a/source/funkin/backend/scripting/Script.hx +++ b/source/funkin/backend/scripting/Script.hx @@ -151,7 +151,7 @@ class Script extends FlxBasic implements IFlxDestroyable { public static function getDefaultPreprocessors():Map { var defines = funkin.backend.system.macros.DefinesMacro.defines; defines.set("CODENAME_ENGINE", true); - defines.set("CODENAME_VER", Application.current.meta.get('version')); + defines.set("CODENAME_VER", Flags.VERSION); defines.set("CODENAME_BUILD", 2675); // 2675 being the last build num before it was removed defines.set("CODENAME_COMMIT", Flags.COMMIT_NUMBER); return defines; diff --git a/source/funkin/backend/shaders/CustomShader.hx b/source/funkin/backend/shaders/CustomShader.hx index 0166e08e..0a53df92 100644 --- a/source/funkin/backend/shaders/CustomShader.hx +++ b/source/funkin/backend/shaders/CustomShader.hx @@ -19,7 +19,8 @@ class CustomShader extends FunkinShader { * @param name Name of the frag and vert files. * @param glslVersion GLSL version to use. Defaults to `120`. */ - public function new(name:String, glslVersion:String = "120") { + public function new(name:String, glslVersion:String = null) { + if (glslVersion == null) glslVersion = Flags.DEFAULT_GLSL_VERSION; var fragShaderPath = Paths.fragShader(name); var vertShaderPath = Paths.vertShader(name); var fragCode = Assets.exists(fragShaderPath) ? Assets.getText(fragShaderPath) : null; diff --git a/source/funkin/backend/shaders/FunkinShader.hx b/source/funkin/backend/shaders/FunkinShader.hx index d3af27b5..fb3f9201 100644 --- a/source/funkin/backend/shaders/FunkinShader.hx +++ b/source/funkin/backend/shaders/FunkinShader.hx @@ -26,7 +26,7 @@ class FunkinShader extends FlxShader implements IHScriptCustomBehaviour { public var onGLUpdate:FlxTypedSignalVoid> = new FlxTypedSignalVoid>(); public var onProcessGLData:FlxTypedSignal<(String, String)->Void> = new FlxTypedSignal<(String, String)->Void>(); - public var glslVer:String = "120"; + public var glslVer:String = Flags.DEFAULT_GLSL_VERSION; public var fileName:String = "FunkinShader"; public var fragFileName:String = "FunkinShader"; public var vertFileName:String = "FunkinShader"; @@ -42,7 +42,8 @@ class FunkinShader extends FlxShader implements IHScriptCustomBehaviour { * @param vert Vertex source (pass `null` to use default) * @param glslVer Version of GLSL to use (defaults to 120) */ - public override function new(frag:String, vert:String, glslVer:String = "120") { + public override function new(frag:String, vert:String, glslVer:String = null) { + if (glslVer == null) glslVer = Flags.DEFAULT_GLSL_VERSION; if (frag == null) frag = ShaderTemplates.defaultFragmentSource; if (vert == null) vert = ShaderTemplates.defaultVertexSource; this.glFragmentSource = frag; diff --git a/source/funkin/backend/system/CommandLineHandler.hx b/source/funkin/backend/system/CommandLineHandler.hx index 3690b6a2..4b26f6d7 100644 --- a/source/funkin/backend/system/CommandLineHandler.hx +++ b/source/funkin/backend/system/CommandLineHandler.hx @@ -64,6 +64,8 @@ class CommandLineHandler { Main.noCwdFix = true; case "-livereload": // do nothing + case "-verbose": + // do nothing default: Sys.println("Unknown command"); } diff --git a/source/funkin/backend/system/Flags.hx b/source/funkin/backend/system/Flags.hx index 1f3d3f84..bfec5e81 100644 --- a/source/funkin/backend/system/Flags.hx +++ b/source/funkin/backend/system/Flags.hx @@ -18,7 +18,11 @@ class Flags { public static var COMMIT_NUMBER:Int = GitCommitMacro.commitNumber; public static var COMMIT_HASH:String = GitCommitMacro.commitHash; public static var COMMIT_MESSAGE:String = 'Commit $COMMIT_NUMBER ($COMMIT_HASH)'; - @:lazy public static var VERSION_MESSAGE:String = 'Codename Engine v${Application.current.meta.get('version')}'; + + @:lazy public static var TITLE:String = Application.current.meta.get('title'); + @:lazy public static var VERSION:String = Application.current.meta.get('version'); + + @:lazy public static var VERSION_MESSAGE:String = 'Codename Engine v$VERSION'; public static var REPO_NAME:String = "CodenameEngine"; public static var REPO_OWNER:String = "CodenameCrew"; @@ -142,6 +146,14 @@ class Flags { public static var DEFAULT_PAUSE_SCRIPT:String = ""; @:also(funkin.game.GameOverSubstate.script) public static var DEFAULT_GAMEOVER_SCRIPT:String = ""; + + public static var URL_WIKI:String = "https://codename-engine.com/"; + public static var URL_EDITOR_FALLBACK:String = "https://www.youtube.com/watch?v=9Youam7GYdQ"; + public static var URL_FNF_ITCH:String = "https://ninja-muffin24.itch.io/funkin"; + + public static var DEFAULT_GLSL_VERSION:String = "120"; + @:also(funkin.backend.utils.HttpUtil.userAgent) + public static var USER_AGENT:String = 'request'; // -- End of Codename's Default Flags -- /** diff --git a/source/funkin/backend/system/Main.hx b/source/funkin/backend/system/Main.hx index 149a11e5..6509bbe6 100644 --- a/source/funkin/backend/system/Main.hx +++ b/source/funkin/backend/system/Main.hx @@ -174,8 +174,6 @@ class Main extends Sprite } public static function refreshAssets() @:privateAccess { - WindowUtils.resetTitle(); - var game = FlxG.game; var daSndTray = Type.createInstance(game._customSoundTray = funkin.menus.ui.FunkinSoundTray, []); var index:Int = game.numChildren - 1; diff --git a/source/funkin/backend/system/MainState.hx b/source/funkin/backend/system/MainState.hx index 0aa26a09..60227ef8 100644 --- a/source/funkin/backend/system/MainState.hx +++ b/source/funkin/backend/system/MainState.hx @@ -59,6 +59,7 @@ class MainState extends FlxState { Flags.load(); ModsFolder.onModSwitch.dispatch(ModsFolder.currentModFolder); // Loads global.hx MusicBeatTransition.script = Flags.DEFAULT_TRANSITION_SCRIPT; + WindowUtils.resetTitle(); Main.refreshAssets(); DiscordUtil.init(); EventsData.reloadEvents(); diff --git a/source/funkin/backend/system/framerate/MemoryCounter.hx b/source/funkin/backend/system/framerate/MemoryCounter.hx index 1c26a27d..a3bb39c8 100644 --- a/source/funkin/backend/system/framerate/MemoryCounter.hx +++ b/source/funkin/backend/system/framerate/MemoryCounter.hx @@ -21,7 +21,7 @@ class MemoryCounter extends Sprite { label.autoSize = LEFT; label.x = 0; label.y = 0; - label.text = "FPS"; + label.text = "MEM"; label.multiline = label.wordWrap = false; label.defaultTextFormat = new TextFormat(Framerate.fontName, 12, -1); label.selectable = false; diff --git a/source/funkin/backend/system/macros/GitCommitMacro.hx b/source/funkin/backend/system/macros/GitCommitMacro.hx index 11f32152..8b275499 100644 --- a/source/funkin/backend/system/macros/GitCommitMacro.hx +++ b/source/funkin/backend/system/macros/GitCommitMacro.hx @@ -29,6 +29,14 @@ class GitCommitMacro { * Returns the current commit date + time **/ public static var commitDate(get, never):Date; + /** + * Returns the current branch name + **/ + public static var currentBranch(get, never):String; + /** + * Returns if there are uncommitted changes + **/ + public static var hasUncommittedChanges(get, never):Bool; // GETTERS #if REGION @@ -46,6 +54,11 @@ class GitCommitMacro { return __getCommitAuthor(); private static inline function get_commitDate() return __getCommitDate(); + + private static inline function get_currentBranch() + return __getCurrentBranch(); + private static inline function get_hasUncommittedChanges() + return __getHasUncommittedChanges(); #end // INTERNAL MACROS @@ -149,5 +162,35 @@ class GitCommitMacro { return macro Date.fromString("1970-01-01T00:00:00"); // failed to parse date #end } + + private static macro function __getCurrentBranch() { + #if display + return macro $v{"-"}; + #else + try { + var process = new Process("git", ["rev-parse", "--abbrev-ref", "HEAD"], false); + if (process.exitCode() != 0) + throw 'Could not fetch current branch'; + + return macro $v{process.stdout.readLine().toString()}; + } catch(e) {} + return macro $v{"-"} + #end + } + + private static macro function __getHasUncommittedChanges() { + #if display + return macro $v{false}; + #else + try { + var process = new Process("git", ["status", "--porcelain"], false); + if (process.exitCode() != 0) + throw 'Could not fetch current branch'; + + return macro $v{process.stdout.readLine().toString() != ""}; + } catch(e) {} + return macro $v{false} + #end + } #end } \ No newline at end of file diff --git a/source/funkin/backend/system/macros/HashLinkFixer.hx b/source/funkin/backend/system/macros/HashLinkFixer.hx index 0a46990b..27742c60 100644 --- a/source/funkin/backend/system/macros/HashLinkFixer.hx +++ b/source/funkin/backend/system/macros/HashLinkFixer.hx @@ -151,7 +151,4 @@ class HashLinkFixer { return fields; } } -#else -class HashLinkFixer { -} #end \ No newline at end of file diff --git a/source/funkin/backend/system/updating/UpdateUtil.hx b/source/funkin/backend/system/updating/UpdateUtil.hx index 9515b990..8118ae8e 100644 --- a/source/funkin/backend/system/updating/UpdateUtil.hx +++ b/source/funkin/backend/system/updating/UpdateUtil.hx @@ -9,9 +9,6 @@ import sys.FileSystem; using funkin.backend.system.github.GitHub; class UpdateUtil { - public static final repoOwner:String = "YoshiCrafter29"; - public static final repoName:String = "CodenameTestRepo"; - public static function init() { // deletes old bak file if it exists #if sys @@ -22,12 +19,12 @@ class UpdateUtil { } public static function checkForUpdates():UpdateCheckCallback { - var curTag = 'v${Application.current.meta.get('version')}'; + var curTag = 'v${Flags.VERSION}'; trace(curTag); var error = false; - var newUpdates = __doReleaseFiltering(GitHub.getReleases(repoOwner, repoName, function(e) { + var newUpdates = __doReleaseFiltering(GitHub.getReleases(Flags.REPO_NAME, Flags.REPO_OWNER, function(e) { error = true; }), curTag); diff --git a/source/funkin/backend/utils/HttpUtil.hx b/source/funkin/backend/utils/HttpUtil.hx index f2d3caf8..d5e9db92 100644 --- a/source/funkin/backend/utils/HttpUtil.hx +++ b/source/funkin/backend/utils/HttpUtil.hx @@ -4,7 +4,7 @@ import haxe.Http; class HttpUtil { - public static var userAgent:String = "request"; + public static var userAgent:String = Flags.USER_AGENT; public static function requestText(url:String) { var r = null; diff --git a/source/funkin/backend/utils/WindowUtils.hx b/source/funkin/backend/utils/WindowUtils.hx index 43cd5f8d..c88b0d38 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 = Lib.application.meta["name"]; + title = Flags.TITLE; resetAffixes(); } diff --git a/source/funkin/editors/EditorPicker.hx b/source/funkin/editors/EditorPicker.hx index a57cc740..f9350780 100644 --- a/source/funkin/editors/EditorPicker.hx +++ b/source/funkin/editors/EditorPicker.hx @@ -34,7 +34,7 @@ class EditorPicker extends MusicBeatSubstate { id: "wiki", state: null, onClick: function() { - CoolUtil.openURL("https://codename-engine.com/"); + CoolUtil.openURL(Flags.URL_WIKI); } }, { @@ -124,7 +124,7 @@ class EditorPicker extends MusicBeatSubstate { }); }); } else { - CoolUtil.openURL("https://www.youtube.com/watch?v=9Youam7GYdQ"); + CoolUtil.openURL(Flags.URL_EDITOR_FALLBACK); } } diff --git a/source/funkin/menus/credits/CreditsMain.hx b/source/funkin/menus/credits/CreditsMain.hx index d19df882..e447ef01 100644 --- a/source/funkin/menus/credits/CreditsMain.hx +++ b/source/funkin/menus/credits/CreditsMain.hx @@ -40,7 +40,7 @@ class CreditsMain extends TreeMenu { optionsTree.add(Type.createInstance(CreditsCodename, [])); })); items.push(new TextOption("Friday Night Funkin'", "Select this to open the itch.io page of the original game to donate!", function() { - CoolUtil.openURL("https://ninja-muffin24.itch.io/funkin"); + CoolUtil.openURL(Flags.URL_FNF_ITCH); })); main = new OptionsScreen('Credits', 'The people who made this possible!', items);