Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #16 from Zaxiure/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Zaxiure authored Sep 21, 2022
2 parents 1cd0868 + 1f4dd25 commit 637822a
Show file tree
Hide file tree
Showing 33 changed files with 1,443 additions and 313 deletions.
2 changes: 1 addition & 1 deletion HuntStats/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected override Window CreateWindow(IActivationState activationState)
var window = base.CreateWindow(activationState);
if (window != null)
{
window.Title = "HüntStäts";
window.Title = "HüntStäts by Zaxiure";
}

return window;
Expand Down
28 changes: 19 additions & 9 deletions HuntStats/Components/Dropdown.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
</div>
}
}
<div @ref="_dropdownElement" class="dropdown shadow @Class @getDropdownClass()">

<div @ref="_dropdownElement" class="dropdown shadow @(AlternateStyle ? "alternate" : "") @(RemoveMargin ? "no-margin" : "") @getDropdownClass()">
@{
if (DropdownContent != null)
{
Expand All @@ -23,14 +24,20 @@
</div>

@code {
[Parameter]
public string? Class { get; set; }

[Parameter]
public RenderFragment<string>? DropdownClickable { get; set; }

[Parameter]
public RenderFragment? DropdownContent { get; set; }

[Parameter]
public bool RemoveMargin { get; set; }

[Parameter]
public bool AlternateStyle { get; set; }

[Parameter]
public EventCallback DropdownOpened { get; set; } = new EventCallback();

private ElementReference _clickWrapper;
private ElementReference _dropdownElement;
Expand All @@ -49,19 +56,22 @@
return returnClass;
}

private void toggleDropdown()
private async Task toggleDropdown()
{
_dropdownOpened = !_dropdownOpened;
if(_dropdownOpened) _appstate.OpenedDropdown(_uniqueId);
if(_dropdownOpened)
{
_appstate.OpenedDropdown(_uniqueId);
await DropdownOpened.InvokeAsync();
};

}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await Task.Delay(500);
await JS.InvokeAsync<string>("createDropdown", _clickWrapper, _dropdownElement);

await JS.InvokeVoidAsync("createDropdown", _clickWrapper, _dropdownElement);
_stopAnimation = true;
_initialized = true;
StateHasChanged();
Expand Down
116 changes: 116 additions & 0 deletions HuntStats/Components/DropdownSelect.razor
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; }
}
}
9 changes: 9 additions & 0 deletions HuntStats/Components/Tooltip.razor
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; }
}
12 changes: 0 additions & 12 deletions HuntStats/Data/WeatherForecast.cs

This file was deleted.

20 changes: 0 additions & 20 deletions HuntStats/Data/WeatherForecastService.cs

This file was deleted.

34 changes: 34 additions & 0 deletions HuntStats/Extensions/GeneralExtensions.cs
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;
}
}
113 changes: 113 additions & 0 deletions HuntStats/Features/ChartHandler.cs
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; }
}
Loading

0 comments on commit 637822a

Please sign in to comment.