Skip to content

Commit

Permalink
discord shenanigans
Browse files Browse the repository at this point in the history
  • Loading branch information
3drosalia committed Jan 1, 2025
1 parent 385934b commit 1827a02
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
21 changes: 10 additions & 11 deletions Encore/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -548,7 +548,6 @@ int main(int argc, char *argv[]) {
previousTime = currentTime;
}
}
Encore::DiscordShutdown();
CloseWindow();
return 0;
}
20 changes: 12 additions & 8 deletions Encore/src/util/discord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,31 @@
#include <array>
#include <ctime>

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<std::string, 11> 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<std::string, 11> 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();
Expand Down
19 changes: 13 additions & 6 deletions Encore/src/util/discord.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@

#ifndef DISCORD_H
#define DISCORD_H
#include "discord-rpc/discord_rpc.h"

#include <string>

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);
};
};


Expand Down

0 comments on commit 1827a02

Please sign in to comment.