From 1827a029e09da035763df1ea2f17b644121846ab Mon Sep 17 00:00:00 2001 From: 3drosalia Date: Wed, 1 Jan 2025 15:04:49 -0500 Subject: [PATCH] discord shenanigans --- Encore/src/main.cpp | 21 ++++++++++----------- Encore/src/util/discord.cpp | 20 ++++++++++++-------- Encore/src/util/discord.h | 19 +++++++++++++------ 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/Encore/src/main.cpp b/Encore/src/main.cpp index 840ce55..b8e7273 100644 --- a/Encore/src/main.cpp +++ b/Encore/src/main.cpp @@ -250,7 +250,7 @@ int main(int argc, char *argv[]) { ); SET_WINDOW_FULLSCREEN_BORDERLESS(); } - Encore::DiscordInitialize(); + Encore::Discord TheGameRPC; Encore::EncoreLog(LOG_INFO, TextFormat("Target FPS: %d", targetFPS)); audioManager.Init(); @@ -276,7 +276,7 @@ int main(int argc, char *argv[]) { Menu::onNewMenu = true; TheSongTime.SetOffset(TheGameSettings.AudioOffset / 1000.0); - audioManager.loadSample("Assets/highway/clap.mp3", "clap"); + // audioManager.loadSample("Assets/highway/clap.mp3", "clap"); while (!WindowShouldClose()) { u.calcUnits(); double curTime = GetTime(); @@ -321,31 +321,31 @@ int main(int argc, char *argv[]) { // add its case to the `ActiveMenu->Draw();` // cases. case MAIN_MENU: { - Encore::DiscordUpdatePresence("Main menu", "In the menus"); + TheGameRPC.DiscordUpdatePresence("Main menu", "In the menus"); ActiveMenu = new MainMenu; ActiveMenu->Load(); break; } case SETTINGS: { - Encore::DiscordUpdatePresence("Configuring", "In the menus"); + TheGameRPC.DiscordUpdatePresence("Configuring", "In the menus"); ActiveMenu = new SettingsMenu; ActiveMenu->Load(); break; } case RESULTS: { - Encore::DiscordUpdatePresence("Viewing results", "In the menus"); + TheGameRPC.DiscordUpdatePresence("Viewing results", "In the menus"); ActiveMenu = new resultsMenu; ActiveMenu->Load(); break; } case SONG_SELECT: { - Encore::DiscordUpdatePresence("Viewing songs", "In the menus"); + TheGameRPC.DiscordUpdatePresence("Viewing songs", "In the menus"); ActiveMenu = new SongSelectMenu; ActiveMenu->Load(); break; } case READY_UP: { - Encore::DiscordUpdatePresence("Readying up", "In the menus"); + TheGameRPC.DiscordUpdatePresence("Readying up", "In the menus"); ActiveMenu = new ReadyUpMenu; ActiveMenu->Load(); break; @@ -356,19 +356,19 @@ int main(int argc, char *argv[]) { break; } case CACHE_LOADING_SCREEN: { - Encore::DiscordUpdatePresence("Loading game", "In the menus"); + TheGameRPC.DiscordUpdatePresence("Loading game", "In the menus"); ActiveMenu = new cacheLoadingScreen; ActiveMenu->Load(); break; } case CHART_LOADING_SCREEN: { - Encore::DiscordUpdatePresence("Loading a song", "In the menus"); + TheGameRPC.DiscordUpdatePresence("Loading a song", "In the menus"); ActiveMenu = new ChartLoadingMenu; ActiveMenu->Load(); break; } case GAMEPLAY: { - Encore::DiscordUpdatePresenceSong( + TheGameRPC.DiscordUpdatePresenceSong( "Playing a song", TheSongList.curSong->title + " - " + TheSongList.curSong->artist, ThePlayerManager.GetActivePlayer(0).Instrument @@ -548,7 +548,6 @@ int main(int argc, char *argv[]) { previousTime = currentTime; } } - Encore::DiscordShutdown(); CloseWindow(); return 0; } diff --git a/Encore/src/util/discord.cpp b/Encore/src/util/discord.cpp index 4026062..84b47ec 100644 --- a/Encore/src/util/discord.cpp +++ b/Encore/src/util/discord.cpp @@ -9,27 +9,31 @@ #include #include -void Encore::DiscordInitialize() { +Encore::Discord::Discord() : presence() { DiscordEventHandlers Handlers {}; Discord_Initialize("1216298119457804379", &Handlers, 1, nullptr); -}; +} -void Encore::DiscordShutdown() { +Encore::Discord::~Discord() { Discord_Shutdown(); } -void Encore::DiscordUpdatePresence(const std::string &title, const std::string &details) { - DiscordRichPresence presence {}; +void Encore::Discord::DiscordUpdatePresence(const std::string &title, const std::string &details) { presence.largeImageKey = "encore"; presence.state = title.c_str(); presence.details = details.c_str(); Discord_UpdatePresence(&presence); } -std::array AssetNames = {"pad_drums", "pad_bass", "pad_guitar", "pad_keys", "pad_vocals", "classic_drums", "classic_bass", "classic_guitar", "classic_keys", "classic_vocals", "classic_vocals"}; +std::array AssetNames = { + "pad_drums", "pad_bass", "pad_guitar", "pad_keys", + "pad_vocals", "classic_drums", "classic_bass", "classic_guitar", + "classic_keys", "classic_vocals", "classic_vocals" +}; -void Encore::DiscordUpdatePresenceSong(const std::string &title, const std::string &details, int instrument) { - DiscordRichPresence presence {}; +void Encore::Discord::DiscordUpdatePresenceSong( + const std::string &title, const std::string &details, int instrument +) { presence.smallImageKey = AssetNames[instrument].c_str(); presence.largeImageKey = "encore"; presence.state = title.c_str(); diff --git a/Encore/src/util/discord.h b/Encore/src/util/discord.h index 86f49b3..67757fd 100644 --- a/Encore/src/util/discord.h +++ b/Encore/src/util/discord.h @@ -4,15 +4,22 @@ #ifndef DISCORD_H #define DISCORD_H +#include "discord-rpc/discord_rpc.h" + #include namespace Encore { - void DiscordInitialize(); - void DiscordShutdown(); - void DiscordUpdatePresence( - const std::string &title, const std::string &details - ); - void DiscordUpdatePresenceSong(const std::string &title, const std::string &details, int instrument); + class Discord { + + DiscordRichPresence presence; + public: + Discord(); + ~Discord(); + void DiscordUpdatePresence( + const std::string &title, const std::string &details + ); + void DiscordUpdatePresenceSong(const std::string &title, const std::string &details, int instrument); + }; };