mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-12-22 16:02:38 +00:00
make this work with discord
This commit is contained in:
parent
98fab4029e
commit
efdf4c7002
5 changed files with 43 additions and 12 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<GuiControl>;
|
||||
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
// SOFTWARE.
|
||||
package fs;
|
||||
|
||||
import src.MarbleGame;
|
||||
import hxd.fs.FileInput;
|
||||
import hxd.net.BinaryLoader;
|
||||
import hxd.impl.ArrayIterator;
|
||||
|
|
@ -130,16 +131,24 @@ class ManifestEntry extends FileEntry {
|
|||
if (onReady != null)
|
||||
onReady();
|
||||
} else {
|
||||
js.Browser.window.fetch(file).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) -> {
|
||||
})
|
||||
.catchError((e) -> {
|
||||
// Try the original file path
|
||||
js.Browser.window.fetch('data/' + originalFile).then((res:js.html.Response) -> {
|
||||
js.Browser.window.fetch(prefix + 'data/' + originalFile).then((res:js.html.Response) -> {
|
||||
return res.arrayBuffer();
|
||||
}).then((buf:js.lib.ArrayBuffer) -> {
|
||||
loaded = true;
|
||||
|
|
|
|||
|
|
@ -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(() -> {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue