diff --git a/src/Ryujinx/Utilities/PlayReport/Delegates.cs b/src/Ryujinx/Utilities/PlayReport/Delegates.cs index 789d408d7..92569d32e 100644 --- a/src/Ryujinx/Utilities/PlayReport/Delegates.cs +++ b/src/Ryujinx/Utilities/PlayReport/Delegates.cs @@ -10,7 +10,7 @@ ///
/// OR a signal to reset the value that the caller is using the for. /// - public delegate FormattedValue ValueFormatter(SingleValue value); + public delegate FormattedValue SingleValueFormatter(SingleValue value); /// /// The delegate type that powers multiple value formatters.
diff --git a/src/Ryujinx/Utilities/PlayReport/MatchedValues.cs b/src/Ryujinx/Utilities/PlayReport/MatchedValues.cs index 01c404c31..3086a9d65 100644 --- a/src/Ryujinx/Utilities/PlayReport/MatchedValues.cs +++ b/src/Ryujinx/Utilities/PlayReport/MatchedValues.cs @@ -7,7 +7,7 @@ namespace Ryujinx.Ava.Utilities.PlayReport { public abstract class MatchedValue { - public MatchedValue(T matched) + protected MatchedValue(T matched) { Matched = matched; } @@ -29,7 +29,7 @@ namespace Ryujinx.Ava.Utilities.PlayReport } /// - /// The input data to a , + /// The input data to a , /// containing the currently running application's , /// and the matched from the Play Report. /// @@ -38,8 +38,6 @@ namespace Ryujinx.Ava.Utilities.PlayReport public SingleValue(Value matched) : base(matched) { } - - public static implicit operator SingleValue(MessagePackObject mpo) => new(mpo); } /// @@ -56,9 +54,6 @@ namespace Ryujinx.Ava.Utilities.PlayReport public MultiValue(IEnumerable matched) : base(Value.ConvertPackedObjects(matched)) { } - - public static implicit operator MultiValue(List matched) - => new(matched.Select(x => new Value(x)).ToArray()); } /// @@ -75,13 +70,5 @@ namespace Ryujinx.Ava.Utilities.PlayReport public SparseMultiValue(Dictionary matched) : base(Value.ConvertPackedObjectMap(matched)) { } - - public static implicit operator SparseMultiValue(Dictionary matched) - => new(matched - .ToDictionary( - x => x.Key, - x => new Value(x.Value) - ) - ); } } diff --git a/src/Ryujinx/Utilities/PlayReport/Specs.cs b/src/Ryujinx/Utilities/PlayReport/Specs.cs index 3c80198b9..e7972fbb4 100644 --- a/src/Ryujinx/Utilities/PlayReport/Specs.cs +++ b/src/Ryujinx/Utilities/PlayReport/Specs.cs @@ -28,7 +28,7 @@ namespace Ryujinx.Ava.Utilities.PlayReport /// The key name to match. /// The function which can return a potential formatted value. /// The current , for chaining convenience. - public GameSpec AddValueFormatter(string reportKey, ValueFormatter valueFormatter) + public GameSpec AddValueFormatter(string reportKey, SingleValueFormatter valueFormatter) => AddValueFormatter(_lastPriority++, reportKey, valueFormatter); /// @@ -40,7 +40,7 @@ namespace Ryujinx.Ava.Utilities.PlayReport /// The function which can return a potential formatted value. /// The current , for chaining convenience. public GameSpec AddValueFormatter(int priority, string reportKey, - ValueFormatter valueFormatter) + SingleValueFormatter valueFormatter) { ValueFormatters.Add(new FormatterSpec { @@ -195,26 +195,21 @@ namespace Ryujinx.Ava.Utilities.PlayReport return true; } - if (Formatter is ValueFormatter vf && data is MessagePackObject mpo) + switch (Formatter) { - formattedValue = vf(new SingleValue(mpo) { Application = appMeta, PlayReport = playReport }); - return true; + case SingleValueFormatter svf when data is MessagePackObject mpo: + formattedValue = svf(new SingleValue(mpo) { Application = appMeta, PlayReport = playReport }); + return true; + case MultiValueFormatter mvf when data is List messagePackObjects: + formattedValue = mvf(new MultiValue(messagePackObjects) { Application = appMeta, PlayReport = playReport }); + return true; + case SparseMultiValueFormatter smvf when + data is Dictionary sparseMessagePackObjects: + formattedValue = smvf(new SparseMultiValue(sparseMessagePackObjects) { Application = appMeta, PlayReport = playReport }); + return true; + default: + throw new InvalidOperationException("Formatter delegate is not of a known type!"); } - - if (Formatter is MultiValueFormatter mvf && data is List messagePackObjects) - { - formattedValue = mvf(new MultiValue(messagePackObjects) { Application = appMeta, PlayReport = playReport }); - return true; - } - - if (Formatter is SparseMultiValueFormatter smvf && - data is Dictionary sparseMessagePackObjects) - { - formattedValue = smvf(new SparseMultiValue(sparseMessagePackObjects) { Application = appMeta, PlayReport = playReport }); - return true; - } - - throw new InvalidOperationException("Formatter delegate is not of a known type!"); } } } diff --git a/src/Ryujinx/Utilities/PlayReport/Value.cs b/src/Ryujinx/Utilities/PlayReport/Value.cs index 65d662ea0..b3108a41e 100644 --- a/src/Ryujinx/Utilities/PlayReport/Value.cs +++ b/src/Ryujinx/Utilities/PlayReport/Value.cs @@ -1,5 +1,4 @@ using MsgPack; -using Ryujinx.Ava.Utilities.AppLibrary; using System; using System.Collections.Generic; using System.Linq; @@ -7,8 +6,7 @@ using System.Linq; namespace Ryujinx.Ava.Utilities.PlayReport { /// - /// The input data to a , - /// containing the currently running application's , + /// The base input data to a ValueFormatter delegate, /// and the matched from the Play Report. /// public readonly struct Value @@ -70,7 +68,7 @@ namespace Ryujinx.Ava.Utilities.PlayReport } /// - /// A potential formatted value returned by a . + /// A potential formatted value returned by a ValueFormatter delegate. /// public readonly struct FormattedValue { @@ -116,28 +114,47 @@ namespace Ryujinx.Ava.Utilities.PlayReport /// /// Return this to tell the caller there is no value to return. /// - public static FormattedValue Unhandled => default; + public static readonly FormattedValue Unhandled = default; /// /// Return this to suggest the caller reset the value it's using the for. /// - public static FormattedValue ForceReset => new() { Handled = true, Reset = true }; + public static readonly FormattedValue ForceReset = new() { Handled = true, Reset = true }; /// - /// A delegate singleton you can use to always return in a . + /// A delegate singleton you can use to always return in a . /// - public static readonly ValueFormatter SingleAlwaysResets = _ => ForceReset; + public static readonly SingleValueFormatter SingleAlwaysResets = _ => ForceReset; /// /// A delegate singleton you can use to always return in a . /// public static readonly MultiValueFormatter MultiAlwaysResets = _ => ForceReset; + + /// + /// A delegate singleton you can use to always return in a . + /// + public static readonly SparseMultiValueFormatter SparseMultiAlwaysResets = _ => ForceReset; /// /// A delegate factory you can use to always return the specified - /// in a . + /// in a . /// /// The string to always return for this delegate instance. - public static ValueFormatter AlwaysReturns(string formattedValue) => _ => formattedValue; + public static SingleValueFormatter SingleAlwaysReturns(string formattedValue) => _ => formattedValue; + + /// + /// A delegate factory you can use to always return the specified + /// in a . + /// + /// The string to always return for this delegate instance. + public static MultiValueFormatter MultiAlwaysReturns(string formattedValue) => _ => formattedValue; + + /// + /// A delegate factory you can use to always return the specified + /// in a . + /// + /// The string to always return for this delegate instance. + public static SparseMultiValueFormatter SparseMultiAlwaysReturns(string formattedValue) => _ => formattedValue; } }