Repository navigation
Added 3 New LBP3 Categories #1109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ff1a5df
daa8007
dda4fc0
cab253c
6a9d17e
6a475af
6bd5dfd
d4bf4d3
d0048c8
93c0c28
1c6cf13
e76d594
5d4f3d5
b051169
aeab303
8b01087
95af005
2686e45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| #nullable enable | ||
| using System.Linq.Expressions; | ||
| using LBPUnion.ProjectLighthouse.Database; | ||
| using LBPUnion.ProjectLighthouse.Filter; | ||
| using LBPUnion.ProjectLighthouse.Helpers; | ||
| using LBPUnion.ProjectLighthouse.Types.Entities.Level; | ||
| using LBPUnion.ProjectLighthouse.Types.Entities.Token; | ||
|
|
||
| namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Types.Categories; | ||
|
|
||
| public class BusiestCategory : SlotCategory | ||
| { | ||
| public override string Name { get; set; } = "Busiest"; | ||
| public override string Description { get; set; } = "Levels being played right now!"; | ||
| public override string IconHash { get; set; } = "g820602"; | ||
| public override string Endpoint { get; set; } = "busiest"; | ||
| public override string Tag => "busiest"; | ||
| public override string[] Sorts { get; } = ["relevance",]; | ||
|
|
||
| public override IQueryable<SlotEntity> GetItems(DatabaseContext database, GameTokenEntity token, SlotQueryBuilder queryBuilder) | ||
| { | ||
| Dictionary<int, int> playerCounts = RoomHelper.GetUserLevelPlayerCounts(); | ||
|
|
||
| if (playerCounts.Count == 0) | ||
| return database.Slots.Where(_ => false); | ||
|
|
||
| List<int> slotIds = playerCounts.Keys.ToList(); | ||
|
|
||
| ParameterExpression slotParameter = Expression.Parameter(typeof(SlotEntity), "slot"); | ||
|
|
||
| MemberExpression slotIdProperty = Expression.Property(slotParameter, nameof(SlotEntity.SlotId)); | ||
|
|
||
| Expression playerCountExpression = Expression.Constant(0); | ||
|
|
||
| foreach (KeyValuePair<int, int> playerCount in playerCounts) | ||
| { | ||
| playerCountExpression = Expression.Condition(Expression.Equal(slotIdProperty, Expression.Constant(playerCount.Key)), Expression.Constant(playerCount.Value), playerCountExpression); | ||
| } | ||
|
|
||
| Expression<Func<SlotEntity, int>> ordering = Expression.Lambda<Func<SlotEntity, int>>(playerCountExpression, slotParameter); | ||
|
|
||
| return database.Slots | ||
| .Where(slot => | ||
| slotIds.Contains(slot.SlotId)) | ||
| .Where(queryBuilder.Build()) | ||
| .OrderByDescending(ordering) | ||
| .ThenByDescending(slot => slot.SlotId); | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overall, I would argue a configuration to manually enable or disable categories by name is a bit unnecessary. But if others disagree with my sentiment, I still think it would be better to use the category's tag or something to put into the configuration rather than separate hardcoded names. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,12 +15,16 @@ public class LuckyDipCategory : SlotCategory | |
| public override string Description { get; set; } = "A random selection of content"; | ||
| public override string IconHash { get; set; } = "g820605"; | ||
| public override string Endpoint { get; set; } = "lucky_dip"; | ||
| public override string Tag => "lucky_dip"; | ||
| public override string Tag => "level_of_the_day"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was the previous tag incorrect? Was nothing being broken before? |
||
| public override string[] Sorts { get; } = ["relevance",]; | ||
| public override bool Curated => false; | ||
| public override bool DisableFilters => true; | ||
| public override bool DefaultToCurrentGame => false; | ||
|
|
||
| public override IQueryable<SlotEntity> GetItems(DatabaseContext database, GameTokenEntity token, SlotQueryBuilder queryBuilder) | ||
| { | ||
| queryBuilder.AddFilter(new LockedSlotFilter()); | ||
| return database.Slots.Where(queryBuilder.Build()) | ||
| .ApplyOrdering(new SlotSortBuilder<SlotEntity>().AddSort(new RandomFirstUploadedSort())); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is a bit long.