mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-23 10:09:43 +01:00
Finish @Daaaav's requests :D
This commit is contained in:
parent
132c5047a4
commit
29708db855
1 changed files with 91 additions and 26 deletions
|
@ -35,9 +35,60 @@ struct DISCORD_application {
|
||||||
struct DiscordActivity activity;
|
struct DiscordActivity activity;
|
||||||
|
|
||||||
bool discordDetected = false;
|
bool discordDetected = false;
|
||||||
|
bool discordPostInit = false;
|
||||||
|
|
||||||
|
|
||||||
static void* libHandle = NULL;
|
static void* libHandle = NULL;
|
||||||
|
|
||||||
|
static const char* DiscordResult_Strings[] = {
|
||||||
|
"DiscordResult_Ok",
|
||||||
|
"DiscordResult_ServiceUnavailable",
|
||||||
|
"DiscordResult_InvalidVersion",
|
||||||
|
"DiscordResult_LockFailed",
|
||||||
|
"DiscordResult_InternalError",
|
||||||
|
"DiscordResult_InvalidPayload",
|
||||||
|
"DiscordResult_InvalidCommand",
|
||||||
|
"DiscordResult_InvalidPermissions",
|
||||||
|
"DiscordResult_NotFetched",
|
||||||
|
"DiscordResult_NotFound",
|
||||||
|
"DiscordResult_Conflict",
|
||||||
|
"DiscordResult_InvalidSecret",
|
||||||
|
"DiscordResult_InvalidJoinSecret",
|
||||||
|
"DiscordResult_NoEligibleActivity",
|
||||||
|
"DiscordResult_InvalidInvite",
|
||||||
|
"DiscordResult_NotAuthenticated",
|
||||||
|
"DiscordResult_InvalidAccessToken",
|
||||||
|
"DiscordResult_ApplicationMismatch",
|
||||||
|
"DiscordResult_InvalidDataUrl",
|
||||||
|
"DiscordResult_InvalidBase64",
|
||||||
|
"DiscordResult_NotFiltered",
|
||||||
|
"DiscordResult_LobbyFull",
|
||||||
|
"DiscordResult_InvalidLobbySecret",
|
||||||
|
"DiscordResult_InvalidFilename",
|
||||||
|
"DiscordResult_InvalidFileSize",
|
||||||
|
"DiscordResult_InvalidEntitlement",
|
||||||
|
"DiscordResult_NotInstalled",
|
||||||
|
"DiscordResult_NotRunning",
|
||||||
|
"DiscordResult_InsufficientBuffer",
|
||||||
|
"DiscordResult_PurchaseCanceled",
|
||||||
|
"DiscordResult_InvalidGuild",
|
||||||
|
"DiscordResult_InvalidEvent",
|
||||||
|
"DiscordResult_InvalidChannel",
|
||||||
|
"DiscordResult_InvalidOrigin",
|
||||||
|
"DiscordResult_RateLimited",
|
||||||
|
"DiscordResult_OAuth2Error",
|
||||||
|
"DiscordResult_SelectChannelTimeout",
|
||||||
|
"DiscordResult_GetGuildTimeout",
|
||||||
|
"DiscordResult_SelectVoiceForceRequired",
|
||||||
|
"DiscordResult_CaptureShortcutAlreadyListening",
|
||||||
|
"DiscordResult_UnauthorizedForAchievement",
|
||||||
|
"DiscordResult_InvalidGiftCode",
|
||||||
|
"DiscordResult_PurchaseError",
|
||||||
|
"DiscordResult_TransactionAborted",
|
||||||
|
"DiscordResult_DrawingInitFailed"
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define FUNC_LIST \
|
#define FUNC_LIST \
|
||||||
FOREACH_FUNC(enum EDiscordResult, DiscordCreate, (DiscordVersion, struct DiscordCreateParams*, struct IDiscordCore**))
|
FOREACH_FUNC(enum EDiscordResult, DiscordCreate, (DiscordVersion, struct DiscordCreateParams*, struct IDiscordCore**))
|
||||||
|
@ -48,6 +99,21 @@ static void* libHandle = NULL;
|
||||||
FUNC_LIST
|
FUNC_LIST
|
||||||
#undef FOREACH_FUNC
|
#undef FOREACH_FUNC
|
||||||
|
|
||||||
|
bool DISCORD_REQUIRE(int x) {
|
||||||
|
//vlog_error(DiscordResult_Strings[x]);
|
||||||
|
if(!discordDetected && discordPostInit)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(x != DiscordResult_Ok)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void ClearPointers(void)
|
static void ClearPointers(void)
|
||||||
{
|
{
|
||||||
SDL_UnloadObject(libHandle);
|
SDL_UnloadObject(libHandle);
|
||||||
|
@ -94,19 +160,24 @@ int32_t DISCORD_init(void)
|
||||||
params.client_id = DISCORD_CLIENT_ID;
|
params.client_id = DISCORD_CLIENT_ID;
|
||||||
params.flags = DiscordCreateFlags_NoRequireDiscord;
|
params.flags = DiscordCreateFlags_NoRequireDiscord;
|
||||||
|
|
||||||
if(DiscordCreate(DISCORD_VERSION, ¶ms, &app.core) != DiscordResult_Ok)
|
if(!DISCORD_REQUIRE(DiscordCreate(DISCORD_VERSION, ¶ms, &app.core)))
|
||||||
{
|
{ // Discord's API couldn't initialise, so just ignore it
|
||||||
|
discordPostInit = true; // even if it fails, set post init to true.
|
||||||
|
//vlog_error("Discord API failed to initialise!");
|
||||||
discordDetected = false;
|
discordDetected = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(app.core == NULL)
|
if(app.core == NULL)
|
||||||
{
|
{
|
||||||
|
discordPostInit = true;
|
||||||
|
//vlog_error("app.core == null. DiscordCreate failed with a positive result?");
|
||||||
discordDetected = false;
|
discordDetected = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
discordPostInit = true;
|
||||||
|
|
||||||
|
// Placeholder, is this really nesaccary
|
||||||
SDL_strlcpy(activity.assets.large_image, "vvvvvv", sizeof(activity.assets.large_image));
|
SDL_strlcpy(activity.assets.large_image, "vvvvvv", sizeof(activity.assets.large_image));
|
||||||
SDL_strlcpy(activity.assets.large_text, "Outside Dimension VVVVVV", sizeof(activity.assets.large_text));
|
SDL_strlcpy(activity.assets.large_text, "Outside Dimension VVVVVV", sizeof(activity.assets.large_text));
|
||||||
|
|
||||||
|
@ -118,39 +189,33 @@ int32_t DISCORD_init(void)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DISCORD_REQUIRE(int x) {
|
|
||||||
if(!discordDetected)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(x != DiscordResult_Ok)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DISCORD_update(const char* area, const char* roomname)
|
void DISCORD_update(const char* area, const char* roomname)
|
||||||
{
|
{
|
||||||
if(app.core == NULL) {
|
if(app.core == NULL || !discordDetected) {
|
||||||
|
//vlog_error("404: Discord not found!");
|
||||||
|
// No Discord
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!DISCORD_REQUIRE(app.core->run_callbacks(app.core)))
|
||||||
|
{
|
||||||
|
// Something or other is wrong, but do we care?
|
||||||
|
//vlog_error("Something went wrong (true windows moment)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(app.activityMan == NULL)
|
if(app.activityMan == NULL)
|
||||||
{
|
{
|
||||||
|
//vlog_error("No activityMan!");
|
||||||
app.activityMan = app.core->get_activity_manager(app.core);
|
app.activityMan = app.core->get_activity_manager(app.core);
|
||||||
}
|
}
|
||||||
if(activity.state == roomname || activity.assets.large_text == area)
|
if(activity.state != roomname || activity.assets.large_text != area)
|
||||||
{
|
{
|
||||||
DISCORD_REQUIRE(app.core->run_callbacks(app.core));
|
//vlog_info("activity updated");
|
||||||
return;
|
SDL_strlcpy(activity.state, roomname, sizeof(activity.state));
|
||||||
|
SDL_strlcpy(activity.assets.large_image, "vvvvvv", sizeof(activity.assets.large_image));
|
||||||
|
SDL_strlcpy(activity.assets.large_text, area, sizeof(activity.assets.large_text));
|
||||||
|
|
||||||
|
app.activityMan->update_activity(app.activityMan, &activity, NULL, NULL);
|
||||||
}
|
}
|
||||||
SDL_strlcpy(activity.state, roomname, sizeof(activity.state));
|
|
||||||
SDL_strlcpy(activity.assets.large_image, "vvvvvv", sizeof(activity.assets.large_image));
|
|
||||||
SDL_strlcpy(activity.assets.large_text, area, sizeof(activity.assets.large_text));
|
|
||||||
|
|
||||||
app.activityMan->update_activity(app.activityMan, &activity, NULL, NULL);
|
|
||||||
|
|
||||||
DISCORD_REQUIRE(app.core->run_callbacks(app.core));
|
|
||||||
}
|
}
|
||||||
void DISCORD_unlockAchievement(const char *name)
|
void DISCORD_unlockAchievement(const char *name)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue