MatchedValues.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using MsgPack;
  2. using Ryujinx.Ava.Utilities.AppLibrary;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. namespace Ryujinx.Ava.Utilities.PlayReport
  6. {
  7. public abstract class MatchedValue<T>
  8. {
  9. public MatchedValue(T matched)
  10. {
  11. Matched = matched;
  12. }
  13. /// <summary>
  14. /// The currently running application's <see cref="ApplicationMetadata"/>.
  15. /// </summary>
  16. public ApplicationMetadata Application { get; init; }
  17. /// <summary>
  18. /// The entire play report.
  19. /// </summary>
  20. public Horizon.Prepo.Types.PlayReport PlayReport { get; init; }
  21. /// <summary>
  22. /// The matched value from the Play Report.
  23. /// </summary>
  24. public T Matched { get; init; }
  25. }
  26. /// <summary>
  27. /// The input data to a <see cref="ValueFormatter"/>,
  28. /// containing the currently running application's <see cref="ApplicationMetadata"/>,
  29. /// and the matched <see cref="MessagePackObject"/> from the Play Report.
  30. /// </summary>
  31. public class SingleValue : MatchedValue<Value>
  32. {
  33. public SingleValue(Value matched) : base(matched)
  34. {
  35. }
  36. public static implicit operator SingleValue(MessagePackObject mpo) => new(mpo);
  37. }
  38. /// <summary>
  39. /// The input data to a <see cref="MultiValueFormatter"/>,
  40. /// containing the currently running application's <see cref="ApplicationMetadata"/>,
  41. /// and the matched <see cref="MessagePackObject"/>s from the Play Report.
  42. /// </summary>
  43. public class MultiValue : MatchedValue<Value[]>
  44. {
  45. public MultiValue(Value[] matched) : base(matched)
  46. {
  47. }
  48. public MultiValue(IEnumerable<MessagePackObject> matched) : base(Value.ConvertPackedObjects(matched))
  49. {
  50. }
  51. public static implicit operator MultiValue(List<MessagePackObject> matched)
  52. => new(matched.Select(x => new Value(x)).ToArray());
  53. }
  54. /// <summary>
  55. /// The input data to a <see cref="SparseMultiValueFormatter"/>,
  56. /// containing the currently running application's <see cref="ApplicationMetadata"/>,
  57. /// and the matched <see cref="MessagePackObject"/>s from the Play Report.
  58. /// </summary>
  59. public class SparseMultiValue : MatchedValue<Dictionary<string, Value>>
  60. {
  61. public SparseMultiValue(Dictionary<string, Value> matched) : base(matched)
  62. {
  63. }
  64. public SparseMultiValue(Dictionary<string, MessagePackObject> matched) : base(Value.ConvertPackedObjectMap(matched))
  65. {
  66. }
  67. public static implicit operator SparseMultiValue(Dictionary<string, MessagePackObject> matched)
  68. => new(matched
  69. .ToDictionary(
  70. x => x.Key,
  71. x => new Value(x.Value)
  72. )
  73. );
  74. }
  75. }