Implement basic filters and LBP2 CrossController fixes (#758)

* implement basic filters and lbp2cc fixes

* lbp3 hide lbp2cc slots

* hide lbp2cc levels from hearted and most played categories in lbp3 and basic filters for lbp3

---------

Co-authored-by: jackcaver <jackcaver@users.noreply.github.com>
Co-authored-by: koko <koko@drones.gay>
This commit is contained in:
jackcaver 2023-05-04 20:42:31 +06:00 committed by GitHub
commit 9deff7ce63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 233 additions and 67 deletions

View file

@ -35,9 +35,9 @@ public class CustomCategory : Category
public sealed override string Description { get; set; }
public sealed override string IconHash { get; set; }
public sealed override string Endpoint { get; set; }
public override SlotEntity? GetPreviewSlot(DatabaseContext database) => database.Slots.FirstOrDefault(s => s.SlotId == this.SlotIds[0]);
public override SlotEntity? GetPreviewSlot(DatabaseContext database) => database.Slots.FirstOrDefault(s => s.SlotId == this.SlotIds[0] && !s.CrossControllerRequired);
public override IQueryable<SlotEntity> GetSlots
(DatabaseContext database, int pageStart, int pageSize)
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3).Where(s => this.SlotIds.Contains(s.SlotId));
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3).Where(s => this.SlotIds.Contains(s.SlotId) && !s.CrossControllerRequired);
public override int GetTotalSlots(DatabaseContext database) => this.SlotIds.Count;
}

View file

@ -17,7 +17,7 @@ public class HeartedCategory : CategoryWithUser
public override string Endpoint { get; set; } = "hearted";
public override SlotEntity? GetPreviewSlot(DatabaseContext database, UserEntity user) // note: developer slots act up in LBP3 when listed here, so I omitted it
=> database.HeartedLevels.Where(h => h.UserId == user.UserId)
.Where(h => h.Slot.Type == SlotType.User && !h.Slot.Hidden && h.Slot.GameVersion <= GameVersion.LittleBigPlanet3)
.Where(h => h.Slot.Type == SlotType.User && !h.Slot.Hidden && h.Slot.GameVersion <= GameVersion.LittleBigPlanet3 && !h.Slot.CrossControllerRequired)
.OrderByDescending(h => h.HeartedLevelId)
.Include(h => h.Slot.Creator)
.Select(h => h.Slot)
@ -26,7 +26,7 @@ public class HeartedCategory : CategoryWithUser
public override IQueryable<SlotEntity> GetSlots(DatabaseContext database, UserEntity user, int pageStart, int pageSize)
=> database.HeartedLevels.Where(h => h.UserId == user.UserId)
.Where(h => h.Slot.Type == SlotType.User && !h.Slot.Hidden && h.Slot.GameVersion <= GameVersion.LittleBigPlanet3)
.Where(h => h.Slot.Type == SlotType.User && !h.Slot.Hidden && h.Slot.GameVersion <= GameVersion.LittleBigPlanet3 && !h.Slot.CrossControllerRequired)
.OrderByDescending(h => h.HeartedLevelId)
.Include(h => h.Slot.Creator)
.Select(h => h.Slot)

View file

