using FluentAvalonia.Core; using System.Collections.Generic; using System.Linq; namespace Ryujinx.Ava.Utilities.PlayReport { /// /// A mapping of title IDs to value formatter specs. /// /// Generally speaking, use the .AddSpec(...) methods instead of creating this class yourself. /// public class GameSpec { public required string[] TitleIds { get; init; } public List SimpleValueFormatters { get; } = []; public List MultiValueFormatters { get; } = []; public List SparseMultiValueFormatters { get; } = []; /// /// Add a value formatter to the current /// matching a specific key that could exist in a Play Report for the previously specified title IDs. /// /// 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) => AddValueFormatter(SimpleValueFormatters.Count, reportKey, valueFormatter); /// /// Add a value formatter at a specific priority to the current /// matching a specific key that could exist in a Play Report for the previously specified title IDs. /// /// The resolution priority of this value formatter. Higher resolves sooner. /// 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, ValueFormatter valueFormatter) { SimpleValueFormatters.Add(new FormatterSpec { Priority = priority, ReportKey = reportKey, Formatter = valueFormatter }); return this; } /// /// Add a multi-value formatter to the current /// matching a specific set of keys that could exist in a Play Report for the previously specified title IDs. /// /// 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(MultiValueFormatters.Count, reportKeys, valueFormatter); /// /// Add a multi-value formatter at a specific priority to the current /// matching a specific set of keys that could exist in a Play Report for the previously specified title IDs. /// /// The resolution priority of this value formatter. Higher resolves sooner. /// 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) { MultiValueFormatters.Add(new MultiFormatterSpec { Priority = priority, ReportKeys = reportKeys, Formatter = valueFormatter }); return this; } /// /// Add a multi-value formatter to the current /// matching a specific set of keys that could exist in a Play Report for the previously specified title IDs. ///

/// The 'Sparse' multi-value formatters do not require every key to be present. /// If you need this requirement, use . ///
/// 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(SparseMultiValueFormatters.Count, reportKeys, valueFormatter); /// /// Add a multi-value formatter at a specific priority to the current /// matching a specific set of keys that could exist in a Play Report for the previously specified title IDs. ///

/// The 'Sparse' multi-value formatters do not require every key to be present. /// If you need this requirement, use . ///
/// The resolution priority of this value formatter. Higher resolves sooner. /// 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) { SparseMultiValueFormatters.Add(new SparseMultiFormatterSpec { Priority = priority, ReportKeys = reportKeys, Formatter = valueFormatter }); return this; } } /// /// A struct containing the data for a mapping of a key in a Play Report to a formatter for its potential value. /// public struct FormatterSpec { public required int Priority { get; init; } public required string ReportKey { get; init; } public ValueFormatter Formatter { get; init; } } /// /// A struct containing the data for a mapping of an arbitrary key set in a Play Report to a formatter for their potential values. /// public struct MultiFormatterSpec { public required int Priority { get; init; } public required string[] ReportKeys { get; init; } public MultiValueFormatter Formatter { get; init; } } /// /// A struct containing the data for a mapping of an arbitrary key set in a Play Report to a formatter for their sparsely populated potential values. /// public struct SparseMultiFormatterSpec { public required int Priority { get; init; } public required string[] ReportKeys { get; init; } public SparseMultiValueFormatter Formatter { get; init; } } }