Skip to content

Commit

Permalink
Allow searching replays by is-MM and rating type. (#2787)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aquanim authored Apr 6, 2024
1 parent 144f611 commit 2714e86
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Shared/PlasmaShared/ISpringieService/RatingCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ public enum RatingCategoryFlags
{
Casual = 1, MatchMaking = 2, Planetwars = 4
}
public enum RatingSearchOption
{
Any = 0, None = 1, Casual = 2, Competitive = 3, Planetwars = 4
}
}
30 changes: 30 additions & 0 deletions Zero-K.info/Controllers/BattlesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,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 RatingSearchOption Rating { get; set; }
public RankSelector Rank { get; set; } = RankSelector.Undefined;

public int? MinLength { get; set; }
Expand Down Expand Up @@ -166,6 +168,34 @@ 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 != RatingSearchOption.Any)
{
switch (model.Rating)
{
case RatingSearchOption.Competitive:
q = q.Where(b => b.ApplicableRatings.HasFlag(RatingCategoryFlags.MatchMaking));
break;
case RatingSearchOption.Casual:
q = q.Where(b => b.ApplicableRatings.HasFlag(RatingCategoryFlags.Casual));
break;
case RatingSearchOption.Planetwars:
q = q.Where(b => b.ApplicableRatings.HasFlag(RatingCategoryFlags.Planetwars));
break;
case RatingSearchOption.None:
q = q.Where(b => b.ApplicableRatings == 0);
break;
default:
// The default case being no filtering should be safe enough.
break;
}
}

q = q.OrderByDescending(b => b.StartTime);

if (model.offset.HasValue) q = q.Skip(model.offset.Value);
Expand Down
32 changes: 30 additions & 2 deletions Zero-K.info/Views/Battles/BattleDetail.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,37 @@
@Model.IsMission
</td>
</tr>
<tr>
<td>
Rating:
</td>
<td>
@{
if (Model.IsRatedMatch())
{
switch (Model.GetRatingCategory())
{
case RatingCategory.MatchMaking:
<text>Competitive</text>
break;
case RatingCategory.Casual:
<text>Casual</text>
break;
case RatingCategory.Planetwars:
<text>Planetwars</text>
break;
}
}
else
{
<text>None</text>
}
}
</td>
</tr>
</table>
@if (!string.IsNullOrEmpty(Model.ReplayFileName))
{
{
<a href="@Html.PrintSpringLink(string.Format("@start_replay:{0},{1},{2},{3}", GlobalConst.BaseSiteUrl+ "/replays/" + Path.GetFileName(Model.ReplayFileName), Model.ResourceByModResourceID.InternalName, Model.ResourceByMapResourceID.InternalName, Model.EngineVersion, Model.SpringBattleID))">
<span class="textbutton" style="font-size: 130%">Watch Replay Now</span>
</a>
Expand All @@ -112,7 +140,7 @@
<a href='/replays/@Model.ReplayFileName'>Manual download</a>
<br />
}
}
}
</div>
<br class="clearfloat" />
<div>
Expand Down
18 changes: 12 additions & 6 deletions Zero-K.info/Views/Battles/BattleIndex.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@
<form action="@Url.Action("Index")" id="ajaxScrollForm" method="post">
<table class="inputTable">
<tr>
<td>Title: </td><td>@Html.TextBoxFor(x => x.Title)</td>
<td>Map: </td><td>@Html.TextBoxFor(x => x.Map, new { data_autocomplete = Url.Action("Maps", "Autocomplete"), data_autocomplete_action = "submit" })</td>
<td>Title: </td>
<td>@Html.TextBoxFor(x => x.Title)</td>
<td>Map: </td>
<td>@Html.TextBoxFor(x => x.Map, new { data_autocomplete = Url.Action("Maps", "Autocomplete"), data_autocomplete_action = "submit" })</td>
</tr>
<tr>
<td>Players: </td>
<td>
@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)));
}
</td>
<td>Player count: </td><td> @Html.TextBoxFor(x => x.PlayersFrom) - @Html.TextBoxFor(x => x.PlayersTo)</td>
</tr>
<tr>
<td>Player count: </td>
<td> @Html.TextBoxFor(x => x.PlayersFrom) - @Html.TextBoxFor(x => x.PlayersTo)</td>
</tr>
<tr></tr>
<tr>
<td>Age:</td>
<td>@Html.EnumDropDownListFor(x => x.Age)</td>
Expand All @@ -30,6 +34,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)
<input name="sa" value="Search" alt="Search" type="image" src="/img/search_img.png" style="border: none; vertical-align: middle;" />
</td>
</tr>
Expand Down

0 comments on commit 2714e86

Please sign in to comment.