Added discord rpc timestamps

This commit is contained in:
KiritoDv 2021-05-24 15:09:19 +00:00
parent dc7a608abc
commit 1f07882b49
4 changed files with 22 additions and 9 deletions

View File

@ -169,7 +169,7 @@ namespace Moon {
seg2_act_name_table = current->acts.data(); seg2_act_name_table = current->acts.data();
seg2_course_name_table = current->courses.data(); seg2_course_name_table = current->courses.data();
#ifdef DISCORDRPC #ifdef DISCORDRPC
DiscordUpdatePresence(true); DiscordReloadPresence();
#endif #endif
} }

View File

@ -62,6 +62,7 @@ Discord_UpdatePresence discordUpdatePresence;
static s16 lastCourseNum = -1; static s16 lastCourseNum = -1;
static s16 lastActNum = -1; static s16 lastActNum = -1;
static int64_t timestamp;
bool reloadRPC = false; bool reloadRPC = false;
static char stage[188]; static char stage[188];
@ -156,6 +157,14 @@ static void init_discord(void) {
initd = true; initd = true;
} }
static void set_time(void){
if (lastCourseNum != gCurrCourseNum) {
timestamp = 0;
discordRichPresence.startTimestamp = time(0);
lastCourseNum = gCurrCourseNum;
}
}
static void set_details(void) { static void set_details(void) {
if (lastCourseNum != gCurrCourseNum || reloadRPC) { if (lastCourseNum != gCurrCourseNum || reloadRPC) {
// If we are in in Course 0 we are in the castle which doesn't have a string // If we are in in Course 0 we are in the castle which doesn't have a string
@ -201,13 +210,16 @@ void set_logo(void) {
discordRichPresence.largeImageKey = largeImageKey; discordRichPresence.largeImageKey = largeImageKey;
} }
void DiscordUpdatePresence(bool force){ void DiscordReloadPresence() {
if(force) reloadRPC = true;
reloadRPC = true; }
void DiscordUpdatePresence(){
if (!configDiscordRPC || !initd) return; if (!configDiscordRPC || !initd) return;
if (time(NULL) < lastUpdatedTime + DISCORD_UPDATE_RATE) return; if (time(NULL) < lastUpdatedTime + DISCORD_UPDATE_RATE) return;
lastUpdatedTime = time(NULL); lastUpdatedTime = time(NULL);
set_time();
set_state(); set_state();
set_details(); set_details();
set_logo(); set_logo();
@ -216,8 +228,8 @@ void DiscordUpdatePresence(bool force){
} }
extern "C" { extern "C" {
void discord_update_rich_presence(bool force) { void discord_update_rich_presence() {
DiscordUpdatePresence(force); DiscordUpdatePresence();
} }
void discord_shutdown(void) { void discord_shutdown(void) {

View File

@ -43,11 +43,12 @@ typedef struct DiscordEventHandlers {
void discord_reset(void); void discord_reset(void);
#ifndef __cplusplus #ifndef __cplusplus
void discord_update_rich_presence(bool force); void discord_update_rich_presence();
void discord_shutdown(void); void discord_shutdown(void);
void discord_init(void); void discord_init(void);
#else #else
void DiscordUpdatePresence(bool force); void DiscordReloadPresence();
void DiscordUpdatePresence();
#endif #endif
#endif // DISCORDRPC_H #endif // DISCORDRPC_H

View File

@ -266,7 +266,7 @@ void main_func(char *argv[]) {
while (true) { while (true) {
wm_api->main_loop(produce_one_frame); wm_api->main_loop(produce_one_frame);
#ifdef DISCORDRPC #ifdef DISCORDRPC
discord_update_rich_presence(0); discord_update_rich_presence();
#endif #endif
} }
#endif #endif