misc: chore: [ci skip] rename ValueFormatter to SingleValueFormatter and some minor cleanups

This commit is contained in:
Evan Husted 2025-02-08 01:34:44 -06:00
parent 30a534edcd
commit 9c226dcc7a
4 changed files with 45 additions and 46 deletions

View File

@ -10,7 +10,7 @@
/// <br/> /// <br/>
/// OR a signal to reset the value that the caller is using the <see cref="Analyzer"/> for. /// OR a signal to reset the value that the caller is using the <see cref="Analyzer"/> for.
/// </summary> /// </summary>
public delegate FormattedValue ValueFormatter(SingleValue value); public delegate FormattedValue SingleValueFormatter(SingleValue value);
/// <summary> /// <summary>
/// The delegate type that powers multiple value formatters.<br/> /// The delegate type that powers multiple value formatters.<br/>

View File

@ -7,7 +7,7 @@ namespace Ryujinx.Ava.Utilities.PlayReport
{ {
public abstract class MatchedValue<T> public abstract class MatchedValue<T>
{ {
public MatchedValue(T matched) protected MatchedValue(T matched)
{ {
Matched = matched; Matched = matched;
} }
@ -29,7 +29,7 @@ namespace Ryujinx.Ava.Utilities.PlayReport
} }
/// <summary> /// <summary>
/// The input data to a <see cref="ValueFormatter"/>, /// The input data to a <see cref="SingleValueFormatter"/>,
/// containing the currently running application's <see cref="ApplicationMetadata"/>, /// containing the currently running application's <see cref="ApplicationMetadata"/>,
/// and the matched <see cref="MessagePackObject"/> from the Play Report. /// and the matched <see cref="MessagePackObject"/> from the Play Report.
/// </summary> /// </summary>
@ -38,8 +38,6 @@ namespace Ryujinx.Ava.Utilities.PlayReport
public SingleValue(Value matched) : base(matched) public SingleValue(Value matched) : base(matched)
{ {
} }
public static implicit operator SingleValue(MessagePackObject mpo) => new(mpo);
} }
/// <summary> /// <summary>
@ -56,9 +54,6 @@ namespace Ryujinx.Ava.Utilities.PlayReport
public MultiValue(IEnumerable<MessagePackObject> matched) : base(Value.ConvertPackedObjects(matched)) public MultiValue(IEnumerable<MessagePackObject> matched) : base(Value.ConvertPackedObjects(matched))
{ {
} }
public static implicit operator MultiValue(List<MessagePackObject> matched)
=> new(matched.Select(x => new Value(x)).ToArray());
} }
/// <summary> /// <summary>
@ -75,13 +70,5 @@ namespace Ryujinx.Ava.Utilities.PlayReport
public SparseMultiValue(Dictionary<string, MessagePackObject> matched) : base(Value.ConvertPackedObjectMap(matched)) public SparseMultiValue(Dictionary<string, MessagePackObject> matched) : base(Value.ConvertPackedObjectMap(matched))
{ {
} }
public static implicit operator SparseMultiValue(Dictionary<string, MessagePackObject> matched)
=> new(matched
.ToDictionary(
x => x.Key,
x => new Value(x.Value)
)
);
} }
} }

View File

@ -28,7 +28,7 @@ namespace Ryujinx.Ava.Utilities.PlayReport
/// <param name="reportKey">The key name to match.</param> /// <param name="reportKey">The key name to match.</param>
/// <param name="valueFormatter">The function which can return a potential formatted value.</param> /// <param name="valueFormatter">The function which can return a potential formatted value.</param>
/// <returns>The current <see cref="GameSpec"/>, for chaining convenience.</returns> /// <returns>The current <see cref="GameSpec"/>, for chaining convenience.</returns>
public GameSpec AddValueFormatter(string reportKey, ValueFormatter valueFormatter) public GameSpec AddValueFormatter(string reportKey, SingleValueFormatter valueFormatter)
=> AddValueFormatter(_lastPriority++, reportKey, valueFormatter); => AddValueFormatter(_lastPriority++, reportKey, valueFormatter);
/// <summary> /// <summary>
@ -40,7 +40,7 @@ namespace Ryujinx.Ava.Utilities.PlayReport
/// <param name="valueFormatter">The function which can return a potential formatted value.</param> /// <param name="valueFormatter">The function which can return a potential formatted value.</param>
/// <returns>The current <see cref="GameSpec"/>, for chaining convenience.</returns> /// <returns>The current <see cref="GameSpec"/>, for chaining convenience.</returns>
public GameSpec AddValueFormatter(int priority, string reportKey, public GameSpec AddValueFormatter(int priority, string reportKey,
ValueFormatter valueFormatter) SingleValueFormatter valueFormatter)
{ {
ValueFormatters.Add(new FormatterSpec ValueFormatters.Add(new FormatterSpec
{ {
@ -195,26 +195,21 @@ namespace Ryujinx.Ava.Utilities.PlayReport
return true; return true;
} }
if (Formatter is ValueFormatter vf && data is MessagePackObject mpo) switch (Formatter)
{ {
formattedValue = vf(new SingleValue(mpo) { Application = appMeta, PlayReport = playReport }); case SingleValueFormatter svf when data is MessagePackObject mpo:
return true; formattedValue = svf(new SingleValue(mpo) { Application = appMeta, PlayReport = playReport });
return true;
case MultiValueFormatter mvf when data is List<MessagePackObject> messagePackObjects:
formattedValue = mvf(new MultiValue(messagePackObjects) { Application = appMeta, PlayReport = playReport });
return true;
case SparseMultiValueFormatter smvf when
data is Dictionary<string, MessagePackObject> 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<MessagePackObject> messagePackObjects)
{
formattedValue = mvf(new MultiValue(messagePackObjects) { Application = appMeta, PlayReport = playReport });
return true;
}
if (Formatter is SparseMultiValueFormatter smvf &&
data is Dictionary<string, MessagePackObject> sparseMessagePackObjects)
{
formattedValue = smvf(new SparseMultiValue(sparseMessagePackObjects) { Application = appMeta, PlayReport = playReport });
return true;
}
throw new InvalidOperationException("Formatter delegate is not of a known type!");
} }
} }
} }

