mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-12-23 00:12:36 +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 {
|
class Analytics {
|
||||||
static var umami = "https://analytics.randomityguy.me/api/send";
|
static var umami = "https://analytics.randomityguy.me/api/send";
|
||||||
|
|
||||||
|
public static function setURL(url:String) {
|
||||||
|
umami = url;
|
||||||
|
}
|
||||||
|
|
||||||
public static function trackSingle(eventName:String) {
|
public static function trackSingle(eventName:String) {
|
||||||
var p = payload(eventName, null);
|
var p = payload(eventName, null);
|
||||||
var json = Json.stringify(p);
|
var json = Json.stringify(p);
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,10 @@ class Leaderboards {
|
||||||
static var host = "https://lb.randomityguy.me";
|
static var host = "https://lb.randomityguy.me";
|
||||||
static var game = "Ultra";
|
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) {
|
public static function submitScore(mission:String, score:Float, rewindUsed:Bool, needsReplayCb:(Bool, Int) -> Void) {
|
||||||
if (!StringTools.startsWith(mission, "data/"))
|
if (!StringTools.startsWith(mission, "data/"))
|
||||||
mission = "data/" + mission;
|
mission = "data/" + mission;
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ import src.Debug;
|
||||||
import src.Gamepad;
|
import src.Gamepad;
|
||||||
import src.Analytics;
|
import src.Analytics;
|
||||||
import src.PreviewWorld;
|
import src.PreviewWorld;
|
||||||
|
import src.Leaderboards;
|
||||||
|
|
||||||
@:publicFields
|
@:publicFields
|
||||||
class MarbleGame {
|
class MarbleGame {
|
||||||
|
|
@ -69,6 +70,8 @@ class MarbleGame {
|
||||||
|
|
||||||
var replayExitGui:Class<GuiControl>;
|
var replayExitGui:Class<GuiControl>;
|
||||||
|
|
||||||
|
var isDiscord:Bool = false;
|
||||||
|
|
||||||
public function new(scene2d:h2d.Scene, scene:h3d.scene.Scene) {
|
public function new(scene2d:h2d.Scene, scene:h3d.scene.Scene) {
|
||||||
Console.log("Initializing the game...");
|
Console.log("Initializing the game...");
|
||||||
canvas = new Canvas(scene2d, cast this);
|
canvas = new Canvas(scene2d, cast this);
|
||||||
|
|
@ -78,6 +81,13 @@ class MarbleGame {
|
||||||
this.touchInput = new TouchInput();
|
this.touchInput = new TouchInput();
|
||||||
|
|
||||||
#if js
|
#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
|
// Pause shit
|
||||||
if (Util.isTouchDevice())
|
if (Util.isTouchDevice())
|
||||||
this.touchInput.registerTouchInput();
|
this.touchInput.registerTouchInput();
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
package fs;
|
package fs;
|
||||||
|
|
||||||
|
import src.MarbleGame;
|
||||||
import hxd.fs.FileInput;
|
import hxd.fs.FileInput;
|
||||||
import hxd.net.BinaryLoader;
|
import hxd.net.BinaryLoader;
|
||||||
import hxd.impl.ArrayIterator;
|
import hxd.impl.ArrayIterator;
|
||||||
|
|
@ -130,24 +131,32 @@ class ManifestEntry extends FileEntry {
|
||||||
if (onReady != null)
|
if (onReady != null)
|
||||||
onReady();
|
onReady();
|
||||||
} else {
|
} else {
|
||||||
js.Browser.window.fetch(file).then((res:js.html.Response) -> {
|
var prefix = "";
|
||||||
return res.arrayBuffer();
|
if (MarbleGame.instance.isDiscord) {
|
||||||
}).then((buf:js.lib.ArrayBuffer) -> {
|
prefix = ".proxy/";
|
||||||
loaded = true;
|
}
|
||||||
bytes = Bytes.ofData(buf);
|
|
||||||
if (onReady != null)
|
js.Browser.window.fetch(prefix + file)
|
||||||
onReady();
|
.then((res:js.html.Response) -> {
|
||||||
}).catchError((e) -> {
|
|
||||||
// Try the original file path
|
|
||||||
js.Browser.window.fetch('data/' + originalFile).then((res:js.html.Response) -> {
|
|
||||||
return res.arrayBuffer();
|
return res.arrayBuffer();
|
||||||
}).then((buf:js.lib.ArrayBuffer) -> {
|
})
|
||||||
|
.then((buf:js.lib.ArrayBuffer) -> {
|
||||||
loaded = true;
|
loaded = true;
|
||||||
bytes = Bytes.ofData(buf);
|
bytes = Bytes.ofData(buf);
|
||||||
if (onReady != null)
|
if (onReady != null)
|
||||||
onReady();
|
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
|
#else
|
||||||
if (onReady != null)
|
if (onReady != null)
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,10 @@ class MasterServerClient {
|
||||||
var stopMutex:sys.thread.Mutex = new sys.thread.Mutex();
|
var stopMutex:sys.thread.Mutex = new sys.thread.Mutex();
|
||||||
#end
|
#end
|
||||||
|
|
||||||
|
public static function setServerIp(ip:String) {
|
||||||
|
serverIp = ip;
|
||||||
|
}
|
||||||
|
|
||||||
public function new(onOpenFunc:() -> Void, onErrorFunc:() -> Void) {
|
public function new(onOpenFunc:() -> Void, onErrorFunc:() -> Void) {
|
||||||
#if hl
|
#if hl
|
||||||
wsThread = sys.thread.Thread.create(() -> {
|
wsThread = sys.thread.Thread.create(() -> {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue