From c54017c7beb059fc6bcf1cd52c6ece4c56eecba0 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Fri, 2 Jun 2023 13:34:01 +0200 Subject: [PATCH] update presence --- include/game/BaseGame.h | 2 +- include/game/client/ClientGame.h | 2 ++ src/game/client/ClientGame.cpp | 28 +++++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/include/game/BaseGame.h b/include/game/BaseGame.h index dc961d6..47d50c6 100644 --- a/include/game/BaseGame.h +++ b/include/game/BaseGame.h @@ -52,7 +52,7 @@ public: const Team& GetTeam(TeamColor team) const { return m_Teams[static_cast(team)]; } GameState GetGameState() const { return m_GameState; } - void SetGameState(GameState gameState) { m_GameState = gameState; }; + virtual void SetGameState(GameState gameState) { m_GameState = gameState; }; const World* GetWorld() const { return m_World; } World* GetWorld() { return m_World; } diff --git a/include/game/client/ClientGame.h b/include/game/client/ClientGame.h index c5c40c9..c1d0fbb 100644 --- a/include/game/client/ClientGame.h +++ b/include/game/client/ClientGame.h @@ -39,6 +39,8 @@ public: render::Renderer* GetRenderer() const { return m_Renderer; } WorldClient& GetWorldClient() { return m_WorldClient; } + void SetGameState(game::GameState gameState) override; + virtual void HandlePacket(const protocol::ConnexionInfoPacket* packet) override; virtual void HandlePacket(const protocol::PlayerJoinPacket* packet) override; virtual void HandlePacket(const protocol::PlayerLeavePacket* packet) override; diff --git a/src/game/client/ClientGame.cpp b/src/game/client/ClientGame.cpp index cd72abb..b756fac 100644 --- a/src/game/client/ClientGame.cpp +++ b/src/game/client/ClientGame.cpp @@ -1,6 +1,7 @@ #include "game/client/ClientGame.h" #include "protocol/PacketDispatcher.h" #include "game/client/Client.h" +#include "misc/DiscordRPC.h" namespace td { namespace client { @@ -97,7 +98,7 @@ void ClientGame::HandlePacket(const protocol::UpdateExpPacket* packet) { } void ClientGame::HandlePacket(const protocol::DisconnectPacket* packet) { - m_GameState = game::GameState::Disconnected; + SetGameState(game::GameState::Disconnected); m_Renderer->SetBackgroundColor({ 0, 0, 0 }); } @@ -114,5 +115,30 @@ void ClientGame::RenderWorld() { } } +void ClientGame::SetGameState(game::GameState newState) { + game::Game::SetGameState(newState); + + // Update Discord presence + switch (newState) { + + case game::GameState::Lobby: + utils::UpdateDiscordPresence("In Lobby", "Normal Mode", true); + break; + + case game::GameState::Game: + utils::UpdateDiscordPresence("In Game", "Normal Mode", true); + break; + + case game::GameState::Closed: + case game::GameState::Disconnected: + utils::UpdateDiscordPresence("In Main Menu", "Normal Mode", true); + break; + + case game::GameState::EndGame: + utils::UpdateDiscordPresence("In End Game", "Normal Mode", true); + break; + } +} + } // namespace client } // namespace td