From 831244681365e51c2ef2a4fc73377027acdc8d63 Mon Sep 17 00:00:00 2001 From: Aquanim Date: Tue, 26 Jan 2021 14:13:53 +1100 Subject: [PATCH 1/3] Allow searching by is-MM and rating type. --- Zero-K.info/Controllers/BattlesController.cs | 40 ++++++++++++++++++++ Zero-K.info/Views/Battles/BattleIndex.cshtml | 18 ++++++--- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/Zero-K.info/Controllers/BattlesController.cs b/Zero-K.info/Controllers/BattlesController.cs index a80e05e624..d77e42d92d 100644 --- a/Zero-K.info/Controllers/BattlesController.cs +++ b/Zero-K.info/Controllers/BattlesController.cs @@ -46,6 +46,8 @@ public class BattleSearchModel public YesNoAny Mission { get; set; } public YesNoAny Bots { get; set; } public YesNoAny Victory { get; set; } + public YesNoAny Matchmaker { get; set; } + public RatingOption Rating { get; set; } public RankSelector Rank { get; set; } = RankSelector.Undefined; public int? offset { get; set; } public List Data; @@ -68,6 +70,15 @@ public enum AgeOption ThisMonth = 3 } + public enum RatingOption + { + Any = 0, + Casual = 1, + Competitive = 2, + Planetwars = 3, + None = 4 + } + /// /// Returns the main battle replay list; params filter /// @@ -138,6 +149,35 @@ public ActionResult Index(BattleSearchModel model) { q = q.Where(b => b.Rank == rank); } + if (model.Matchmaker != YesNoAny.Any) + { + var bval = model.Matchmaker == YesNoAny.Yes; + q = q.Where(b => b.IsMatchMaker == bval); + } + + if (model.Rating != RatingOption.Any) + { + switch (model.Rating) + { + case RatingOption.Competitive: + //q = q.Where(b => b.IsRatedMatch() && b.GetRatingCategory() == RatingCategory.MatchMaking); + q = q.Where(b => b.ApplicableRatings.HasFlag(RatingCategoryFlags.MatchMaking)); + break; + case RatingOption.Casual: + //q = q.Where(b => b.IsRatedMatch() && b.GetRatingCategory() == RatingCategory.Casual); + q = q.Where(b => b.ApplicableRatings.HasFlag(RatingCategoryFlags.Casual)); + break; + case RatingOption.Planetwars: + //q = q.Where(b => b.IsRatedMatch() && b.GetRatingCategory() == RatingCategory.Planetwars); + q = q.Where(b => b.ApplicableRatings.HasFlag(RatingCategoryFlags.Planetwars)); + break; + case RatingOption.None: + //q = q.Where(b => !b.IsRatedMatch()); + q = q.Where(b => b.ApplicableRatings == 0); + break; + } + } + q = q.OrderByDescending(b => b.StartTime); if (model.offset.HasValue) q = q.Skip(model.offset.Value); diff --git a/Zero-K.info/Views/Battles/BattleIndex.cshtml b/Zero-K.info/Views/Battles/BattleIndex.cshtml index 0690246123..591a5ccf1d 100644 --- a/Zero-K.info/Views/Battles/BattleIndex.cshtml +++ b/Zero-K.info/Views/Battles/BattleIndex.cshtml @@ -6,18 +6,22 @@
- - + + + + - - - + + + From 055945944e301c5cfa86991edba3c976bf4c147d Mon Sep 17 00:00:00 2001 From: Aquanim Date: Wed, 27 Jan 2021 15:28:32 +1100 Subject: [PATCH 2/3] Refactor rating search. Display replays' primary rating type to users. --- .../ISpringieService/RatingCategory.cs | 4 +++ Zero-K.info/Controllers/BattlesController.cs | 28 ++++++---------- Zero-K.info/Views/Battles/BattleDetail.cshtml | 32 +++++++++++++++++-- 3 files changed, 43 insertions(+), 21 deletions(-) diff --git a/Shared/PlasmaShared/ISpringieService/RatingCategory.cs b/Shared/PlasmaShared/ISpringieService/RatingCategory.cs index fea5adc3d1..aabc3a1129 100644 --- a/Shared/PlasmaShared/ISpringieService/RatingCategory.cs +++ b/Shared/PlasmaShared/ISpringieService/RatingCategory.cs @@ -11,4 +11,8 @@ public enum RatingCategoryFlags { Casual = 1, MatchMaking = 2, Planetwars = 4 } + public enum RatingSearchOption + { + Any = 0, Casual = 1, Competitive = 2, Planetwars = 3, None = 4 + } } diff --git a/Zero-K.info/Controllers/BattlesController.cs b/Zero-K.info/Controllers/BattlesController.cs index d77e42d92d..630917057e 100644 --- a/Zero-K.info/Controllers/BattlesController.cs +++ b/Zero-K.info/Controllers/BattlesController.cs @@ -47,7 +47,7 @@ public class BattleSearchModel public YesNoAny Bots { get; set; } public YesNoAny Victory { get; set; } public YesNoAny Matchmaker { get; set; } - public RatingOption Rating { get; set; } + public RatingSearchOption Rating { get; set; } public RankSelector Rank { get; set; } = RankSelector.Undefined; public int? offset { get; set; } public List Data; @@ -70,15 +70,6 @@ public enum AgeOption ThisMonth = 3 } - public enum RatingOption - { - Any = 0, - Casual = 1, - Competitive = 2, - Planetwars = 3, - None = 4 - } - /// /// Returns the main battle replay list; params filter /// @@ -155,26 +146,25 @@ public ActionResult Index(BattleSearchModel model) { q = q.Where(b => b.IsMatchMaker == bval); } - if (model.Rating != RatingOption.Any) + if (model.Rating != RatingSearchOption.Any) { switch (model.Rating) { - case RatingOption.Competitive: - //q = q.Where(b => b.IsRatedMatch() && b.GetRatingCategory() == RatingCategory.MatchMaking); + case RatingSearchOption.Competitive: q = q.Where(b => b.ApplicableRatings.HasFlag(RatingCategoryFlags.MatchMaking)); break; - case RatingOption.Casual: - //q = q.Where(b => b.IsRatedMatch() && b.GetRatingCategory() == RatingCategory.Casual); + case RatingSearchOption.Casual: q = q.Where(b => b.ApplicableRatings.HasFlag(RatingCategoryFlags.Casual)); break; - case RatingOption.Planetwars: - //q = q.Where(b => b.IsRatedMatch() && b.GetRatingCategory() == RatingCategory.Planetwars); + case RatingSearchOption.Planetwars: q = q.Where(b => b.ApplicableRatings.HasFlag(RatingCategoryFlags.Planetwars)); break; - case RatingOption.None: - //q = q.Where(b => !b.IsRatedMatch()); + case RatingSearchOption.None: q = q.Where(b => b.ApplicableRatings == 0); break; + default: + // The default case being no filtering should be safe enough. + break; } } diff --git a/Zero-K.info/Views/Battles/BattleDetail.cshtml b/Zero-K.info/Views/Battles/BattleDetail.cshtml index f7b6115306..1ed2099d3f 100644 --- a/Zero-K.info/Views/Battles/BattleDetail.cshtml +++ b/Zero-K.info/Views/Battles/BattleDetail.cshtml @@ -92,9 +92,37 @@ @Model.IsMission + + + +
Title: @Html.TextBoxFor(x => x.Title)Map: @Html.TextBoxFor(x => x.Map, new { data_autocomplete = Url.Action("Maps", "Autocomplete"), data_autocomplete_action = "submit" })Title: @Html.TextBoxFor(x => x.Title)Map: @Html.TextBoxFor(x => x.Map, new { data_autocomplete = Url.Action("Maps", "Autocomplete"), data_autocomplete_action = "submit" })
Players: - @using (var db = new ZkDataContext()) { @Html.MultiSelectFor(x => x.UserId, Url.Action("UsersNoLink", "Autocomplete"), x => Html.PrintAccount(db.Accounts.Find(x))); } + @using (var db = new ZkDataContext()) + {@Html.MultiSelectFor(x => x.UserId, Url.Action("UsersNoLink", "Autocomplete"), x => Html.PrintAccount(db.Accounts.Find(x))); + } Player count: @Html.TextBoxFor(x => x.PlayersFrom) - @Html.TextBoxFor(x => x.PlayersTo)
Player count: @Html.TextBoxFor(x => x.PlayersFrom) - @Html.TextBoxFor(x => x.PlayersTo)
Age: @Html.EnumDropDownListFor(x => x.Age) @@ -25,6 +29,8 @@ Bots: @Html.EnumDropDownListFor(x => x.Bots) Rank: @Html.EnumDropDownListFor(x => x.Rank) Victory: @Html.EnumDropDownListFor(x => x.Victory) + MM: @Html.EnumDropDownListFor(x => x.Matchmaker) + Rating: @Html.EnumDropDownListFor(x => x.Rating)
+ Rating: + + @{ + if (Model.IsRatedMatch()) + { + switch (Model.GetRatingCategory()) + { + case RatingCategory.MatchMaking: + Competitive + break; + case RatingCategory.Casual: + Casual + break; + case RatingCategory.Planetwars: + Planetwars + break; + } + } + else + { + None + } + } +
@if (!string.IsNullOrEmpty(Model.ReplayFileName)) -{ + { Watch Replay Now @@ -104,7 +132,7 @@ Manual download
} -} + }
From 0b00e80d6d2c081b7cbe381e2c056ec1e65a8fc9 Mon Sep 17 00:00:00 2001 From: Aquanim Date: Sat, 30 Jan 2021 23:58:40 +1100 Subject: [PATCH 3/3] Tweak. --- Shared/PlasmaShared/ISpringieService/RatingCategory.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Shared/PlasmaShared/ISpringieService/RatingCategory.cs b/Shared/PlasmaShared/ISpringieService/RatingCategory.cs index aabc3a1129..e63bbbe1c8 100644 --- a/Shared/PlasmaShared/ISpringieService/RatingCategory.cs +++ b/Shared/PlasmaShared/ISpringieService/RatingCategory.cs @@ -13,6 +13,6 @@ public enum RatingCategoryFlags } public enum RatingSearchOption { - Any = 0, Casual = 1, Competitive = 2, Planetwars = 3, None = 4 + Any = 0, None = 1, Casual = 2, Competitive = 3, Planetwars = 4 } }