From def7709b3bc7e0029a726c4f04c27411e936e0ee Mon Sep 17 00:00:00 2001 From: Joalor64 Date: Fri, 8 Nov 2024 08:59:57 -0500 Subject: [PATCH] refactor and small hscript fix --- docs/05 - adding-custom-credits.md | 2 +- source/backend/Utilities.hx | 10 ++++++++++ source/modding/Hscript.hx | 4 ++-- source/states/CreditsState.hx | 9 ++++----- source/states/UpdateState.hx | 9 +-------- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/docs/05 - adding-custom-credits.md b/docs/05 - adding-custom-credits.md index d6f4474..6485a7e 100644 --- a/docs/05 - adding-custom-credits.md +++ b/docs/05 - adding-custom-credits.md @@ -29,5 +29,5 @@ Explanation: * `name` - The user's name. * `iconData` - An array with the filename for their icon, and optional X and Y offsets for positioning the icon. * `textData` - Includes the user's contribution and an optional description. -* `urlData` - A list of links related to the user. Each entry is an array: the first element is the platform name, and the second is the URL. +* `urlData` - A list of links related to the user. Each entry is an array: the first element is the platform name, and the second is the URL, or you can set it to `nolink`. * `colors` - An array using RGB values to set the background to a custom color (`[R, G, B]`). \ No newline at end of file diff --git a/source/backend/Utilities.hx b/source/backend/Utilities.hx index 2816b71..066b518 100644 --- a/source/backend/Utilities.hx +++ b/source/backend/Utilities.hx @@ -35,6 +35,16 @@ class Utilities { } } + public static function openUrlPlease(url:String) { + #if linux + var cmd = Sys.command("xdg-open", [url]); + if (cmd != 0) cmd = Sys.command("/usr/bin/xdg-open", [url]); + Sys.command('/usr/bin/xdg-open', [url]); + #else + FlxG.openURL(url); + #end + } + public static function wait(milliseconds:Int, callback:Void->Void):Void { Timer.delay(callback, milliseconds); } diff --git a/source/modding/Hscript.hx b/source/modding/Hscript.hx index 565fee7..9edb0c7 100644 --- a/source/modding/Hscript.hx +++ b/source/modding/Hscript.hx @@ -61,8 +61,8 @@ class Hscript extends FlxBasic { setVariable('importScript', function(source:String) { var name:String = StringTools.replace(source, '.', '/'); - var script:Hscript = new Hscript(name, false); - script.execute(name, false); + var script:Hscript = new Hscript('$name.hxs', false); + script.execute('$name.hxs', false); return script.getAll(); }); diff --git a/source/states/CreditsState.hx b/source/states/CreditsState.hx index e9310a0..2920e1f 100644 --- a/source/states/CreditsState.hx +++ b/source/states/CreditsState.hx @@ -163,11 +163,10 @@ class CreditsState extends ExtendableState { updateSocial(Input.justPressed('left') ? -1 : 1); if (Input.justPressed('accept') && credData.users[curSelected].urlData[curSocial][1] != null) { - #if linux - Sys.command('/usr/bin/xdg-open', [credData.users[curSelected].urlData[curSocial][1]]); - #else - FlxG.openURL(credData.users[curSelected].urlData[curSocial][1]); - #end + if ((credData.users[curSelected].urlData[curSocial][1] == "nolink")) + FlxG.sound.play(Paths.sound('cancel')); + else + Utilities.openUrlPlease(credData.users[curSelected].urlData[curSocial][1]); } if (Input.justPressed('exit')) { diff --git a/source/states/UpdateState.hx b/source/states/UpdateState.hx index ff320fd..a481f7b 100644 --- a/source/states/UpdateState.hx +++ b/source/states/UpdateState.hx @@ -43,14 +43,7 @@ class UpdateState extends ExtendableState { ExtendableState.switchState(new TitleState()); if (!Input.justPressed('exit')) { FlxG.sound.play(Paths.sound('select')); - var url:String = "https://github.com/Joalor64GH/Rhythmo-SC/releases/latest"; - #if linux - var cmd = Sys.command("xdg-open", [url]); - if (cmd != 0) cmd = Sys.command("/usr/bin/xdg-open", [url]); - Sys.command('/usr/bin/xdg-open', [url]); - #else - FlxG.openURL(url); - #end + Utilities.openUrlPlease("https://github.com/Joalor64GH/Rhythmo-SC/releases/latest"); } else FlxG.sound.play(Paths.sound('cancel')); }