From efdf4c7002b5d12cb6aa13998fca602c4cfd5ca4 Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Sat, 12 Jul 2025 12:43:27 +0530 Subject: [PATCH] make this work with discord --- src/Analytics.hx | 4 ++++ src/Leaderboards.hx | 4 ++++ src/MarbleGame.hx | 10 ++++++++++ src/fs/ManifestFileSystem.hx | 33 +++++++++++++++++++++------------ src/net/MasterServerClient.hx | 4 ++++ 5 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/Analytics.hx b/src/Analytics.hx index d987a0f8..c24e9790 100644 --- a/src/Analytics.hx +++ b/src/Analytics.hx @@ -19,6 +19,10 @@ typedef PayloadData = { class Analytics { static var umami = "https://analytics.randomityguy.me/api/send"; + public static function setURL(url:String) { + umami = url; + } + public static function trackSingle(eventName:String) { var p = payload(eventName, null); var json = Json.stringify(p); diff --git a/src/Leaderboards.hx b/src/Leaderboards.hx index a7103bee..8187c2e3 100644 --- a/src/Leaderboards.hx +++ b/src/Leaderboards.hx @@ -31,6 +31,10 @@ class Leaderboards { static var host = "https://lb.randomityguy.me"; static var game = "Ultra"; + public static function setHost(url:String) { + host = url; + } + public static function submitScore(mission:String, score:Float, rewindUsed:Bool, needsReplayCb:(Bool, Int) -> Void) { if (!StringTools.startsWith(mission, "data/")) mission = "data/" + mission; diff --git a/src/MarbleGame.hx b/src/MarbleGame.hx index 809005e3..36f2fa4f 100644 --- a/src/MarbleGame.hx +++ b/src/MarbleGame.hx @@ -35,6 +35,7 @@ import src.Debug; import src.Gamepad; import src.Analytics; import src.PreviewWorld; +import src.Leaderboards; @:publicFields class MarbleGame { @@ -69,6 +70,8 @@ class MarbleGame { var replayExitGui:Class; + var isDiscord:Bool = false; + public function new(scene2d:h2d.Scene, scene:h3d.scene.Scene) { Console.log("Initializing the game..."); canvas = new Canvas(scene2d, cast this); @@ -78,6 +81,13 @@ class MarbleGame { this.touchInput = new TouchInput(); #if js + isDiscord = js.Browser.window.location.href.indexOf("discord.com") != -1; + if (isDiscord) { + Analytics.setURL(".proxy/analytics/api/send"); + Leaderboards.setHost(".proxy/lb"); + MasterServerClient.setServerIp(".proxy/mbomaster"); + } + // Pause shit if (Util.isTouchDevice()) this.touchInput.registerTouchInput(); diff --git a/src/fs/ManifestFileSystem.hx b/src/fs/ManifestFileSystem.hx index 91731951..0cdf8849 100644 --- a/src/fs/ManifestFileSystem.hx +++ b/src/fs/ManifestFileSystem.hx @@ -17,6 +17,7 @@ // SOFTWARE. package fs; +import src.MarbleGame; import hxd.fs.FileInput; import hxd.net.BinaryLoader; import hxd.impl.ArrayIterator; @@ -130,24 +131,32 @@ class ManifestEntry extends FileEntry { if (onReady != null) onReady(); } else { - js.Browser.window.fetch(file).then((res:js.html.Response) -> { - return res.arrayBuffer(); - }).then((buf:js.lib.ArrayBuffer) -> { - loaded = true; - bytes = Bytes.ofData(buf); - if (onReady != null) - onReady(); - }).catchError((e) -> { - // Try the original file path - js.Browser.window.fetch('data/' + originalFile).then((res:js.html.Response) -> { + var prefix = ""; + if (MarbleGame.instance.isDiscord) { + prefix = ".proxy/"; + } + + js.Browser.window.fetch(prefix + file) + .then((res:js.html.Response) -> { return res.arrayBuffer(); - }).then((buf:js.lib.ArrayBuffer) -> { + }) + .then((buf:js.lib.ArrayBuffer) -> { loaded = true; bytes = Bytes.ofData(buf); if (onReady != null) onReady(); + }) + .catchError((e) -> { + // Try the original file path + js.Browser.window.fetch(prefix + 'data/' + originalFile).then((res:js.html.Response) -> { + return res.arrayBuffer(); + }).then((buf:js.lib.ArrayBuffer) -> { + loaded = true; + bytes = Bytes.ofData(buf); + if (onReady != null) + onReady(); + }); }); - }); } #else if (onReady != null) diff --git a/src/net/MasterServerClient.hx b/src/net/MasterServerClient.hx index d9e511c5..3f01eddc 100644 --- a/src/net/MasterServerClient.hx +++ b/src/net/MasterServerClient.hx @@ -41,6 +41,10 @@ class MasterServerClient { var stopMutex:sys.thread.Mutex = new sys.thread.Mutex(); #end + public static function setServerIp(ip:String) { + serverIp = ip; + } + public function new(onOpenFunc:() -> Void, onErrorFunc:() -> Void) { #if hl wsThread = sys.thread.Thread.create(() -> {