Compare commits

...

3 Commits

Author SHA1 Message Date
Evan Husted
11bc32d98e UI: RPC: Reset Details when switching between Master Mode and Normal Mode on the title screen. 2025-02-03 19:19:17 -06:00
Evan Husted
063430ea16 misc: chore: Use .Match 2025-02-03 19:18:31 -06:00
Evan Husted
65f08caaa3 misc: chore: .Match helper method on PlayReportAnalyzer.FormattedValue. 2025-02-03 19:18:17 -06:00
3 changed files with 37 additions and 17 deletions

View File

@@ -135,21 +135,21 @@ namespace Ryujinx.Ava
if (!TitleIDs.CurrentApplication.Value.HasValue) return;
if (_discordPresencePlaying is null) return;
PlayReportAnalyzer.FormattedValue value = PlayReport.Analyzer.FormatPlayReportValue(TitleIDs.CurrentApplication.Value, _currentApp, playReport);
if (!value.Handled) return;
if (value.Reset)
{
_discordPresencePlaying.Details = $"Playing {_currentApp.Title}";
Logger.Info?.Print(LogClass.UI, "Reset Discord RPC based on a supported play report value formatter.");
}
else
{
_discordPresencePlaying.Details = value.FormattedString;
Logger.Info?.Print(LogClass.UI, "Updated Discord RPC based on a supported play report.");
}
UpdatePlayingState();
PlayReport.Analyzer.FormatPlayReportValue(TitleIDs.CurrentApplication.Value, _currentApp, playReport)
.Match(out bool handled,
() =>
{
_discordPresencePlaying.Details = $"Playing {_currentApp.Title}";
Logger.Info?.Print(LogClass.UI, "Reset Discord RPC based on a supported play report value formatter.");
},
formattedString =>
{
_discordPresencePlaying.Details = formattedString;
Logger.Info?.Print(LogClass.UI, "Updated Discord RPC based on a supported play report.");
});
if (handled)
UpdatePlayingState();
}
private static string TruncateToByteLength(string input)

View File

@@ -7,7 +7,10 @@ namespace Ryujinx.Ava.Utilities
public static PlayReportAnalyzer Analyzer { get; } = new PlayReportAnalyzer()
.AddSpec(
"01007ef00011e000",
spec => spec.AddValueFormatter("IsHardMode", BreathOfTheWild_MasterMode)
spec => spec
.AddValueFormatter("IsHardMode", BreathOfTheWild_MasterMode)
// reset to normal status when switching between normal & master mode in title screen
.AddValueFormatter("AoCVer", PlayReportFormattedValue.AlwaysResets)
)
.AddSpec(
"0100f2c0115b6000",

View File

@@ -115,7 +115,7 @@ namespace Ryujinx.Ava.Utilities
/// <summary>
/// A potential formatted value returned by a <see cref="PlayReportValueFormatter"/>.
/// </summary>
public struct FormattedValue
public readonly struct FormattedValue
{
/// <summary>
/// Was any handler able to match anything in the Play Report?
@@ -132,6 +132,23 @@ namespace Ryujinx.Ava.Utilities
/// </summary>
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>
/// 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/>