mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-04-24 06:47:44 +02:00
misc: chore: Play Report analyzer code simplification
This commit is contained in:
parent
d7707d4176
commit
566f3d079a
2 changed files with 14 additions and 36 deletions
|
@ -117,17 +117,6 @@ namespace Ryujinx.Ava
|
||||||
_currentApp = appMeta;
|
_currentApp = appMeta;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool UpdatePlayingState()
|
|
||||||
{
|
|
||||||
if (_discordClient is null) return false;
|
|
||||||
if (_discordClient.CurrentPresence.Details.Equals(_discordPresencePlaying.Details))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
_discordClient?.SetPresence(_discordPresencePlaying);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void SwitchToMainState()
|
private static void SwitchToMainState()
|
||||||
{
|
{
|
||||||
_discordClient?.SetPresence(_discordPresenceMain);
|
_discordClient?.SetPresence(_discordPresenceMain);
|
||||||
|
@ -141,14 +130,20 @@ namespace Ryujinx.Ava
|
||||||
if (!TitleIDs.CurrentApplication.Value.HasValue) return;
|
if (!TitleIDs.CurrentApplication.Value.HasValue) return;
|
||||||
if (_discordPresencePlaying is null) return;
|
if (_discordPresencePlaying is null) return;
|
||||||
|
|
||||||
PlayReport.Analyzer.FormatPlayReportValue(TitleIDs.CurrentApplication.Value, _currentApp, playReport)
|
PlayReportAnalyzer.FormattedValue formattedValue =
|
||||||
.Match(out bool handled,
|
PlayReport.Analyzer.Format(TitleIDs.CurrentApplication.Value, _currentApp, playReport);
|
||||||
() => _discordPresencePlaying.Details = $"Playing {_currentApp.Title}",
|
|
||||||
formattedString => _discordPresencePlaying.Details = formattedString
|
|
||||||
);
|
|
||||||
|
|
||||||
if (handled && UpdatePlayingState())
|
if (!formattedValue.Handled) return;
|
||||||
Logger.Info?.Print(LogClass.UI, "Updated Discord RPC based on a supported play report.");
|
|
||||||
|
_discordPresencePlaying.Details = formattedValue.Reset
|
||||||
|
? $"Playing {_currentApp.Title}"
|
||||||
|
: formattedValue.FormattedString;
|
||||||
|
|
||||||
|
if (_discordClient.CurrentPresence.Details.Equals(_discordPresencePlaying.Details))
|
||||||
|
return; //don't trigger an update if the set presence Details are identical to current
|
||||||
|
|
||||||
|
_discordClient.SetPresence(_discordPresencePlaying);
|
||||||
|
Logger.Info?.Print(LogClass.UI, "Updated Discord RPC based on a supported play report.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string TruncateToByteLength(string input)
|
private static string TruncateToByteLength(string input)
|
||||||
|
|
|
@ -86,7 +86,7 @@ namespace Ryujinx.Ava.Utilities
|
||||||
/// <param name="appMeta">The Application metadata information, including localized game name and play time information.</param>
|
/// <param name="appMeta">The Application metadata information, including localized game name and play time information.</param>
|
||||||
/// <param name="playReport">The Play Report received from HLE.</param>
|
/// <param name="playReport">The Play Report received from HLE.</param>
|
||||||
/// <returns>A struct representing a possible formatted value.</returns>
|
/// <returns>A struct representing a possible formatted value.</returns>
|
||||||
public FormattedValue FormatPlayReportValue(
|
public FormattedValue Format(
|
||||||
string runningGameId,
|
string runningGameId,
|
||||||
ApplicationMetadata appMeta,
|
ApplicationMetadata appMeta,
|
||||||
MessagePackObject playReport
|
MessagePackObject playReport
|
||||||
|
@ -132,23 +132,6 @@ namespace Ryujinx.Ava.Utilities
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string FormattedString { get; private init; }
|
public string FormattedString { get; private init; }
|
||||||
|
|
||||||
public void Match(out bool wasHandled, Action onReset, Action<string> onSuccess)
|
|
||||||
{
|
|
||||||
if (!Handled)
|
|
||||||
{
|
|
||||||
wasHandled = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Reset)
|
|
||||||
onReset();
|
|
||||||
else
|
|
||||||
onSuccess(FormattedString);
|
|
||||||
|
|
||||||
wasHandled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The intended path of execution for having a string to return: simply return the string.
|
/// The intended path of execution for having a string to return: simply return the string.
|
||||||
/// This implicit conversion will make the struct for you.<br/><br/>
|
/// This implicit conversion will make the struct for you.<br/><br/>
|
||||||
|
|
Loading…
Add table
Reference in a new issue