Merge branch 'main' into translations-system
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package funkin.backend.utils;
|
||||
|
||||
import flixel.util.FlxSignal.FlxTypedSignal;
|
||||
import flixel.sound.FlxSound;
|
||||
import flixel.util.typeLimit.OneOfTwo;
|
||||
import funkin.backend.scripting.*; // lazy
|
||||
@@ -107,14 +108,28 @@ class DiscordUtil
|
||||
|
||||
public static function loadScript()
|
||||
{
|
||||
#if DISCORD_RPC
|
||||
if (script != null)
|
||||
{
|
||||
call("destroy");
|
||||
script = FlxDestroyUtil.destroy(script);
|
||||
}
|
||||
script = Script.create(Paths.script('data/discord'));
|
||||
script.set("ActivityType", {
|
||||
Playing: ActivityType.Playing,
|
||||
PLAYING: ActivityType.Playing,
|
||||
Streaming: ActivityType.Streaming,
|
||||
STREAMING: ActivityType.Streaming,
|
||||
Watching: ActivityType.Watching,
|
||||
WATCHING: ActivityType.Watching,
|
||||
Listening: ActivityType.Listening,
|
||||
LISTENING: ActivityType.Listening,
|
||||
Competing: ActivityType.Competing,
|
||||
COMPETING: ActivityType.Competing
|
||||
});
|
||||
// script.setParent(DiscordUtil);
|
||||
script.load();
|
||||
#end
|
||||
}
|
||||
|
||||
public static function changePresence(details:String, state:String, ?smallImageKey:String)
|
||||
@@ -218,6 +233,8 @@ class DiscordUtil
|
||||
Utils.safeSetWrapper(dp.joinSecret, data.joinSecret, fixString);
|
||||
Utils.safeSetWrapper(dp.spectateSecret, data.spectateSecret, fixString);
|
||||
Utils.safeSet(dp.instance, data.instance);
|
||||
Utils.safeSet(dp.activityType, data.activityType);
|
||||
Utils.safeSetWrapper(dp.streamUrl, data.streamUrl, fixString);
|
||||
if (data.matchSecret == null && data.joinSecret == null && data.spectateSecret == null)
|
||||
{
|
||||
Utils.safeSetWrapper(dp.button1Label, data.button1Label, fixString);
|
||||
@@ -252,6 +269,7 @@ class DiscordUtil
|
||||
handlers.joinGame = cpp.Function.fromStaticFunction(onJoin);
|
||||
handlers.joinRequest = cpp.Function.fromStaticFunction(onJoinReq);
|
||||
handlers.spectateGame = cpp.Function.fromStaticFunction(onSpectate);
|
||||
handlers.anyResponse = cpp.Function.fromStaticFunction(onAnyResponse);
|
||||
Discord.Initialize(id, cpp.RawPointer.addressOf(handlers), 1, null);
|
||||
stopThread = false;
|
||||
|
||||
@@ -309,7 +327,7 @@ class DiscordUtil
|
||||
Logs.logText(")")
|
||||
], INFO);
|
||||
|
||||
call("onReady", [errorCode, cast(finalMsg, String)]);
|
||||
call("onDisconnected", [errorCode, cast(finalMsg, String)]);
|
||||
}
|
||||
|
||||
private static function onError(errorCode:Int, message:cpp.ConstCharStar):Void
|
||||
@@ -351,7 +369,38 @@ class DiscordUtil
|
||||
var req:DUser = DUser.initRaw(request);
|
||||
call("onJoinRequest", [req]);
|
||||
}
|
||||
|
||||
public static var anyResponse:FlxTypedSignal<String->Void> = new FlxTypedSignal<String->Void>();
|
||||
|
||||
private static function onAnyResponse(data:cpp.ConstCharStar):Void
|
||||
{
|
||||
call("onAnyResponse", [data]);
|
||||
anyResponse.dispatch(data);
|
||||
}
|
||||
#end
|
||||
|
||||
private static function getUUID():String {
|
||||
var uuid = new StringBuf();
|
||||
for (i in 0...16) {
|
||||
uuid.add(StringTools.hex(Math.floor(Math.random() * 16), 1));
|
||||
}
|
||||
return uuid.toString();
|
||||
}
|
||||
|
||||
public static function sendCustomCommand(data:Dynamic) {
|
||||
#if DISCORD_RPC
|
||||
if(data == null) return;
|
||||
if(data.nonce == null) data.nonce = getUUID();
|
||||
var json = Json.stringify(data);
|
||||
Discord.SendCustomCommand(json);
|
||||
#end
|
||||
}
|
||||
|
||||
public static function setDebugMode(mode:Bool) {
|
||||
#if DISCORD_RPC
|
||||
Discord.SetDebugMode(mode);
|
||||
#end
|
||||
}
|
||||
}
|
||||
|
||||
typedef DiscordJson =
|
||||
@@ -476,6 +525,8 @@ typedef DPresence =
|
||||
var ?button1Url:String; /* max 512 bytes */
|
||||
var ?button2Label:String; /* max 32 bytes */
|
||||
var ?button2Url:String; /* max 512 bytes */
|
||||
var ?activityType:ActivityType;
|
||||
var ?streamUrl:String; /* max 512 bytes */
|
||||
}
|
||||
|
||||
typedef DEvents =
|
||||
|
||||
Reference in New Issue
Block a user