From 67cfc29699c871509ec0a6e7bb39423c2b7de35a Mon Sep 17 00:00:00 2001 From: W0lf4llo <96880844+W0lf4llo@users.noreply.github.com> Date: Thu, 1 Dec 2022 23:34:25 -0500 Subject: [PATCH] Added three new categories to LBP3 (#567) * Added three new categories to LBP3 * removed my comment in most hearted --- .../Levels/Categories/CategoryHelper.cs | 3 ++ .../Levels/Categories/HighestRatedCategory.cs | 28 +++++++++++++++++++ .../Levels/Categories/MostHeartedCategory.cs | 27 ++++++++++++++++++ .../Levels/Categories/MostPlayedCategory.cs | 28 +++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 ProjectLighthouse/Levels/Categories/HighestRatedCategory.cs create mode 100644 ProjectLighthouse/Levels/Categories/MostHeartedCategory.cs create mode 100644 ProjectLighthouse/Levels/Categories/MostPlayedCategory.cs diff --git a/ProjectLighthouse/Levels/Categories/CategoryHelper.cs b/ProjectLighthouse/Levels/Categories/CategoryHelper.cs index db7a38b9..7330fbe9 100644 --- a/ProjectLighthouse/Levels/Categories/CategoryHelper.cs +++ b/ProjectLighthouse/Levels/Categories/CategoryHelper.cs @@ -9,7 +9,10 @@ public static class CategoryHelper static CategoryHelper() { Categories.Add(new TeamPicksCategory()); + Categories.Add(new MostHeartedCategory()); Categories.Add(new NewestLevelsCategory()); + Categories.Add(new MostPlayedCategory()); + Categories.Add(new HighestRatedCategory()); Categories.Add(new QueueCategory()); Categories.Add(new HeartedCategory()); Categories.Add(new LuckyDipCategory()); diff --git a/ProjectLighthouse/Levels/Categories/HighestRatedCategory.cs b/ProjectLighthouse/Levels/Categories/HighestRatedCategory.cs new file mode 100644 index 00000000..09a9b249 --- /dev/null +++ b/ProjectLighthouse/Levels/Categories/HighestRatedCategory.cs @@ -0,0 +1,28 @@ +#nullable enable +using System; +using System.Collections.Generic; +using System.Linq; +using LBPUnion.ProjectLighthouse.Extensions; +using LBPUnion.ProjectLighthouse.PlayerData; +using YamlDotNet.Core.Tokens; + +namespace LBPUnion.ProjectLighthouse.Levels.Categories; + +public class HighestRatedCategory : Category +{ + Random rand = new(); + public override string Name { get; set; } = "Highest Rated"; + public override string Description { get; set; } = "Community Highest Rated content"; + public override string IconHash { get; set; } = "g820603"; + public override string Endpoint { get; set; } = "thumbs"; + public override Slot? GetPreviewSlot(Database database) => database.Slots.Where(s => s.Type == SlotType.User).AsEnumerable().OrderByDescending(s => s.Thumbsup).FirstOrDefault(); + public override IEnumerable GetSlots + (Database database, int pageStart, int pageSize) + => database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true) + .AsEnumerable() + .OrderByDescending(s => s.Thumbsup) + .ThenBy(_ => rand.Next()) + .Skip(Math.Max(0, pageStart - 1)) + .Take(Math.Min(pageSize, 20)); + public override int GetTotalSlots(Database database) => database.Slots.Count(s => s.Type == SlotType.User); +} \ No newline at end of file diff --git a/ProjectLighthouse/Levels/Categories/MostHeartedCategory.cs b/ProjectLighthouse/Levels/Categories/MostHeartedCategory.cs new file mode 100644 index 00000000..04c54b01 --- /dev/null +++ b/ProjectLighthouse/Levels/Categories/MostHeartedCategory.cs @@ -0,0 +1,27 @@ +#nullable enable +using System; +using System.Collections.Generic; +using System.Linq; +using LBPUnion.ProjectLighthouse.Extensions; +using LBPUnion.ProjectLighthouse.PlayerData; + +namespace LBPUnion.ProjectLighthouse.Levels.Categories; + +public class MostHeartedCategory : Category +{ + Random rand = new(); + public override string Name { get; set; } = "Most Hearted"; + public override string Description { get; set; } = "The Most Hearted Content"; + public override string IconHash { get; set; } = "g820607"; + public override string Endpoint { get; set; } = "mostHearted"; + public override Slot? GetPreviewSlot(Database database) => database.Slots.Where(s => s.Type == SlotType.User).AsEnumerable().OrderByDescending(s => s.Hearts).FirstOrDefault(); + public override IEnumerable GetSlots + (Database database, int pageStart, int pageSize) + => database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true) + .AsEnumerable() + .OrderByDescending(s => s.Hearts) + .ThenBy(_ => rand.Next()) + .Skip(Math.Max(0, pageStart - 1)) + .Take(Math.Min(pageSize, 20)); + public override int GetTotalSlots(Database database) => database.Slots.Count(s => s.Type == SlotType.User); +} \ No newline at end of file diff --git a/ProjectLighthouse/Levels/Categories/MostPlayedCategory.cs b/ProjectLighthouse/Levels/Categories/MostPlayedCategory.cs new file mode 100644 index 00000000..1828bb78 --- /dev/null +++ b/ProjectLighthouse/Levels/Categories/MostPlayedCategory.cs @@ -0,0 +1,28 @@ +#nullable enable +using System; +using System.Collections.Generic; +using System.Linq; +using LBPUnion.ProjectLighthouse.Extensions; +using LBPUnion.ProjectLighthouse.PlayerData; +using YamlDotNet.Core.Tokens; + +namespace LBPUnion.ProjectLighthouse.Levels.Categories; + +public class MostPlayedCategory : Category +{ + Random rand = new(); + public override string Name { get; set; } = "Most Played"; + public override string Description { get; set; } = "The most played content"; + public override string IconHash { get; set; } = "g820608"; + public override string Endpoint { get; set; } = "mostUniquePlays"; + public override Slot? GetPreviewSlot(Database database) => database.Slots.Where(s => s.Type == SlotType.User).AsEnumerable().OrderByDescending(s => s.PlaysUnique).FirstOrDefault(); + public override IEnumerable GetSlots + (Database database, int pageStart, int pageSize) + => database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true) + .AsEnumerable() + .OrderByDescending(s => s.PlaysUnique) + .ThenBy(_ => rand.Next()) + .Skip(Math.Max(0, pageStart - 1)) + .Take(Math.Min(pageSize, 20)); + public override int GetTotalSlots(Database database) => database.Slots.Count(s => s.Type == SlotType.User); +} \ No newline at end of file