コード例 #1
0
        public GamePassCatalogBrowserService(IPlayniteAPI api, string dataPath, bool _notifyCatalogUpdates, bool _addExpiredTagToGames, bool _addNewGames, bool _removeExpiredGames, string _countryCode, string _languageCode = "en-us")
        {
            playniteApi          = api;
            userDataPath         = dataPath;
            notifyCatalogUpdates = _notifyCatalogUpdates;
            addExpiredTagToGames = _addExpiredTagToGames;
            addNewGames          = _addNewGames;
            removeExpiredGames   = _removeExpiredGames;
            client = new HttpClient();
            client.DefaultRequestHeaders.Add("Accept", "application/json");

            cachePath               = Path.Combine(userDataPath, "cache");
            imageCachePath          = Path.Combine(cachePath, "images");
            gameDataCachePath       = Path.Combine(cachePath, "gamesCache.json");
            languageCode            = _languageCode;
            countryCode             = _countryCode;
            gamepassCatalogApiUrl   = string.Format(gamepassCatalogApiBaseUrl, languageCode, countryCode);
            gamepassEaCatalogApiUrl = string.Format(gamepassEaCatalogApiBaseUrl, languageCode, countryCode);

            xboxLibraryHelper = new XboxLibraryHelper(api);
        }
コード例 #2
0
        public CatalogBrowserViewModel(List <GamePassGame> list, IPlayniteAPI api)
        {
            PlayniteApi = api;

            xboxLibraryHelper = new XboxLibraryHelper(api);

            IList <GamePassGame> gamePassGames = list;

            _gamePassGamesView = CollectionViewSource.GetDefaultView(gamePassGames);

            _gamePassGamesView.CurrentChanged += GamePassGameSelectionChanged;

            void GamePassGameSelectionChanged(object sender, EventArgs e)
            {
                // Not implemented
            }

            _gamePassGamesView.Filter = GamePassGameFilter;


            bool IsGameInGenre(GamePassGame game)
            {
                if (_categoriesFilterString == "All")
                {
                    return(true);
                }
                else if (string.IsNullOrEmpty(game.Category))
                {
                    return(false);
                }
                else if (game.Category == _categoriesFilterString)
                {
                    return(true);
                }

                return(false);
            }

            bool GameContainsString(GamePassGame game)
            {
                if (string.IsNullOrEmpty(_searchString))
                {
                    return(IsGameInGenre(game));
                }
                else if (game.Name.ToLower().Contains(_searchString.ToLower()))
                {
                    return(IsGameInGenre(game));
                }
                else
                {
                    return(false);
                }
            }

            bool GamePassGameFilter(object item)
            {
                GamePassGame game = item as GamePassGame;

                switch (game.ProductType)
                {
                case ProductType.Game:
                    if (_collectionsFilterString != "Games")
                    {
                        return(false);
                    }
                    break;

                case ProductType.Collection:
                    if (_collectionsFilterString != "Collections")
                    {
                        return(false);
                    }
                    break;

                case ProductType.EaGame:
                    if (_collectionsFilterString != "EA Games")
                    {
                        return(false);
                    }
                    break;

                default:
                    break;
                }

                if (showGamesOnLibrary == false)
                {
                    if (xboxLibraryHelper.GameIdsInLibrary.Contains(game.GameId))
                    {
                        return(false);
                    }
                    else
                    {
                        return(GameContainsString(game));
                    }
                }

                return(GameContainsString(game));
            }

            IList <string> collections = GetCollectionsList();

            _collectionsView = CollectionViewSource.GetDefaultView(collections);

            _collectionsView.CurrentChanged += CollectionSelectionChanged;

            void CollectionSelectionChanged(object sender, EventArgs e)
            {
                CollectionsFilterString = Collections.CurrentItem.ToString();
            }

            List <string> GetCollectionsList()
            {
                return(new List <string>()
                {
                    { "Games" },
                    { "EA Games" },
                    { "Collections" }
                });
            }

            IList <string> categories = GetCategoriesList(list);

            _categoriesView = CollectionViewSource.GetDefaultView(categories);

            _categoriesView.CurrentChanged += CategoriesSelectionChanged;

            void CategoriesSelectionChanged(object sender, EventArgs e)
            {
                CategoriesFilterString = Categories.CurrentItem.ToString();
            }

            List <string> GetCategoriesList(List <GamePassGame> collection)
            {
                var categoriesList = new List <string>()
                {
                    { "All" }
                };
                var categoriesTempList = collection.Select(x => x.Category).
                                         Where(a => a != null).Distinct().
                                         OrderBy(c => c).ToList();

                foreach (string category in categoriesTempList)
                {
                    categoriesList.Add(category);
                }
                return(categoriesList);
            }
        }