View File

@ -1,5 +1,4 @@
using MsgPack; using MsgPack;
using Ryujinx.Ava.Utilities.AppLibrary;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -7,8 +6,7 @@ using System.Linq;
namespace Ryujinx.Ava.Utilities.PlayReport namespace Ryujinx.Ava.Utilities.PlayReport
{ {
/// <summary> /// <summary>
/// The input data to a <see cref="ValueFormatter"/>, /// The base input data to a ValueFormatter delegate,
/// containing the currently running application's <see cref="ApplicationMetadata"/>,
/// and the matched <see cref="MessagePackObject"/> from the Play Report. /// and the matched <see cref="MessagePackObject"/> from the Play Report.
/// </summary> /// </summary>
public readonly struct Value public readonly struct Value
@ -70,7 +68,7 @@ namespace Ryujinx.Ava.Utilities.PlayReport
} }
/// <summary> /// <summary>
/// A potential formatted value returned by a <see cref="ValueFormatter"/>. /// A potential formatted value returned by a ValueFormatter delegate.
/// </summary> /// </summary>
public readonly struct FormattedValue public readonly struct FormattedValue
{ {
@ -116,28 +114,47 @@ namespace Ryujinx.Ava.Utilities.PlayReport
/// <summary> /// <summary>
/// Return this to tell the caller there is no value to return. /// Return this to tell the caller there is no value to return.
/// </summary> /// </summary>
public static FormattedValue Unhandled => default; public static readonly FormattedValue Unhandled = default;
/// <summary> /// <summary>
/// Return this to suggest the caller reset the value it's using the <see cref="Analyzer"/> for. /// Return this to suggest the caller reset the value it's using the <see cref="Analyzer"/> for.
/// </summary> /// </summary>
public static FormattedValue ForceReset => new() { Handled = true, Reset = true }; public static readonly FormattedValue ForceReset = new() { Handled = true, Reset = true };
/// <summary> /// <summary>
/// A delegate singleton you can use to always return <see cref="ForceReset"/> in a <see cref="ValueFormatter"/>. /// A delegate singleton you can use to always return <see cref="ForceReset"/> in a <see cref="SingleValueFormatter"/>.
/// </summary> /// </summary>
public static readonly ValueFormatter SingleAlwaysResets = _ => ForceReset; public static readonly SingleValueFormatter SingleAlwaysResets = _ => ForceReset;
/// <summary> /// <summary>
/// A delegate singleton you can use to always return <see cref="ForceReset"/> in a <see cref="MultiValueFormatter"/>. /// A delegate singleton you can use to always return <see cref="ForceReset"/> in a <see cref="MultiValueFormatter"/>.
/// </summary> /// </summary>
public static readonly MultiValueFormatter MultiAlwaysResets = _ => ForceReset; public static readonly MultiValueFormatter MultiAlwaysResets = _ => ForceReset;
/// <summary>
/// A delegate singleton you can use to always return <see cref="ForceReset"/> in a <see cref="SparseMultiValueFormatter"/>.
/// </summary>
public static readonly SparseMultiValueFormatter SparseMultiAlwaysResets = _ => ForceReset;
/// <summary> /// <summary>
/// A delegate factory you can use to always return the specified /// A delegate factory you can use to always return the specified
/// <paramref name="formattedValue"/> in a <see cref="ValueFormatter"/>. /// <paramref name="formattedValue"/> in a <see cref="SingleValueFormatter"/>.
/// </summary> /// </summary>
/// <param name="formattedValue">The string to always return for this delegate instance.</param> /// <param name="formattedValue">The string to always return for this delegate instance.</param>
public static ValueFormatter AlwaysReturns(string formattedValue) => _ => formattedValue; public static SingleValueFormatter SingleAlwaysReturns(string formattedValue) => _ => formattedValue;
/// <summary>
/// A delegate factory you can use to always return the specified
/// <paramref name="formattedValue"/> in a <see cref="MultiValueFormatter"/>.
/// </summary>
/// <param name="formattedValue">The string to always return for this delegate instance.</param>
public static MultiValueFormatter MultiAlwaysReturns(string formattedValue) => _ => formattedValue;
/// <summary>
/// A delegate factory you can use to always return the specified
/// <paramref name="formattedValue"/> in a <see cref="SparseMultiValueFormatter"/>.
/// </summary>
/// <param name="formattedValue">The string to always return for this delegate instance.</param>
public static SparseMultiValueFormatter SparseMultiAlwaysReturns(string formattedValue) => _ => formattedValue;
} }
} }