mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-05 21:22:07 +02:00
commit
d2e0e2f41b
3 changed files with 31 additions and 22 deletions
|
@ -11,15 +11,15 @@
|
|||
//
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QDateTime>
|
||||
#include <QtCore/QLoggingCategory>
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include "discord_rpc.h"
|
||||
#include "DiscordRichPresence.h"
|
||||
#include "DependencyManager.h"
|
||||
#include "AddressManager.h"
|
||||
#include "scripting/HMDScriptingInterface.h"
|
||||
#include "Application.h"
|
||||
#include "EntityTreeRenderer.h"
|
||||
|
||||
#define DISCORD_APPLICATION_CLIENT_ID "1168082546270163014"
|
||||
|
@ -31,10 +31,18 @@ DiscordPresence::DiscordPresence()
|
|||
{
|
||||
DiscordEventHandlers handlers;
|
||||
Discord_Initialize(DISCORD_APPLICATION_CLIENT_ID, &handlers, 1, STEAM_APPLICATION_ID);
|
||||
discordPresence.largeImageKey = "header";
|
||||
discordPresence.smallImageKey = "";
|
||||
discordPresence.smallImageText = "";
|
||||
const int64_t startEpoch = QDateTime::currentSecsSinceEpoch();
|
||||
discordPresence.startTimestamp = startEpoch;
|
||||
|
||||
auto addressManager = DependencyManager::get<AddressManager>();
|
||||
connect(addressManager.data(), &AddressManager::hostChanged, this, &DiscordPresence::domainChanged);
|
||||
|
||||
auto hMDScriptingInterface = DependencyManager::get<HMDScriptingInterface>();
|
||||
DiscordPresence::vrChanged(hMDScriptingInterface->isHMDMode()); // we don't receive the initial signal, so we ask for the current state
|
||||
connect(hMDScriptingInterface.data(), &HMDScriptingInterface::displayModeChanged, this, &DiscordPresence::vrChanged);
|
||||
}
|
||||
|
||||
void DiscordPresence::shutdown()
|
||||
|
@ -46,34 +54,33 @@ void DiscordPresence::domainChanged()
|
|||
{
|
||||
const auto addressManager = DependencyManager::get<AddressManager>();
|
||||
if (!addressManager) return;
|
||||
const auto entityTreeRenderer = DependencyManager::get<EntityTreeRenderer>();
|
||||
if (!entityTreeRenderer) return;
|
||||
|
||||
// only continue if domain id changed or is serverless
|
||||
bool isServerless = false;
|
||||
const auto tree = entityTreeRenderer->getTree();
|
||||
if (tree) isServerless = tree->isServerlessMode();
|
||||
QString domainID = addressManager->getDomainID();
|
||||
if (currentDomainID == domainID && !isServerless) return;
|
||||
currentDomainID = domainID;
|
||||
|
||||
// get data
|
||||
QString state;
|
||||
// TODO: switch to getPlaceName once https://github.com/overte-org/overte/issues/684 is fixed
|
||||
const QString worldName = addressManager->getHost();
|
||||
qCDebug(discord_rich_presence) << "Discord log hostName: " + worldName;
|
||||
if (isServerless) {
|
||||
state = "In a serverless world";
|
||||
} else {
|
||||
if (worldName != "") {
|
||||
state = ("In " + worldName);
|
||||
qCDebug(discord_rich_presence) << "Discord log hostName: " + worldName;
|
||||
} else {
|
||||
state = "";
|
||||
qCDebug(discord_rich_presence) << "Discord log: in unknown place";
|
||||
}
|
||||
|
||||
// create Discord presence payload
|
||||
QByteArray state_data = state.toUtf8();
|
||||
discordPresence.state = state_data.constData();
|
||||
discordPresence.largeImageKey = "header";
|
||||
discordPresence.smallImageKey = "logo";
|
||||
|
||||
// update activity
|
||||
Discord_UpdatePresence(&discordPresence);
|
||||
}
|
||||
|
||||
void DiscordPresence::vrChanged(bool isHMDMode = false)
|
||||
{
|
||||
if (isHMDMode) {
|
||||
discordPresence.smallImageKey = "hmd";
|
||||
discordPresence.smallImageText = "in VR";
|
||||
} else {
|
||||
discordPresence.smallImageKey = "desktop";
|
||||
discordPresence.smallImageText = "in desktop mode";
|
||||
}
|
||||
qCDebug(discord_rich_presence) << "Discord log HMDMode: " + QString::number(isHMDMode);
|
||||
Discord_UpdatePresence(&discordPresence);
|
||||
}
|
||||
|
|
|
@ -23,10 +23,11 @@ class DiscordPresence : public QObject {
|
|||
Q_OBJECT
|
||||
public:
|
||||
DiscordPresence();
|
||||
void shutdown();
|
||||
static void shutdown();
|
||||
|
||||
public slots:
|
||||
void domainChanged();
|
||||
void vrChanged(bool isHMDMode);
|
||||
|
||||
private:
|
||||
QString currentDomainID;
|
||||
|
|
|
@ -500,6 +500,7 @@ int main(int argc, const char* argv[]) {
|
|||
socket.close();
|
||||
|
||||
qDebug() << "Interface instance appears to be running, exiting";
|
||||
qDebug() << "Start with --allowMultipleInstances to allow running multiple instances at once.";
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue