diff --git a/src/Ryujinx/Utilities/PlayReport/Specs.cs b/src/Ryujinx/Utilities/PlayReport/Specs.cs index 837c37e76..be9232dc8 100644 --- a/src/Ryujinx/Utilities/PlayReport/Specs.cs +++ b/src/Ryujinx/Utilities/PlayReport/Specs.cs @@ -16,12 +16,12 @@ namespace Ryujinx.Ava.Utilities.PlayReport { public static GameSpec Create(string requiredTitleId, params IEnumerable otherTitleIds) => new() { TitleIds = otherTitleIds.Prepend(requiredTitleId).ToArray() }; - + public static GameSpec Create(IEnumerable titleIds) => new() { TitleIds = titleIds.ToArray() }; - + private int _lastPriority; - + public required string[] TitleIds { get; init; } public List ValueFormatters { get; } = []; @@ -34,8 +34,10 @@ 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, SingleValueFormatter valueFormatter) - => AddValueFormatter(_lastPriority++, reportKey, valueFormatter); + public GameSpec AddValueFormatter( + string reportKey, + SingleValueFormatter valueFormatter + ) => AddValueFormatter(_lastPriority++, reportKey, valueFormatter); /// /// Add a value formatter at a specific priority to the current @@ -45,15 +47,14 @@ 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(int priority, string reportKey, - SingleValueFormatter valueFormatter) + public GameSpec AddValueFormatter( + int priority, + string reportKey, + SingleValueFormatter valueFormatter + ) => AddValueFormatter(new FormatterSpec { - ValueFormatters.Add(new FormatterSpec - { - Priority = priority, ReportKeys = [reportKey], Formatter = valueFormatter - }); - return this; - } + Priority = priority, ReportKeys = [reportKey], Formatter = valueFormatter + }); /// /// Add a multi-value formatter to the current @@ -62,8 +63,10 @@ namespace Ryujinx.Ava.Utilities.PlayReport /// The key names to match. /// The function which can format the values. /// The current , for chaining convenience. - public GameSpec AddMultiValueFormatter(string[] reportKeys, MultiValueFormatter valueFormatter) - => AddMultiValueFormatter(_lastPriority++, reportKeys, valueFormatter); + public GameSpec AddMultiValueFormatter( + string[] reportKeys, + MultiValueFormatter valueFormatter + ) => AddMultiValueFormatter(_lastPriority++, reportKeys, valueFormatter); /// /// Add a multi-value formatter at a specific priority to the current @@ -73,15 +76,14 @@ namespace Ryujinx.Ava.Utilities.PlayReport /// The key names to match. /// The function which can format the values. /// The current , for chaining convenience. - public GameSpec AddMultiValueFormatter(int priority, string[] reportKeys, - MultiValueFormatter valueFormatter) + public GameSpec AddMultiValueFormatter( + int priority, + string[] reportKeys, + MultiValueFormatter valueFormatter + ) => AddValueFormatter(new MultiFormatterSpec { - ValueFormatters.Add(new MultiFormatterSpec - { - Priority = priority, ReportKeys = reportKeys, Formatter = valueFormatter - }); - return this; - } + Priority = priority, ReportKeys = reportKeys, Formatter = valueFormatter + }); /// /// Add a multi-value formatter to the current @@ -93,8 +95,10 @@ namespace Ryujinx.Ava.Utilities.PlayReport /// The key names to match. /// The function which can format the values. /// The current , for chaining convenience. - public GameSpec AddSparseMultiValueFormatter(string[] reportKeys, SparseMultiValueFormatter valueFormatter) - => AddSparseMultiValueFormatter(_lastPriority++, reportKeys, valueFormatter); + public GameSpec AddSparseMultiValueFormatter( + string[] reportKeys, + SparseMultiValueFormatter valueFormatter + ) => AddSparseMultiValueFormatter(_lastPriority++, reportKeys, valueFormatter); /// /// Add a multi-value formatter at a specific priority to the current @@ -107,13 +111,18 @@ namespace Ryujinx.Ava.Utilities.PlayReport /// The key names to match. /// The function which can format the values. /// The current , for chaining convenience. - public GameSpec AddSparseMultiValueFormatter(int priority, string[] reportKeys, - SparseMultiValueFormatter valueFormatter) + public GameSpec AddSparseMultiValueFormatter( + int priority, + string[] reportKeys, + SparseMultiValueFormatter valueFormatter + ) => AddValueFormatter(new SparseMultiFormatterSpec { - ValueFormatters.Add(new SparseMultiFormatterSpec - { - Priority = priority, ReportKeys = reportKeys, Formatter = valueFormatter - }); + Priority = priority, ReportKeys = reportKeys, Formatter = valueFormatter + }); + + private GameSpec AddValueFormatter(T formatterSpec) where T : FormatterSpecBase + { + ValueFormatters.Add(formatterSpec); return this; } } @@ -180,16 +189,17 @@ namespace Ryujinx.Ava.Utilities.PlayReport return true; } } - + public abstract class FormatterSpecBase { public abstract bool GetData(Horizon.Prepo.Types.PlayReport playReport, out object data); - + public int Priority { get; init; } public string[] ReportKeys { get; init; } public Delegate Formatter { get; init; } - public bool Format(ApplicationMetadata appMeta, Horizon.Prepo.Types.PlayReport playReport, out FormattedValue formattedValue) + public bool Format(ApplicationMetadata appMeta, Horizon.Prepo.Types.PlayReport playReport, + out FormattedValue formattedValue) { formattedValue = default; if (!GetData(playReport, out object data)) @@ -207,11 +217,16 @@ namespace Ryujinx.Ava.Utilities.PlayReport 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 }); + 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 }); + formattedValue = + smvf(new SparseMultiValue(sparseMessagePackObjects) + { + Application = appMeta, PlayReport = playReport + }); return true; default: throw new InvalidOperationException("Formatter delegate is not of a known type!");