Merge pull request #1736 from oddMLan/discord-rpc-cleanup

Discord-rpc: Code cleanup
This commit is contained in:
zilmar 2020-05-05 19:37:21 +09:30 committed by GitHub
commit 21bf8ccf57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 35 deletions

View File

@ -260,6 +260,7 @@ void CSettings::AddHowToHandleSetting(const char * BaseDirectory)
AddHandler(Game_FullSpeed, new CSettingTypeTempBool(true, "Full Speed")); AddHandler(Game_FullSpeed, new CSettingTypeTempBool(true, "Full Speed"));
AddHandler(Game_UnalignedDMA, new CSettingTypeGame("Unaligned DMA", Rdb_UnalignedDMA)); AddHandler(Game_UnalignedDMA, new CSettingTypeGame("Unaligned DMA", Rdb_UnalignedDMA));
AddHandler(Game_RandomizeSIPIInterrupts, new CSettingTypeGame("Randomize SI/PI Interrupts", Rdb_RandomizeSIPIInterrupts)); AddHandler(Game_RandomizeSIPIInterrupts, new CSettingTypeGame("Randomize SI/PI Interrupts", Rdb_RandomizeSIPIInterrupts));
AddHandler(Game_RPCKey, new CSettingTypeTempString(""));
//User Interface //User Interface
AddHandler(UserInterface_ShowCPUPer, new CSettingTypeApplication("Settings", "Display CPU Usage", (uint32_t)false)); AddHandler(UserInterface_ShowCPUPer, new CSettingTypeApplication("Settings", "Display CPU Usage", (uint32_t)false));

View File

@ -28,55 +28,49 @@ void CDiscord::Init()
void CDiscord::Shutdown() void CDiscord::Shutdown()
{ {
Discord_ClearPresence();
Discord_Shutdown(); Discord_Shutdown();
} }
static stdstr GetTitle()
{
stdstr Default = "";
bool existsInRdb = g_Settings->LoadStringVal(Rdb_GoodName, Default);
if (existsInRdb)
return g_Settings->LoadStringVal(Rdb_GoodName);
else {
Default = CPath(g_Settings->LoadStringVal(Game_File)).GetName().c_str();
if (strstr(const_cast<char*>(Default.c_str()), "?") != NULL) {
return Default.substr(Default.find("?") + 1);
}
return Default;
}
}
void CDiscord::Update(bool bHaveGame) void CDiscord::Update(bool bHaveGame)
{ {
//Variables we use later //Variables we use later
//szState uses the Rdb_GoodName to display a proper game name over DiscordRPC //title uses the Rdb_GoodName to display a proper game name over DiscordRPC
//keyState uses the Header of the rom to easily add game pictures through the discord developer panel using the ID above //artwork uses the Header of the rom to easily add game pictures through the discord developer panel using the ID above
char szState[256]; stdstr title = bHaveGame ? GetTitle() : "";
char keyState[256]; stdstr artwork = bHaveGame ? g_Settings->LoadStringVal(Rdb_RPCKey) : "";
sprintf(szState, "%s", g_Settings->LoadStringVal(Rdb_GoodName).c_str()); //rdb_GoodName in a variable for use later
sprintf(keyState, "%s", g_Settings->LoadStringVal(Rdb_RPCKey).c_str()); //Game Image Key in a variable for use later
//Load Game Into DiscordRPC //Load Game Into DiscordRPC
DiscordRichPresence discordPresence = {}; //activates DiscordRPC DiscordRichPresence discordPresence = {}; //activates DiscordRPC
if (bHaveGame && g_Settings->LoadStringVal(Game_File).length() != 0) if (artwork.empty())
{ {
discordPresence.largeImageKey = "pj64_icon";
//DiscordRPC Game Name - Playing <game> discordPresence.largeImageText = "Project64";
discordPresence.state = szState; //sets the state of the DiscordRPC to the Rdb_GoodName file
//Play Time over DiscordRPC
discordPresence.startTimestamp = Timestamp(); //sets the time on the DiscordRPC
//Large Image Text over DiscordRPC
discordPresence.largeImageText = szState; //sets the RDB_GoodName Variable as the large image text
//Large Image File Name over DiscordRPC
discordPresence.largeImageKey = keyState; //sets the Rom Header Variable as the large image key (the file you upload to discord)
//Small Image over DiscordRPC
discordPresence.smallImageKey = "icon"; //Project 64 Logo in bottom right corner
discordPresence.smallImageText = "Project64"; //Name of the Project64 Logo
discordPresence.instance = 1; //Instance of Active DiscordRPC
} }
else else
{ {
discordPresence.largeImageKey = artwork.c_str();
//Show when you are not playing a game over DiscordRPC. discordPresence.largeImageText = title.c_str();
// This is not perfect due to Project64's method of loading discordPresence.smallImageKey = "pj64_icon";
// ROM's into the filesystem before emulation starts. discordPresence.smallImageText = "Project64";
discordPresence.details = "Not in-game"; //shows "Not in-game" on the active DiscordRPC text
discordPresence.largeImageKey = "icon"; //Shows the Project64 logo on the large image box
discordPresence.largeImageText = "Project64"; //Name of the Project64 Logo
discordPresence.smallImageKey = NULL; //Safety Measure to force unload the smallImageKey
discordPresence.smallImageText = NULL; //Safety Measure to force unload the smallImageText
discordPresence.endTimestamp = NULL; //Safety Measure to force unload the TimeStamp
} }
discordPresence.details = title.empty() ? "Not in-game" : title.c_str();
discordPresence.startTimestamp = Timestamp();
Discord_UpdatePresence(&discordPresence); //end DiscordRPC Discord_UpdatePresence(&discordPresence); //end DiscordRPC
} }