misc: chore: cleanup Specs.cs
This commit is contained in:
parent
764c9e9d4e
commit
e4b4e94b56
@ -16,12 +16,12 @@ namespace Ryujinx.Ava.Utilities.PlayReport
|
|||||||
{
|
{
|
||||||
public static GameSpec Create(string requiredTitleId, params IEnumerable<string> otherTitleIds)
|
public static GameSpec Create(string requiredTitleId, params IEnumerable<string> otherTitleIds)
|
||||||
=> new() { TitleIds = otherTitleIds.Prepend(requiredTitleId).ToArray() };
|
=> new() { TitleIds = otherTitleIds.Prepend(requiredTitleId).ToArray() };
|
||||||
|
|
||||||
public static GameSpec Create(IEnumerable<string> titleIds)
|
public static GameSpec Create(IEnumerable<string> titleIds)
|
||||||
=> new() { TitleIds = titleIds.ToArray() };
|
=> new() { TitleIds = titleIds.ToArray() };
|
||||||
|
|
||||||
private int _lastPriority;
|
private int _lastPriority;
|
||||||
|
|
||||||
public required string[] TitleIds { get; init; }
|
public required string[] TitleIds { get; init; }
|
||||||
|
|
||||||
public List<FormatterSpecBase> ValueFormatters { get; } = [];
|
public List<FormatterSpecBase> ValueFormatters { get; } = [];
|
||||||
@ -34,8 +34,10 @@ 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, SingleValueFormatter valueFormatter)
|
public GameSpec AddValueFormatter(
|
||||||
=> AddValueFormatter(_lastPriority++, reportKey, valueFormatter);
|
string reportKey,
|
||||||
|
SingleValueFormatter valueFormatter
|
||||||
|
) => AddValueFormatter(_lastPriority++, reportKey, valueFormatter);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add a value formatter at a specific priority to the current <see cref="GameSpec"/>
|
/// Add a value formatter at a specific priority to the current <see cref="GameSpec"/>
|
||||||
@ -45,15 +47,14 @@ 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(int priority, string reportKey,
|
public GameSpec AddValueFormatter(
|
||||||
SingleValueFormatter valueFormatter)
|
int priority,
|
||||||
|
string reportKey,
|
||||||
|
SingleValueFormatter valueFormatter
|
||||||
|
) => AddValueFormatter(new FormatterSpec
|
||||||
{
|
{
|
||||||
ValueFormatters.Add(new FormatterSpec
|
Priority = priority, ReportKeys = [reportKey], Formatter = valueFormatter
|
||||||
{
|
});
|
||||||
Priority = priority, ReportKeys = [reportKey], Formatter = valueFormatter
|
|
||||||
});
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add a multi-value formatter to the current <see cref="GameSpec"/>
|
/// Add a multi-value formatter to the current <see cref="GameSpec"/>
|
||||||
@ -62,8 +63,10 @@ namespace Ryujinx.Ava.Utilities.PlayReport
|
|||||||
/// <param name="reportKeys">The key names to match.</param>
|
/// <param name="reportKeys">The key names to match.</param>
|
||||||
/// <param name="valueFormatter">The function which can format the values.</param>
|
/// <param name="valueFormatter">The function which can format the values.</param>
|
||||||
/// <returns>The current <see cref="GameSpec"/>, for chaining convenience.</returns>
|
/// <returns>The current <see cref="GameSpec"/>, for chaining convenience.</returns>
|
||||||
public GameSpec AddMultiValueFormatter(string[] reportKeys, MultiValueFormatter valueFormatter)
|
public GameSpec AddMultiValueFormatter(
|
||||||
=> AddMultiValueFormatter(_lastPriority++, reportKeys, valueFormatter);
|
string[] reportKeys,
|
||||||
|
MultiValueFormatter valueFormatter
|
||||||
|
) => AddMultiValueFormatter(_lastPriority++, reportKeys, valueFormatter);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add a multi-value formatter at a specific priority to the current <see cref="GameSpec"/>
|
/// Add a multi-value formatter at a specific priority to the current <see cref="GameSpec"/>
|
||||||
@ -73,15 +76,14 @@ namespace Ryujinx.Ava.Utilities.PlayReport
|
|||||||
/// <param name="reportKeys">The key names to match.</param>
|
/// <param name="reportKeys">The key names to match.</param>
|
||||||
/// <param name="valueFormatter">The function which can format the values.</param>
|
/// <param name="valueFormatter">The function which can format the values.</param>
|
||||||
/// <returns>The current <see cref="GameSpec"/>, for chaining convenience.</returns>
|
/// <returns>The current <see cref="GameSpec"/>, for chaining convenience.</returns>
|
||||||
public GameSpec AddMultiValueFormatter(int priority, string[] reportKeys,
|
public GameSpec AddMultiValueFormatter(
|
||||||
MultiValueFormatter valueFormatter)
|
int priority,
|
||||||
|
string[] reportKeys,
|
||||||
|
MultiValueFormatter valueFormatter
|
||||||
|
) => AddValueFormatter(new MultiFormatterSpec
|
||||||
{
|
{
|
||||||
ValueFormatters.Add(new MultiFormatterSpec
|
Priority = priority, ReportKeys = reportKeys, Formatter = valueFormatter
|
||||||
{
|
});
|
||||||
Priority = priority, ReportKeys = reportKeys, Formatter = valueFormatter
|
|
||||||
});
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add a multi-value formatter to the current <see cref="GameSpec"/>
|
/// Add a multi-value formatter to the current <see cref="GameSpec"/>
|
||||||
@ -93,8 +95,10 @@ namespace Ryujinx.Ava.Utilities.PlayReport
|
|||||||
/// <param name="reportKeys">The key names to match.</param>
|
/// <param name="reportKeys">The key names to match.</param>
|
||||||
/// <param name="valueFormatter">The function which can format the values.</param>
|
/// <param name="valueFormatter">The function which can format the values.</param>
|
||||||
/// <returns>The current <see cref="GameSpec"/>, for chaining convenience.</returns>
|
/// <returns>The current <see cref="GameSpec"/>, for chaining convenience.</returns>
|
||||||
public GameSpec AddSparseMultiValueFormatter(string[] reportKeys, SparseMultiValueFormatter valueFormatter)
|
public GameSpec AddSparseMultiValueFormatter(
|
||||||
=> AddSparseMultiValueFormatter(_lastPriority++, reportKeys, valueFormatter);
|
string[] reportKeys,
|
||||||
|
SparseMultiValueFormatter valueFormatter
|
||||||
|
) => AddSparseMultiValueFormatter(_lastPriority++, reportKeys, valueFormatter);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add a multi-value formatter at a specific priority to the current <see cref="GameSpec"/>
|
/// Add a multi-value formatter at a specific priority to the current <see cref="GameSpec"/>
|
||||||
@ -107,13 +111,18 @@ namespace Ryujinx.Ava.Utilities.PlayReport
|
|||||||
/// <param name="reportKeys">The key names to match.</param>
|
/// <param name="reportKeys">The key names to match.</param>
|
||||||
/// <param name="valueFormatter">The function which can format the values.</param>
|
/// <param name="valueFormatter">The function which can format the values.</param>
|
||||||
/// <returns>The current <see cref="GameSpec"/>, for chaining convenience.</returns>
|
/// <returns>The current <see cref="GameSpec"/>, for chaining convenience.</returns>
|
||||||
public GameSpec AddSparseMultiValueFormatter(int priority, string[] reportKeys,
|
public GameSpec AddSparseMultiValueFormatter(
|
||||||
SparseMultiValueFormatter valueFormatter)
|
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>(T formatterSpec) where T : FormatterSpecBase
|
||||||
|
{
|
||||||
|
ValueFormatters.Add(formatterSpec);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -180,16 +189,17 @@ namespace Ryujinx.Ava.Utilities.PlayReport
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class FormatterSpecBase
|
public abstract class FormatterSpecBase
|
||||||
{
|
{
|
||||||
public abstract bool GetData(Horizon.Prepo.Types.PlayReport playReport, out object data);
|
public abstract bool GetData(Horizon.Prepo.Types.PlayReport playReport, out object data);
|
||||||
|
|
||||||
public int Priority { get; init; }
|
public int Priority { get; init; }
|
||||||
public string[] ReportKeys { get; init; }
|
public string[] ReportKeys { get; init; }
|
||||||
public Delegate Formatter { 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;
|
formattedValue = default;
|
||||||
if (!GetData(playReport, out object data))
|
if (!GetData(playReport, out object data))
|
||||||
@ -207,11 +217,16 @@ namespace Ryujinx.Ava.Utilities.PlayReport
|
|||||||
formattedValue = svf(new SingleValue(mpo) { Application = appMeta, PlayReport = playReport });
|
formattedValue = svf(new SingleValue(mpo) { Application = appMeta, PlayReport = playReport });
|
||||||
return true;
|
return true;
|
||||||
case MultiValueFormatter mvf when data is List<MessagePackObject> messagePackObjects:
|
case MultiValueFormatter mvf when data is List<MessagePackObject> messagePackObjects:
|
||||||
formattedValue = mvf(new MultiValue(messagePackObjects) { Application = appMeta, PlayReport = playReport });
|
formattedValue =
|
||||||
|
mvf(new MultiValue(messagePackObjects) { Application = appMeta, PlayReport = playReport });
|
||||||
return true;
|
return true;
|
||||||
case SparseMultiValueFormatter smvf when
|
case SparseMultiValueFormatter smvf when
|
||||||
data is Dictionary<string, MessagePackObject> sparseMessagePackObjects:
|
data is Dictionary<string, MessagePackObject> sparseMessagePackObjects:
|
||||||
formattedValue = smvf(new SparseMultiValue(sparseMessagePackObjects) { Application = appMeta, PlayReport = playReport });
|
formattedValue =
|
||||||
|
smvf(new SparseMultiValue(sparseMessagePackObjects)
|
||||||
|
{
|
||||||
|
Application = appMeta, PlayReport = playReport
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
throw new InvalidOperationException("Formatter delegate is not of a known type!");
|
throw new InvalidOperationException("Formatter delegate is not of a known type!");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user