Added display names and buttons

This commit is contained in:
NeeEoo
2024-03-24 04:24:14 +01:00
parent 9370d5da43
commit 4cc8f27734
4 changed files with 61 additions and 10 deletions
+9
View File
@@ -4,6 +4,15 @@ function onGameOver() {
DiscordUtil.changePresence('Game Over', PlayState.SONG.meta.displayName + " (" + PlayState.difficulty + ")");
}
function onDiscordPresenceUpdate(e) {
var data = e.presence;
if(data.button1Label == null)
data.button1Label = "Codename Engine Discord";
if(data.button1Url == null)
data.button1Url = "https://discord.gg/2NTCdsQvx4";
}
function onPlayStateUpdate() {
DiscordUtil.changeSongPresence(
PlayState.instance.detailsText,
+2 -1
View File
@@ -11,7 +11,8 @@
<!-- Other Libraries -->
<git name="hscript-improved" url="https://github.com/FNF-CNE-Devs/hscript-improved" ref="custom-classes" />
<git name="flxanimate" url="https://github.com/FNF-CNE-Devs/flxanimate" />
<lib name="hxdiscord_rpc" />
<git name="hxdiscord_rpc" url="https://github.com/NeeEoo/hxdiscord_rpc" ref="buttons" /> <!-- Temp until it gets added to main -->
<!-- <lib name="hxdiscord_rpc" /> -->
<lib name="hxvlc" />
<!-- Documentation and other features -->
+49 -8
View File
@@ -206,6 +206,13 @@ class DiscordUtil
Utils.safeSetWrapper(dp.joinSecret, data.joinSecret, fixString);
Utils.safeSetWrapper(dp.spectateSecret, data.spectateSecret, fixString);
Utils.safeSet(dp.instance, data.instance);
if (data.matchSecret == null && data.joinSecret == null && data.spectateSecret == null)
{
Utils.safeSetWrapper(dp.button1Label, data.button1Label, fixString);
Utils.safeSetWrapper(dp.button1Url, data.button1Url, fixString);
Utils.safeSetWrapper(dp.button2Label, data.button2Label, fixString);
Utils.safeSetWrapper(dp.button2Url, data.button2Url, fixString);
}
Discord.UpdatePresence(cpp.RawConstPointer.addressOf(dp));
#end
@@ -255,8 +262,8 @@ class DiscordUtil
Logs.traceColored([
Logs.logText("[Discord] ", BLUE),
Logs.logText("Connected to User ("),
Logs.logText(user.tag, GRAY),
Logs.logText("Connected to User " + user.globalName + " ("),
Logs.logText(user.handle, GRAY),
Logs.logText(")")
], INFO);
@@ -285,9 +292,7 @@ class DiscordUtil
Logs.traceColored([
Logs.logText("[Discord] ", BLUE),
Logs.logText("Error ("),
Logs.logText('$errorCode: $finalMsg', RED),
Logs.logText(")")
Logs.logText('Error ($errorCode: $finalMsg)', RED)
], ERROR);
call("onError", [errorCode, cast(finalMsg, String)]);
@@ -336,7 +341,7 @@ final class DUser
/**
* The username + discriminator if they have it
**/
public var tag:String;
public var handle:String;
/**
* The user id, aka 860561967383445535
@@ -358,6 +363,26 @@ final class DUser
**/
public var avatar:String;
/**
* The user's display name
**/
public var globalName:String;
/**
* If the user is a bot or not
**/
public var bot:Bool;
/**
* Idk check discord docs
**/
public var flags:Int;
/**
* If the user has nitro
**/
public var premium:NitroType;
private function new()
{
}
@@ -374,11 +399,15 @@ final class DUser
d.username = userData.username;
d.discriminator = Std.parseInt(userData.discriminator);
d.avatar = userData.avatar;
d.globalName = userData.globalName;
d.bot = userData.bot;
d.flags = userData.flags;
d.premium = userData.premium;
if (d.discriminator != 0)
d.tag = '${d.username}#${d.discriminator}';
d.handle = '${d.username}#${d.discriminator}';
else
d.tag = '${d.username}';
d.handle = '${d.username}';
return d;
}
@@ -389,6 +418,14 @@ final class DUser
return BitmapData.fromBytes(HttpUtil.requestBytes('https://cdn.discordapp.com/avatars/$userId/$avatar.png?size=$size'));
}
enum abstract NitroType(Int) to Int from Int
{
var NONE = 0;
var NITRO_CLASSIC = 1;
var NITRO = 2;
var NITRO_BASIC = 3;
}
typedef DPresence =
{
var ?state:String; /* max 128 bytes */
@@ -407,6 +444,10 @@ typedef DPresence =
var ?joinSecret:String; /* max 128 bytes */
var ?spectateSecret:String; /* max 128 bytes */
var ?instance:OneOfTwo<Int, cpp.Int8>;
var ?button1Label:String; /* max 32 bytes */
var ?button1Url:String; /* max 512 bytes */
var ?button2Label:String; /* max 32 bytes */
var ?button2Url:String; /* max 512 bytes */
}
typedef DEvents =
+1 -1
View File
@@ -530,7 +530,7 @@ class Charter extends UIState {
notesGroup.autoSort = false;
var noteCount:Int = 0;
for (strL in PlayState.SONG.strumLines)
for (note in strL.notes) noteCount++;
noteCount += strL.notes.length;
notesGroup.preallocate(noteCount);
var notesCreated:Int = 0;