From 3819e5f5b78bcf6a7280552b60b6bc64e4d867d9 Mon Sep 17 00:00:00 2001 From: Citrinate Date: Sat, 24 Feb 2024 19:35:29 -0500 Subject: [PATCH] Added WishlistOnly filter #23 --- FreePackages/Data/FilterConfig.cs | 3 +++ FreePackages/Data/UserData.cs | 6 ++++++ FreePackages/Handlers/PackageFilter.cs | 9 +++++++++ 3 files changed, 18 insertions(+) diff --git a/FreePackages/Data/FilterConfig.cs b/FreePackages/Data/FilterConfig.cs index 3351ccb..ded9b39 100644 --- a/FreePackages/Data/FilterConfig.cs +++ b/FreePackages/Data/FilterConfig.cs @@ -55,6 +55,9 @@ internal sealed class FilterConfig { [JsonProperty(Required = Required.Default)] internal HashSet Systems = new(); + [JsonProperty(Required = Required.Default)] + internal bool WishlistOnly = false; + [JsonConstructor] internal FilterConfig() { } } diff --git a/FreePackages/Data/UserData.cs b/FreePackages/Data/UserData.cs index cb7d218..1ddeeee 100644 --- a/FreePackages/Data/UserData.cs +++ b/FreePackages/Data/UserData.cs @@ -21,6 +21,12 @@ internal sealed class UserData { [JsonProperty(PropertyName = "rgExcludedContentDescriptorIDs", Required = Required.Always)] internal HashSet ExcludedContentDescriptorIDs = new(); + [JsonProperty(PropertyName = "rgWishlist", Required = Required.Always)] + internal HashSet WishlistedApps = new(); + + [JsonProperty(PropertyName = "rgFollowedApps", Required = Required.Always)] + internal HashSet FollowedApps = new(); + [JsonExtensionData] internal Dictionary AdditionalData = new(); diff --git a/FreePackages/Handlers/PackageFilter.cs b/FreePackages/Handlers/PackageFilter.cs index b5d84a9..c5d038e 100644 --- a/FreePackages/Handlers/PackageFilter.cs +++ b/FreePackages/Handlers/PackageFilter.cs @@ -83,6 +83,10 @@ internal bool IsRedeemableApp(FilterableApp app, HashSet? includedAppIDs = } internal bool IsAppWantedByFilter(FilterableApp app, FilterConfig filter) { + if (UserData == null) { + throw new InvalidOperationException(nameof(UserData)); + } + if (filter.Types.Count > 0 && app.Type != EAppType.Beta && !app.HasType(filter.Types)) { // Don't require user to specify they want playtests (Beta), this is already implied by the PlaytestMode filter // App isn't a wanted type @@ -115,6 +119,11 @@ internal bool IsAppWantedByFilter(FilterableApp app, FilterConfig filter) { return false; } + if (filter.WishlistOnly && !UserData.WishlistedApps.Contains(app.ID) && !UserData.FollowedApps.Contains(app.ID)) { + // Unwated to due not being wishlisted or followed on the Steam storefront + return false; + } + return true; }