misc: chore: unify GameSpec creation

This commit is contained in:
Evan Husted 2025-02-09 00:37:54 -06:00
parent 05e991db87
commit 764c9e9d4e
2 changed files with 20 additions and 7 deletions

View file

@ -31,8 +31,7 @@ namespace Ryujinx.Ava.Utilities.PlayReport
Guard.Ensure(ulong.TryParse(titleId, NumberStyles.HexNumber, null, out _),
$"Cannot use a non-hexadecimal string as the Title ID for a {nameof(GameSpec)}.");
_specs.Add(transform(new GameSpec { TitleIds = [titleId] }));
return this;
return AddSpec(transform(GameSpec.Create(titleId)));
}
/// <summary>
@ -46,8 +45,7 @@ namespace Ryujinx.Ava.Utilities.PlayReport
Guard.Ensure(ulong.TryParse(titleId, NumberStyles.HexNumber, null, out _),
$"Cannot use a non-hexadecimal string as the Title ID for a {nameof(GameSpec)}.");
_specs.Add(new GameSpec { TitleIds = [titleId] }.Apply(transform));
return this;
return AddSpec(GameSpec.Create(titleId).Apply(transform));
}
/// <summary>
@ -63,8 +61,7 @@ namespace Ryujinx.Ava.Utilities.PlayReport
Guard.Ensure(tids.All(x => ulong.TryParse(x, NumberStyles.HexNumber, null, out _)),
$"Cannot use a non-hexadecimal string as the Title ID for a {nameof(GameSpec)}.");
_specs.Add(transform(new GameSpec { TitleIds = [..tids] }));
return this;
return AddSpec(transform(GameSpec.Create(tids)));
}
/// <summary>
@ -79,7 +76,17 @@ namespace Ryujinx.Ava.Utilities.PlayReport
Guard.Ensure(tids.All(x => ulong.TryParse(x, NumberStyles.HexNumber, null, out _)),
$"Cannot use a non-hexadecimal string as the Title ID for a {nameof(GameSpec)}.");
_specs.Add(new GameSpec { TitleIds = [..tids] }.Apply(transform));
return AddSpec(GameSpec.Create(tids).Apply(transform));
}
/// <summary>
/// Add an analysis spec matching a specific game by title ID, with the provided pre-configured spec.
/// </summary>
/// <param name="spec">The <see cref="GameSpec"/> to add.</param>
/// <returns>The current <see cref="Analyzer"/>, for chaining convenience.</returns>
public Analyzer AddSpec(GameSpec spec)
{
_specs.Add(spec);
return this;
}

View file

@ -14,6 +14,12 @@ namespace Ryujinx.Ava.Utilities.PlayReport
/// </summary>
public class GameSpec
{
public static GameSpec Create(string requiredTitleId, params IEnumerable<string> otherTitleIds)
=> new() { TitleIds = otherTitleIds.Prepend(requiredTitleId).ToArray() };
public static GameSpec Create(IEnumerable<string> titleIds)
=> new() { TitleIds = titleIds.ToArray() };
private int _lastPriority;
public required string[] TitleIds { get; init; }