From 35aa8731d0e94a6dfb7f97eabbf950e066c51906 Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Thu, 19 Sep 2024 11:13:05 -0400 Subject: [PATCH] Better status messages, buttons, updated album art, basic chart editor support --- source/funkin/api/discord/DiscordClient.hx | 22 ++++-- source/funkin/play/PlayState.hx | 78 +++++++++++++------ .../ui/debug/charting/ChartEditorState.hx | 17 ++++ source/funkin/util/Constants.hx | 7 +- 4 files changed, 93 insertions(+), 31 deletions(-) diff --git a/source/funkin/api/discord/DiscordClient.hx b/source/funkin/api/discord/DiscordClient.hx index c722762b0..3b6e891d3 100644 --- a/source/funkin/api/discord/DiscordClient.hx +++ b/source/funkin/api/discord/DiscordClient.hx @@ -96,16 +96,28 @@ class DiscordClient // The large image displaying what the user is doing. // This should probably be album art. // IMPORTANT NOTE: This can be an asset key uploaded to Discord's developer panel OR any URL you like. + + // TODO: Make this use the song's album art. // presence.largeImageKey = "icon"; - presence.largeImageKey = "https://f4.bcbits.com/img/a3122193953_16.jpg"; + presence.largeImageKey = "https://f4.bcbits.com/img/a0746694746_16.jpg"; + // The small inset image for what the user is doing. // This can be the opponent's health icon? presence.smallImageKey = cast(params.smallImageKey, Null); - // Start timestamp, used to power elapsed/remaining data - // presence.startTimestamp - // End timestamp, used to power elapsed/remaining data - // presence.endTimestamp + // NOTE: In previous versions, this showed as "Elapsed", but now shows as playtime and doesn't look good + // presence.startTimestamp = time - 10; + // presence.endTimestamp = time + 30; + + final button1:DiscordButton = DiscordButton.create(); + button1.label = "Play on Web"; + button1.url = Constants.URL_NEWGROUNDS; + presence.buttons[0] = button1; + + final button2:DiscordButton = DiscordButton.create(); + button2.label = "Download"; + button2.url = Constants.URL_ITCH; + presence.buttons[1] = button2; return presence; } diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx index 22ba22b71..aeba619ff 100644 --- a/source/funkin/play/PlayState.hx +++ b/source/funkin/play/PlayState.hx @@ -447,10 +447,7 @@ class PlayState extends MusicBeatSubState #if FEATURE_DISCORD_RPC // Discord RPC variables - var discordRPCDifficulty:String = ''; var discordRPCIcon:String = ''; - var discordRPCDetailsText:String = ''; - var discordRPCDetailsPausedText:String = ''; #end /** @@ -986,8 +983,10 @@ class PlayState extends MusicBeatSubState #if FEATURE_DISCORD_RPC DiscordClient.instance.setPresence( { - state: '${currentChart.songName} (${discordRPCDifficulty})', - details: discordRPCDetailsPausedText, + details: 'Paused - ${buildDiscordRPCDetails()}', + + state: buildDiscordRPCState(), + smallImageKey: discordRPCIcon }); #end @@ -1080,8 +1079,8 @@ class PlayState extends MusicBeatSubState #if FEATURE_DISCORD_RPC DiscordClient.instance.setPresence( { - state: '${currentChart.songName} [${discordRPCDifficulty}]', - details: 'Game Over - ${discordRPCDetailsText}', + details: 'Game Over - ${buildDiscordRPCDetails()}', + state: buildDiscordRPCState(), smallImageKey: discordRPCIcon }); #end @@ -1300,8 +1299,8 @@ class PlayState extends MusicBeatSubState // currentSongLengthMs - Conductor.instance.songPosition); DiscordClient.instance.setPresence( { - state: '${currentChart.songName} [${discordRPCDifficulty}]', - details: discordRPCDetailsText, + state: buildDiscordRPCState(), + details: 'Paused - ${buildDiscordRPCDetails()}', smallImageKey: discordRPCIcon }); } @@ -1309,8 +1308,8 @@ class PlayState extends MusicBeatSubState { DiscordClient.instance.setPresence( { - state: '${currentChart.songName} [${discordRPCDifficulty}]', - details: discordRPCDetailsText, + state: buildDiscordRPCState(), + details: 'Paused - ${buildDiscordRPCDetails()}', smallImageKey: discordRPCIcon }); } @@ -1344,8 +1343,8 @@ class PlayState extends MusicBeatSubState { DiscordClient.instance.setPresence( { - state: '${currentChart.songName} [${discordRPCDifficulty}]', - details: discordRPCDetailsText, + state: buildDiscordRPCState(), + details: buildDiscordRPCDetails(), smallImageKey: discordRPCIcon }); } @@ -1353,8 +1352,8 @@ class PlayState extends MusicBeatSubState { DiscordClient.instance.setPresence( { - state: '${currentChart.songName} [${discordRPCDifficulty}]', - details: discordRPCDetailsText, + state: buildDiscordRPCState(), + details: buildDiscordRPCDetails(), smallImageKey: discordRPCIcon }); // DiscordClient.changePresence(detailsText, '${currentChart.songName} ($discordRPCDifficulty)', discordRPCIcon, true, @@ -1380,8 +1379,8 @@ class PlayState extends MusicBeatSubState { DiscordClient.instance.setPresence( { - state: '${currentChart.songName} [${discordRPCDifficulty}]', - details: discordRPCDetailsText, + state: buildDiscordRPCState(), + details: buildDiscordRPCDetails(), smallImageKey: discordRPCIcon }); } @@ -1801,22 +1800,51 @@ class PlayState extends MusicBeatSubState function initDiscord():Void { #if FEATURE_DISCORD_RPC - discordRPCDifficulty = PlayState.instance.currentDifficulty.replace('-', ' ').toTitleCase(); - // Determine the details strings once and reuse them. - discordRPCDetailsText = PlayStatePlaylist.isStoryMode ? 'Story Mode: Week ${PlayStatePlaylist.campaignId}' : 'Freeplay'; - discordRPCDetailsPausedText = 'Paused - $discordRPCDetailsText'; // Updating Discord Rich Presence. DiscordClient.instance.setPresence( { - state: '${currentChart.songName} [${discordRPCDifficulty}]', - details: discordRPCDetailsText, + state: buildDiscordRPCState(), + details: buildDiscordRPCDetails(), smallImageKey: discordRPCIcon }); #end } + function buildDiscordRPCDetails():String + { + if (PlayStatePlaylist.isStoryMode) + { + return 'Story Mode: ${PlayStatePlaylist.campaignTitle}'; + } + else + { + if (isChartingMode) + { + return 'Chart Editor [Playtest]'; + } + else if (isPracticeMode) + { + return 'Freeplay [Practice]'; + } + else if (isBotPlayMode) + { + return 'Freeplay [Bot Play]'; + } + else + { + return 'Freeplay'; + } + } + } + + function buildDiscordRPCState():String + { + var discordRPCDifficulty = PlayState.instance.currentDifficulty.replace('-', ' ').toTitleCase(); + return '${currentChart.songName} [${discordRPCDifficulty}]'; + } + function initPreciseInputs():Void { PreciseInputManager.instance.onInputPressed.add(onKeyPress); @@ -2010,8 +2038,8 @@ class PlayState extends MusicBeatSubState // Updating Discord Rich Presence (with Time Left) DiscordClient.instance.setPresence( { - state: '${currentChart.songName} (${discordRPCDifficulty})', - details: discordRPCDetailsText, + state: buildDiscordRPCState(), + details: buildDiscordRPCDetails(), smallImageKey: discordRPCIcon }); // DiscordClient.changePresence(detailsText, '${currentChart.songName} ($discordRPCDifficulty)', discordRPCIcon, true, currentSongLengthMs); diff --git a/source/funkin/ui/debug/charting/ChartEditorState.hx b/source/funkin/ui/debug/charting/ChartEditorState.hx index 2e259d3f5..458e5d5fb 100644 --- a/source/funkin/ui/debug/charting/ChartEditorState.hx +++ b/source/funkin/ui/debug/charting/ChartEditorState.hx @@ -2274,8 +2274,25 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState this.openBackupAvailableDialog(welcomeDialog); } } + + #if FEATURE_DISCORD_RPC + updateDiscordRPC(); + #end } + #if FEATURE_DISCORD_RPC + function updateDiscordRPC():Void + { + funkin.api.discord.DiscordClient.instance.setPresence( + { + // TODO: Make this display the song name and update when it changes. + // state: '${currentSongName} [${selectedDifficulty}]', + state: null, + details: 'Chart Editor [Charting]' + }); + } + #end + function setupWelcomeMusic() { this.welcomeMusic.loadEmbedded(Paths.music('chartEditorLoop/chartEditorLoop')); diff --git a/source/funkin/util/Constants.hx b/source/funkin/util/Constants.hx index cf58d191a..b2fa46aea 100644 --- a/source/funkin/util/Constants.hx +++ b/source/funkin/util/Constants.hx @@ -78,7 +78,12 @@ class Constants /** * Link to download the game on Itch.io. */ - public static final URL_ITCH:String = 'https://ninja-muffin24.itch.io/funkin/purchase'; + public static final URL_ITCH:String = 'https://ninja-muffin24.itch.io/funkin'; + + /** + * Link to play the game on Newgrounds. + */ + public static final URL_NEWGROUNDS:String = 'https://www.newgrounds.com/portal/view/770371'; /** * Link to the game's page on Kickstarter.