This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from Zaxiure/development
Development
- Loading branch information
Showing
33 changed files
with
1,443 additions
and
313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
@using HuntStats.State | ||
@typeparam TValue | ||
@inject AppState AppState | ||
<Dropdown DropdownOpened="FocusSearchInput" AlternateStyle="true" RemoveMargin="true"> | ||
<DropdownClickable> | ||
<input readonly class="form-control" value="@GetInputText()" type="text"/> | ||
</DropdownClickable> | ||
<DropdownContent> | ||
@if (SearchDisabled == null || SearchDisabled == false) | ||
{ | ||
<div class="search-container"> | ||
<input @ref="_searchInput" placeholder="Search..." type="text" class="form-control" value="@_searchValue" @oninput="SetSearchedList"> | ||
</div> | ||
} | ||
<div class="scrollable-container"> | ||
<ul> | ||
@if (searchedList != null) | ||
{ | ||
@foreach (var item in searchedList) | ||
{ | ||
@if (item.Color == null) | ||
{ | ||
<li @key="item" @onclick="() => { SelectItem(item); }"> | ||
@(item.SecondaryVariable == null ? item.Variable : item.Variable + " - " + item.SecondaryVariable) | ||
</li> | ||
} | ||
else | ||
{ | ||
<li @key="item" @onclick="() => { SelectItem(item); }"> | ||
<div class="color-circle" style="background-color: #@item.Color"></div> | ||
<span> | ||
@(item.SecondaryVariable == null ? item.Variable : item.Variable + " - " + item.SecondaryVariable) | ||
</span> | ||
</li> | ||
} | ||
} | ||
} | ||
</ul> | ||
</div> | ||
</DropdownContent> | ||
</Dropdown> | ||
|
||
@code { | ||
[Parameter] | ||
public TValue? Value { get; set; } | ||
|
||
[Parameter] | ||
public EventCallback<TValue> ValueChanged { get; set; } | ||
|
||
[Parameter] | ||
public List<ListItem> ListItems { get; set; } | ||
|
||
[Parameter] | ||
public bool SearchDisabled { get; set; } | ||
|
||
private ElementReference _searchInput; | ||
|
||
private List<ListItem> searchedList; | ||
|
||
private string? _searchValue; | ||
|
||
public string GetInputText() | ||
{ | ||
if (Value != null) | ||
{ | ||
if (ListItems.FirstOrDefault(x => Nullable.Equals(x.Id, Value)) == null) return "Select..."; | ||
return ListItems.FirstOrDefault(x => Nullable.Equals(x.Id, Value))!.Variable; | ||
} | ||
|
||
return "Select..."; | ||
} | ||
|
||
public async Task FocusSearchInput() | ||
{ | ||
if (!SearchDisabled) | ||
{ | ||
await Task.Delay(100); | ||
await _searchInput.FocusAsync(); | ||
} | ||
} | ||
|
||
public void SetSearchedList(ChangeEventArgs args) | ||
{ | ||
_searchValue = args.Value.ToString(); | ||
if (string.IsNullOrEmpty(_searchValue)) | ||
{ | ||
searchedList = ListItems; | ||
} | ||
else | ||
{ | ||
searchedList = ListItems.Where(x => x.Variable.ToLower().Contains(_searchValue.ToLower())).ToList(); | ||
} | ||
StateHasChanged(); | ||
} | ||
|
||
public void SelectItem(ListItem item) | ||
{ | ||
AppState.CloseOpenedDropdown(); | ||
Value = item.Id; | ||
ValueChanged.InvokeAsync(Value); | ||
StateHasChanged(); | ||
} | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
searchedList = ListItems; | ||
} | ||
|
||
public class ListItem | ||
{ | ||
public TValue Id { get; set; } | ||
public string Variable { get; set; } | ||
public string? SecondaryVariable { get; set; } | ||
public string? Color { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div class="tooltip-wrapper"> | ||
<span>@Text</span> | ||
@ChildContent | ||
</div> | ||
|
||
@code { | ||
[Parameter] public RenderFragment ChildContent { get; set; } | ||
[Parameter] public string Text { get; set; } | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
namespace HuntStats.Extensions; | ||
|
||
public static class GeneralExtensions | ||
{ | ||
public static int ToStarRating(this int value) | ||
{ | ||
if (value >= 0 && value < 2000) | ||
{ | ||
return 1; | ||
} | ||
|
||
if (value >= 2000 && value < 2300) | ||
{ | ||
return 2; | ||
} | ||
|
||
if (value >= 2300 && value < 2600) | ||
{ | ||
return 3; | ||
} | ||
|
||
if (value >= 2600 && value < 2750) | ||
{ | ||
return 4; | ||
} | ||
|
||
if (value >= 2750 && value < 3000) | ||
{ | ||
return 5; | ||
} | ||
|
||
return 6; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
using HuntStats.Data; | ||
using MediatR; | ||
|
||
namespace HuntStats.Features; | ||
|
||
public class MmrChartQuery : IRequest<List<ChartInfo>> | ||
{ | ||
public MmrChartQuery(int amount) | ||
{ | ||
Amount = amount; | ||
} | ||
|
||
public int Amount { get; set; } | ||
} | ||
|
||
public class MmrChartQueryHandler : IRequestHandler<MmrChartQuery, List<ChartInfo>> | ||
{ | ||
private readonly IDbConnectionFactory _connectionFactory; | ||
private readonly IMediator _mediator; | ||
|
||
public MmrChartQueryHandler(IDbConnectionFactory connectionFactory, IMediator mediator) | ||
{ | ||
_connectionFactory = connectionFactory; | ||
_mediator = mediator; | ||
} | ||
|
||
public async Task<List<ChartInfo>> Handle(MmrChartQuery request, CancellationToken cancellationToken) | ||
{ | ||
var Matches = await _mediator.Send(new GetMatchCommand()); | ||
var Settings = await _mediator.Send(new GetSettingsCommand()); | ||
Matches = Matches.OrderByDescending(x => x.DateTime).Take(request.Amount).ToList(); | ||
|
||
return Matches.Select(x => | ||
{ | ||
var team = x.Teams.FirstOrDefault(x => x.Players.FirstOrDefault(y => y.ProfileId == Settings.PlayerProfileId) != null); | ||
if (team != null) | ||
{ | ||
var totalMmr = x.Teams.Select(x => x.Players.Select(x => x.Mmr).Sum() / x.Players.Count()).Sum() / x.Teams.Count; | ||
var mmr = team.Players.FirstOrDefault(y => y.ProfileId == Settings.PlayerProfileId).Mmr; | ||
return new ChartInfo | ||
{ | ||
DateTime = x.DateTime, | ||
TotalMmr = totalMmr, | ||
Mmr = mmr | ||
}; | ||
} | ||
return null; | ||
}).Where(x => x != null).OrderBy(x => x.DateTime).ToList(); | ||
} | ||
} | ||
|
||
public class KillChartQuery : IRequest<List<KillChartInfo>> | ||
{ | ||
public KillChartQuery(int amount) | ||
{ | ||
Amount = amount; | ||
} | ||
|
||
public int Amount { get; set; } | ||
} | ||
|
||
public class KillChartQueryHandler : IRequestHandler<KillChartQuery, List<KillChartInfo>> | ||
{ | ||
private readonly IDbConnectionFactory _connectionFactory; | ||
private readonly IMediator _mediator; | ||
|
||
public KillChartQueryHandler(IDbConnectionFactory connectionFactory, IMediator mediator) | ||
{ | ||
_connectionFactory = connectionFactory; | ||
_mediator = mediator; | ||
} | ||
|
||
public async Task<List<KillChartInfo>> Handle(KillChartQuery request, CancellationToken cancellationToken) | ||
{ | ||
var Matches = await _mediator.Send(new GetMatchCommand()); | ||
var Settings = await _mediator.Send(new GetSettingsCommand()); | ||
Matches = Matches.OrderByDescending(x => x.DateTime).Take(request.Amount).ToList(); | ||
|
||
return Matches.Select(x => | ||
{ | ||
var team = x.Teams.FirstOrDefault(x => x.Players.FirstOrDefault(y => y.ProfileId == Settings.PlayerProfileId) != null); | ||
if (team != null) | ||
{ | ||
var Kills = x.Teams.Select(x => x.Players.Select(y => y.KilledByMe + y.DownedByMe + y.KilledByTeammate + y.DownedByTeammate).Sum()).Sum(); | ||
var YourKills = x.Teams.Select(x => x.Players.Select(y => y.KilledByMe + y.DownedByMe).Sum()).Sum(); | ||
var Deaths = x.Teams.Select(x => x.Players.Select(y => y.KilledMe + y.DownedMe).Sum()).Sum(); | ||
return new KillChartInfo | ||
{ | ||
DateTime = x.DateTime, | ||
YourKills = YourKills, | ||
Deaths = Deaths, | ||
Kills = Kills, | ||
}; | ||
} | ||
return null; | ||
}).Where(x => x != null).OrderBy(x => x.DateTime).ToList(); | ||
} | ||
} | ||
|
||
public class ChartInfo | ||
{ | ||
public DateTime DateTime { get; set; } | ||
public int TotalMmr { get; set; } | ||
public int Mmr { get; set; } | ||
} | ||
|
||
public class KillChartInfo | ||
{ | ||
public DateTime DateTime { get; set; } | ||
public int Kills { get; set; } | ||
public int YourKills { get; set; } | ||
public int Deaths { get; set; } | ||
} |
Oops, something went wrong.