clean up sample to just basics for now, start stubbing in lib

This commit is contained in:
Chris Marsh 2017-06-27 12:24:35 -07:00
parent 6271f29996
commit 8e13ed2a63
2 changed files with 51 additions and 27 deletions

View File

@ -0,0 +1,23 @@
static DiscordEventHandlers Handlers;
void Discord_Initialize(const char* applicationId, DiscordEventHandlers* handlers)
{
if (handlers) {
memcpy(&Handlers, handlers, sizeof(Handlers));
}
else {
memset(&Handlers, 0, sizeof(Handlers));
}
}
void Discord_Shutdown()
{
}
void Discord_UpdatePresence(const DiscordRichPresence* presence)
{
}

View File

@ -1,9 +1,12 @@
#include <stdio.h>
static const char* YOUR_APPLICATION_ID = "23984729347234"; #include "discord-rpc.h"
static const char* APPLICATION_ID = "12345678910";
void updateDiscordPresence() { void updateDiscordPresence() {
DiscordRichPresence myPresence = {0}; DiscordRichPresence myPresence{};
myPresence.name = "League of Legends"; myPresence.name = "My Awesome Game";
myPresence.gameState = "In Game"; myPresence.gameState = "In Game";
myPresence.gameMode = "Summoner's Rift"; myPresence.gameMode = "Summoner's Rift";
myPresence.gameModifier = "Ranked"; myPresence.gameModifier = "Ranked";
@ -11,47 +14,45 @@ void updateDiscordPresence() {
myPresence.flavorImageKey = "FLAVOR_SUMMONERS_RIFT"; myPresence.flavorImageKey = "FLAVOR_SUMMONERS_RIFT";
myPresence.choiceImageKey = "PORTRAIT_AATROX"; myPresence.choiceImageKey = "PORTRAIT_AATROX";
myPresence.partyId = GameEngine_GetMultiplayerPartyId();
myPresence.partySize = GameEngine_GetCurrentPartyCount();
myPresence.partyCapacity = PARTY_CAPACITY;
myPresence.context = GameEngine_GetPartyAndMatchSecret();
myPresence.isInstance = true;
myPresence.joinSecret = GameEngine_GetPartyAndMatchSecret();
myPresence.spectateSecret = GameEngine_GetUserIdSecret();
Discord_UpdatePresence(&myPresence); Discord_UpdatePresence(&myPresence);
} }
void handleDiscordDisconnected() { void handleDiscordReady() {
// oh noes printf("discord ready\n");
} }
void handleDiscordReady() { void handleDiscordDisconnected() {
updateDiscordPresence(); printf("discord disconnected\n");
} }
void handleDiscordWantsPresence() { void handleDiscordWantsPresence() {
printf("discord requests presence\n");
updateDiscordPresence(); updateDiscordPresence();
} }
void handleDiscordJoinGame(const char* joinSecret) { void gameLoop() {
GameEngine_JoinParty(joinSecret); char line[512];
} while (fgets(line, 512, stdin)) {
line[511] = 0;
void handleDiscordSpectateGame(const char* spectateSecret) { printf("line: %s\n", line);
GameEngine_SpectateGame(spectateSecret); }
} }
int main() { int main() {
DiscordEventHandlers handlers = {0}; printf("Starting game client\n");
DiscordEventHandlers handlers{};
handlers.ready = handleDiscordReady; handlers.ready = handleDiscordReady;
handlers.disconnected = handleDiscordDisconnected; handlers.disconnected = handleDiscordDisconnected;
handlers.wantsPresence = handleDiscordWantsPresence; handlers.wantsPresence = handleDiscordWantsPresence;
handlers.joinGame = handleDiscordJoinGame;
handlers.spectateGame = handleDiscordSpectateGame;
Discord_Initialize(YOUR_APPLICATION_ID, handlers); Discord_Initialize(APPLICATION_ID, handlers);
gameLoop();
Discord_Shutdown();
return 0;
} }