Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RetroAchievements - Discord Presence #12755

Merged

Conversation

LillyJadeKatrin
Copy link
Contributor

Sends RetroAchievements Rich Presence to Discord as its presence text provided the correct settings are enabled.

Rebase of #12594 after the refactor to rc_client.

Copy link
Contributor

@iwubcode iwubcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM. Untested.

if (state_string.length() >= 128)
{
// 124 characters + 3 dots + null terminator - thanks to Stenzek for format
state_string.replace(124, 4, "...");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is right? I think for strings > 128 this would insert the ... in the middle of the string instead of replacing the end.

Copy link
Contributor

@iwubcode iwubcode May 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gah, I was thinking of it wrong too.

Probably should be something like: state_string = fmt::format("{}...", state_string.substr(0, 124));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding was that this would insert ...\0 into the middle of the string and thus cut it off when it copies to a cstring?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah you're right, but that's really not obvious with how the code is written. But yeah fair enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more easily verifiable approach is this:

Suggested change
state_string.replace(124, 4, "...");
state_string.resize(124);
state_string += "...";

(not that it mattered here, but this won't have overhead since down-sizing string never re-allocates)

As a side note, std::string's null terminator is not included in its length(), but the comment suggests a different assumption was made. Might be worth double-checking.

@AdmiralCurtiss
Copy link
Contributor

Please hide the Discord presence option in the Achievement UI if RetroAchievements is enabled but Discord is disabled. (USE_DISCORD_PRESENCE off, USE_RETRO_ACHIEVEMENTS on)

@LillyJadeKatrin
Copy link
Contributor Author

Completely hide, or could I just gray it out like with other settings here when they're not active?

@mbc07
Copy link
Contributor

mbc07 commented May 6, 2024

Since we have a discoverability issue here (two related settings at completely different places in the GUI), I'd be in favor of leaving the option in the achievements UI always visible but grayed out when Discord integration is disabled (bonus points if the tooltip also explains why it can't be enabled)...

@AdmiralCurtiss
Copy link
Contributor

AdmiralCurtiss commented May 6, 2024

Ah, I was talking about the compile time switch that disables Discord integration from being compiled altogether, but yes that is a good point too.

So:

  • If Discord is disabled at compile time, don't show the checkbox at all.
  • If Discord is enabled at compile time but currently disabled in the settings, show the box but grey it out.
  • If Discord is enabled at compile time and currently enabled in the settings, show the box regularly.

The tooltip for the box should indeed contain that the regular Discord integration needs to be enabled.

@LillyJadeKatrin
Copy link
Contributor Author

OH right good call, got it.

When enabled, this will send Rich Presence to Discord to be displayed in players' statuses.
If Rich Presence and Discord Presence are enabled in Achievement Settings, the string generated by rcheevos as the player's current Rich Presence will be sent to the Status field in the Discord Presence object. This will be updated whenever Rich Presence updates.
Setting is only enabled when Rich Presence is enabled. Toggling either Rich Presence or Discord Presence will immediately update the Discord status.
@AdmiralCurtiss
Copy link
Contributor

I'm not entirely sure whether the reset_timer flag makes sense but we'll probably figure this out in actual usage.

@AdmiralCurtiss AdmiralCurtiss merged commit fd3867a into dolphin-emu:master May 18, 2024
11 checks passed
@LillyJadeKatrin
Copy link
Contributor Author

FYI the reset_timer flag was because we noticed while testing that without specifying this, the "time played" timer was resetting every time the RP was updating instead of actually reporting the amount of time spent in game. But let me know if we want to change the specific implementation of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants