Revert "Merge branch 'discord'"

This reverts commit e7b9a57723, reversing
changes made to 02b4aa3c91.

Revert "moved rapidjson files"

This reverts commit f5012f770c.
This commit is contained in:
2023-06-21 23:30:35 +02:00
parent 1dde1dbf1e
commit 36f37b6548
57 changed files with 4 additions and 17185 deletions

View File

@@ -14,7 +14,6 @@
#include "window/Display.h"
#include "updater/Updater.h"
#include "misc/Backward.hpp"
#include "misc/DiscordRPC.h"
#ifdef __ANDROID__
extern "C"
@@ -26,9 +25,6 @@ int main(int argc, const char* args[]) {
backward::SignalHandling sh;
#endif
// start discord rpc
td::utils::InitDiscordRPC();
// remove the outdated binary
td::utils::Updater::RemoveOldFile();
@@ -37,10 +33,7 @@ int main(int argc, const char* args[]) {
Display::PollEvents();
Display::Render();
Display::Update();
td::utils::UpdateDiscordRPC();
}
Display::Destroy();
td::utils::ShutdownDiscordRPC();
return 0;
}

View File

@@ -1,7 +1,6 @@
#include "game/client/ClientGame.h"
#include "protocol/PacketDispatcher.h"
#include "game/client/Client.h"
#include "misc/DiscordRPC.h"
namespace td {
namespace client {
@@ -98,7 +97,7 @@ void ClientGame::HandlePacket(const protocol::UpdateExpPacket* packet) {
}
void ClientGame::HandlePacket(const protocol::DisconnectPacket* packet) {
SetGameState(game::GameState::Disconnected);
m_GameState = game::GameState::Disconnected;
m_Renderer->SetBackgroundColor({ 0, 0, 0 });
}
@@ -115,30 +114,5 @@ 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

View File

@@ -1,72 +0,0 @@
#include "misc/DiscordRPC.h"
#include "misc/Time.h"
#include <cstring>
#include <discordrpc/discord_rpc.h>
namespace td {
namespace utils {
static const std::string APPLICATION_ID = "1114135294283874334";
static const std::string TD_ICON = "td_icon2";
static void handleDiscordReady(const DiscordUser* connectedUser);
static void handleDiscordDisconnected(int errcode, const char* message);
static void handleDiscordError(int errcode, const char* message);
void InitDiscordRPC() {
DiscordEventHandlers handlers {};
handlers.ready = handleDiscordReady;
handlers.disconnected = handleDiscordDisconnected;
handlers.errored = handleDiscordError;
Discord_Initialize(APPLICATION_ID.c_str(), &handlers, true, nullptr);
// Set default presence
UpdateDiscordPresence("In Main Menu", "", true);
}
void UpdateDiscordRPC() {
Discord_RunCallbacks();
}
void ShutdownDiscordRPC() {
Discord_Shutdown();
}
void UpdateDiscordPresence(const std::string& state, const std::string& details, bool resetTimer) {
static std::int64_t currentTimeStamp = static_cast<std::int64_t>(GetTime());
if (resetTimer) currentTimeStamp = static_cast<std::int64_t>(GetTime());
DiscordRichPresence discordPresence {};
discordPresence.state = state.c_str();
discordPresence.details = details.c_str();
discordPresence.startTimestamp = currentTimeStamp;
discordPresence.largeImageKey = TD_ICON.c_str();
discordPresence.largeImageText = "Tower Defense";
Discord_UpdatePresence(&discordPresence);
}
static void handleDiscordReady(const DiscordUser* connectedUser)
{
printf("\nDiscord: connected to user %s#%s - %s\n",
connectedUser->username,
connectedUser->discriminator,
connectedUser->userId);
}
static void handleDiscordDisconnected(int errcode, const char* message)
{
printf("\nDiscord: disconnected (%d: %s)\n", errcode, message);
}
static void handleDiscordError(int errcode, const char* message)
{
printf("\nDiscord: error (%d: %s)\n", errcode, message);
}
} // namespace utils
} // namespace td