@ -16,7 +16,7 @@ public class HighestRatedCategory : Category
public override string IconHash { get; set; } = "g820603";
public override string Endpoint { get; set; } = "thumbs";
public override SlotEntity? GetPreviewSlot(DatabaseContext database) =>
database.Slots.Where(s => s.Type == SlotType.User)
database.Slots.Where(s => s.Type == SlotType.User && !s.CrossControllerRequired)
.Select(s => new SlotMetadata
{
Slot = s,
@ -28,6 +28,7 @@ public class HighestRatedCategory : Category
public override IEnumerable<SlotEntity> GetSlots(DatabaseContext database, int pageStart, int pageSize) =>
database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
.Where(s => !s.CrossControllerRequired)
.Select(s => new SlotMetadata
{
Slot = s,

View file

@ -14,10 +14,11 @@ public class LuckyDipCategory : Category
public override string Description { get; set; } = "A random selection of content";
public override string IconHash { get; set; } = "g820605";
public override string Endpoint { get; set; } = "lbp2luckydip";
public override SlotEntity? GetPreviewSlot(DatabaseContext database) => database.Slots.Where(s => s.Type == SlotType.User).OrderByDescending(_ => EF.Functions.Random()).FirstOrDefault();
public override SlotEntity? GetPreviewSlot(DatabaseContext database) => database.Slots.Where(s => s.Type == SlotType.User && !s.CrossControllerRequired).OrderByDescending(_ => EF.Functions.Random()).FirstOrDefault();
public override IQueryable<SlotEntity> GetSlots
(DatabaseContext database, int pageStart, int pageSize)
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
.Where(s => !s.CrossControllerRequired)
.OrderByDescending(_ => EF.Functions.Random())
.Skip(Math.Max(0, pageStart - 1))
.Take(Math.Min(pageSize, 20));

View file

@ -16,7 +16,7 @@ public class MostHeartedCategory : Category
public override string Endpoint { get; set; } = "mostHearted";
public override SlotEntity? GetPreviewSlot(DatabaseContext database) =>
database.Slots.Where(s => s.Type == SlotType.User)
database.Slots.Where(s => s.Type == SlotType.User && !s.CrossControllerRequired)
.Select(s => new SlotMetadata
{
Slot = s,
@ -28,6 +28,7 @@ public class MostHeartedCategory : Category
public override IEnumerable<SlotEntity> GetSlots(DatabaseContext database, int pageStart, int pageSize) =>
database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
.Where(s => !s.CrossControllerRequired)
.Select(s => new SlotMetadata
{
Slot = s,

View file

@ -14,13 +14,14 @@ public class MostPlayedCategory : Category
public override string IconHash { get; set; } = "g820608";
public override string Endpoint { get; set; } = "mostUniquePlays";
public override SlotEntity? GetPreviewSlot(DatabaseContext database) => database.Slots
.Where(s => s.Type == SlotType.User)
.Where(s => s.Type == SlotType.User && !s.CrossControllerRequired)
.OrderByDescending(s => s.PlaysLBP1Unique + s.PlaysLBP2Unique + s.PlaysLBP3Unique)
.ThenByDescending(s => s.PlaysLBP1 + s.PlaysLBP2 + s.PlaysLBP3)
.FirstOrDefault();
public override IQueryable<SlotEntity> GetSlots
(DatabaseContext database, int pageStart, int pageSize)
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
.Where(s => !s.CrossControllerRequired)
.OrderByDescending(s => s.PlaysLBP1Unique + s.PlaysLBP2Unique + s.PlaysLBP3Unique)
.ThenByDescending(s => s.PlaysLBP1 + s.PlaysLBP2 + s.PlaysLBP3)
.Skip(Math.Max(0, pageStart - 1))

View file

@ -13,10 +13,11 @@ public class NewestLevelsCategory : Category
public override string Description { get; set; } = "The most recently published content";
public override string IconHash { get; set; } = "g820623";
public override string Endpoint { get; set; } = "newest";
public override SlotEntity? GetPreviewSlot(DatabaseContext database) => database.Slots.Where(s => s.Type == SlotType.User).OrderByDescending(s => s.FirstUploaded).FirstOrDefault();
public override SlotEntity? GetPreviewSlot(DatabaseContext database) => database.Slots.Where(s => s.Type == SlotType.User && !s.CrossControllerRequired).OrderByDescending(s => s.FirstUploaded).FirstOrDefault();
public override IQueryable<SlotEntity> GetSlots
(DatabaseContext database, int pageStart, int pageSize)
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
.Where(s => !s.CrossControllerRequired)
.OrderByDescending(s => s.FirstUploaded)
.Skip(Math.Max(0, pageStart - 1))
.Take(Math.Min(pageSize, 20));

View file

@ -13,12 +13,12 @@ public class TeamPicksCategory : Category
public override string Description { get; set; } = "Community Team Picks";
public override string IconHash { get; set; } = "g820626";
public override string Endpoint { get; set; } = "team_picks";
public override SlotEntity? GetPreviewSlot(DatabaseContext database) => database.Slots.OrderByDescending(s => s.FirstUploaded).FirstOrDefault(s => s.TeamPick);
public override SlotEntity? GetPreviewSlot(DatabaseContext database) => database.Slots.OrderByDescending(s => s.FirstUploaded).FirstOrDefault(s => s.TeamPick && !s.CrossControllerRequired);
public override IQueryable<SlotEntity> GetSlots
(DatabaseContext database, int pageStart, int pageSize)
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
.OrderByDescending(s => s.FirstUploaded)
.Where(s => s.TeamPick)
.Where(s => s.TeamPick && !s.CrossControllerRequired)
.Skip(Math.Max(0, pageStart - 1))
.Take(Math.Min(pageSize, 20));
public override int GetTotalSlots(DatabaseContext database) => database.Slots.Count(s => s.TeamPick);