summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorPierre Bourdon <delroth@gmail.com>2018-08-19 14:43:39 +0200
committerPierre Bourdon <delroth@gmail.com>2018-08-19 14:53:40 +0200
commit4ecee3cb9900f7f1fc34b806965cc399f43d7f28 (patch)
tree9fe02c277b9b40226b366f0f2993d5dae04d1336 /Source
parent0fdb6f4267dd34fc15d49d1aeaffd6734851936d (diff)
DiscordPresence: use game-specific artwork if available
Since we don't have a way (AFAIK) to dynamically collect the list of available art assets, we hardcode a list of gameids with available artwork inside Dolphin. It's not great, but I don't think it's a terrible solution either. Art has to be manually uploaded to our Discord app configuration, and we have a limit of ~150 assets, so most likely we'll limit ourselves to a small set of popular games.
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/UICommon/DiscordPresence.cpp49
1 files changed, 42 insertions, 7 deletions
diff --git a/Source/Core/UICommon/DiscordPresence.cpp b/Source/Core/UICommon/DiscordPresence.cpp
index 5fb7ee676b..b39d372fa2 100644
--- a/Source/Core/UICommon/DiscordPresence.cpp
+++ b/Source/Core/UICommon/DiscordPresence.cpp
@@ -13,23 +13,28 @@
#ifdef USE_DISCORD_PRESENCE
+#include <algorithm>
+#include <cctype>
#include <ctime>
#include <discord-rpc/include/discord_rpc.h>
+#include <string>
#endif
namespace Discord
{
#ifdef USE_DISCORD_PRESENCE
-static Handler* event_handler = nullptr;
-static const char* username = "";
+namespace
+{
+Handler* event_handler = nullptr;
+const char* username = "";
-static void HandleDiscordReady(const DiscordUser* user)
+void HandleDiscordReady(const DiscordUser* user)
{
username = user->username;
}
-static void HandleDiscordJoinRequest(const DiscordUser* user)
+void HandleDiscordJoinRequest(const DiscordUser* user)
{
if (event_handler == nullptr)
return;
@@ -38,7 +43,7 @@ static void HandleDiscordJoinRequest(const DiscordUser* user)
event_handler->DiscordJoinRequest(user->userId, discord_tag, user->avatar);
}
-static void HandleDiscordJoin(const char* join_secret)
+void HandleDiscordJoin(const char* join_secret)
{
if (event_handler == nullptr)
return;
@@ -82,6 +87,25 @@ static void HandleDiscordJoin(const char* join_secret)
event_handler->DiscordJoin();
}
+
+std::string ArtworkForGameId(const std::string& gameid)
+{
+ static const std::set<std::string> REGISTERED_GAMES{
+ "GAL", // Super Smash Bros. Melee
+ };
+
+ std::string region_neutral_gameid = gameid.substr(0, 3);
+ if (REGISTERED_GAMES.count(region_neutral_gameid) != 0)
+ {
+ // Discord asset keys can only be lowercase.
+ std::transform(region_neutral_gameid.begin(), region_neutral_gameid.end(),
+ region_neutral_gameid.begin(), tolower);
+ return "game_" + region_neutral_gameid;
+ }
+ return "";
+}
+
+} // namespace
#endif
Discord::Handler::~Handler() = default;
@@ -130,10 +154,21 @@ void UpdateDiscordPresence(int party_size, SecretType type, const std::string& s
const std::string& title =
current_game.empty() ? SConfig::GetInstance().GetTitleDescription() : current_game;
+ std::string game_artwork = ArtworkForGameId(SConfig::GetInstance().GetGameID());
DiscordRichPresence discord_presence = {};
- discord_presence.largeImageKey = "dolphin_logo";
- discord_presence.largeImageText = "Dolphin is an emulator for the GameCube and the Wii.";
+ if (game_artwork.empty())
+ {
+ discord_presence.largeImageKey = "dolphin_logo";
+ discord_presence.largeImageText = "Dolphin is an emulator for the GameCube and the Wii.";
+ }
+ else
+ {
+ discord_presence.largeImageKey = game_artwork.c_str();
+ discord_presence.largeImageText = title.c_str();
+ discord_presence.smallImageKey = "dolphin_logo";
+ discord_presence.smallImageText = "Dolphin is an emulator for the GameCube and the Wii.";
+ }
discord_presence.details = title.empty() ? "Not in-game" : title.c_str();
discord_presence.startTimestamp = std::time(nullptr);