CompatibilityViewModel.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using CommunityToolkit.Mvvm.ComponentModel;
  2. using Gommon;
  3. using Ryujinx.Ava.UI.ViewModels;
  4. using Ryujinx.Ava.Utilities.AppLibrary;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. namespace Ryujinx.Ava.Utilities.Compat
  8. {
  9. public class CompatibilityViewModel : BaseModel
  10. {
  11. private bool _onlyShowOwnedGames = true;
  12. private IEnumerable<CompatibilityEntry> _currentEntries = CompatibilityCsv.Entries;
  13. private string[] _ownedGameTitleIds = [];
  14. public IEnumerable<CompatibilityEntry> CurrentEntries => OnlyShowOwnedGames
  15. ? _currentEntries.Where(x =>
  16. x.TitleId.Check(tid => _ownedGameTitleIds.ContainsIgnoreCase(tid)))
  17. : _currentEntries;
  18. public CompatibilityViewModel() {}
  19. public CompatibilityViewModel(ApplicationLibrary appLibrary)
  20. {
  21. appLibrary.ApplicationCountUpdated += (_, _)
  22. => _ownedGameTitleIds = appLibrary.Applications.Keys.Select(x => x.ToString("X16")).ToArray();
  23. _ownedGameTitleIds = appLibrary.Applications.Keys.Select(x => x.ToString("X16")).ToArray();
  24. }
  25. public bool OnlyShowOwnedGames
  26. {
  27. get => _onlyShowOwnedGames;
  28. set
  29. {
  30. OnPropertyChanging();
  31. OnPropertyChanging(nameof(CurrentEntries));
  32. _onlyShowOwnedGames = value;
  33. OnPropertyChanged();
  34. OnPropertyChanged(nameof(CurrentEntries));
  35. }
  36. }
  37. public void Search(string searchTerm)
  38. {
  39. if (string.IsNullOrEmpty(searchTerm))
  40. {
  41. SetEntries(CompatibilityCsv.Entries);
  42. return;
  43. }
  44. SetEntries(CompatibilityCsv.Entries.Where(x =>
  45. x.GameName.ContainsIgnoreCase(searchTerm)
  46. || x.TitleId.Check(tid => tid.ContainsIgnoreCase(searchTerm))));
  47. }
  48. private void SetEntries(IEnumerable<CompatibilityEntry> entries)
  49. {
  50. #pragma warning disable MVVMTK0034
  51. _currentEntries = entries.ToList();
  52. #pragma warning restore MVVMTK0034
  53. OnPropertyChanged(nameof(CurrentEntries));
  54. }
  55. }
  56. }