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 #15 from Zaxiure/development
Browse files Browse the repository at this point in the history
First visual update.
  • Loading branch information
Zaxiure authored Sep 18, 2022
2 parents e7d4912 + b468000 commit de31e0c
Show file tree
Hide file tree
Showing 14 changed files with 276 additions and 33 deletions.
28 changes: 27 additions & 1 deletion HuntStats/Features/MatchHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using ConsoleApp1.Models;
using Dommel;
using HuntStats.Data;
using HuntStats.Models;
using MediatR;
using Newtonsoft.Json;

Expand All @@ -16,7 +17,6 @@ public GetMatchbyIdCommand(int id)

public int Id { get; set; }
}

public class GetMatchbyIdCommandHandler : IRequestHandler<GetMatchbyIdCommand, HuntMatch>
{
private readonly IDbConnectionFactory _connectionFactory;
Expand Down Expand Up @@ -54,6 +54,32 @@ public async Task<HuntMatch> Handle(GetMatchbyIdCommand request, CancellationTok
}
}

public class GetAccoladesByMatchIdCommand : IRequest<List<Accolade>> {

public GetAccoladesByMatchIdCommand(int matchId)
{
MatchId = matchId;
}

public int MatchId { get; set; }
}

public class GetAccoladesByMatchIdCommandHandler : IRequestHandler<GetAccoladesByMatchIdCommand, List<Accolade>>
{
private readonly IDbConnectionFactory _connectionFactory;

public GetAccoladesByMatchIdCommandHandler(IDbConnectionFactory connectionFactory)
{
_connectionFactory = connectionFactory;
}
public async Task<List<Accolade>> Handle(GetAccoladesByMatchIdCommand request, CancellationToken cancellationToken)
{
var con = await _connectionFactory.GetOpenConnectionAsync();
var accolades = await con.SelectAsync<Accolade>(x => x.MatchId == request.MatchId);
return accolades.ToList();
}
}

public class GetMatchCommand : IRequest<List<HuntMatch>>
{

Expand Down
9 changes: 9 additions & 0 deletions HuntStats/Features/SettingsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,20 @@ MatchId INTEGER not null
");
var columnCheck = await con.QueryAsync<ColumnsClass>("pragma table_info(Settings)");
var StartWorkerOnBoot = columnCheck.FirstOrDefault(x => x.name == "StartWorkerOnBoot");
var PlayerProfileId = columnCheck.FirstOrDefault(x => x.name == "PlayerProfileId");
if (StartWorkerOnBoot == null)
{
con.QueryAsync(@"alter table Settings
add StartWorkerOnBoot integer default 0 not null;");
}

if (PlayerProfileId == null)
{
con.QueryAsync(@"alter table Settings
add PlayerProfileId nvarchar;
");
}

return GeneralStatus.Succes;
}
}
Expand Down Expand Up @@ -182,6 +190,7 @@ await con.InsertAsync(new Settings()
else
{
settings.Path = request.Settings.Path;
settings.PlayerProfileId = request.Settings.PlayerProfileId;
settings.StartWorkerOnBoot = request.Settings.StartWorkerOnBoot;
await con.UpdateAsync(settings);
}
Expand Down
4 changes: 3 additions & 1 deletion HuntStats/Features/XmlFileHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ public async Task<GeneralStatus> Handle(XmlFileQuery request, CancellationToken
// File.Copy(huntFilePath, huntFileTempPath);
// File.Delete(huntFileTempPath + ".tmp");
XmlSerializer reader = new XmlSerializer(typeof(Attributes));
StreamReader file = new System.IO.StreamReader(huntFileTempPath);
var fileText = File.ReadAllText(huntFileTempPath);
var file = new StringReader(fileText);


Attributes overview = (Attributes)reader.Deserialize(file);
Expand Down Expand Up @@ -267,6 +268,7 @@ public async Task<GeneralStatus> Handle(XmlFileQuery request, CancellationToken
team.Players.Add(new Player()
{
Name = attributes["MissionBagPlayer_" + i + "_" + j +"_blood_line_name"],
ProfileId = attributes["MissionBagPlayer_" + i + "_" + j + "_profileid"],
Mmr = Convert.ToInt32(attributes["MissionBagPlayer_" + i + "_" + j + "_mmr"]),
KilledMe = Convert.ToInt32(attributes["MissionBagPlayer_" + i + "_" + j + "_killedme"]),
DownedMe = Convert.ToInt32(attributes["MissionBagPlayer_" + i + "_" + j + "_downedme"]),
Expand Down
7 changes: 7 additions & 0 deletions HuntStats/HuntStats.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,11 @@
<Folder Include="State" />
</ItemGroup>

<ItemGroup>
<None Include="C:\Users\Zaxiure\Downloads\Conjurer-Mire-album-cover.jpg">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion HuntStats/Models/Match.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class Player
{
public int Id { get; set; }

public int ProfileId { get; set; }
public string ProfileId { get; set; }
public String Name { get; set; }
public int Mmr { get; set; }

Expand Down
2 changes: 2 additions & 0 deletions HuntStats/Models/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ public class Settings
public string Path { get; set; }

public bool StartWorkerOnBoot { get; set; }

public string PlayerProfileId { get; set; }
}
91 changes: 79 additions & 12 deletions HuntStats/Pages/Match.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,70 @@
@inject IFolderPicker FolderPicker
@inject NavigationManager NavigationManager

<div class="card-container" style="max-width: 1280px;margin: auto;">
<div class="card-container" style="margin: auto;">
<div class="d-flex justify-content-between mb-3">
<div class="left"></div>
<div class="left">
<h3>Match: @HuntMatch.DateTime.ToLocalTime().ToString("dd-MM-yyyy HH:mm:ss")</h3>
</div>
<div class="right">
<div class="btn btn-primary" @onclick='() => { NavigationManager.NavigateTo("/match"); }'>Back</div>
</div>
</div>
<div class="card">
@if (HuntMatch != null)
{

<div class="card-body">
<h3>Match: @HuntMatch.DateTime.ToLocalTime().ToString("dd-MM-yyyy HH:mm:ss")</h3>
@foreach (var team in HuntMatch.Teams)
{
<div class="team">
<div class="team-title">Team #@(HuntMatch.Teams.IndexOf(team)+1)</div>
@foreach (var player in team.Players)
<div class="totals">
<div class="kills">
Total kills: @Kills
</div>
<div class="kills">
Your Kills: @YourKills
</div>
<div class="assists">
Kill Assists: @Assists
</div>
<div class="deaths">
Deaths: @Deaths
</div>
@if (EventPoints != null)
{
<div class="eventpoints">
Event Points: @EventPoints
</div>
}
</div>
<div class="teams w-50">
<div class="d-flex flex-row pt-4 flex-wrap">
@foreach (var team in HuntMatch.Teams)
{
<div class="team-player">
@player.Name
<div @onclick="() => { Team = team; }" class="btn btn-primary ms-3 mb-3 flex-shrink-0">Team @(HuntMatch.Teams.IndexOf(team)+1)@(team.Players.FirstOrDefault(x => x.ProfileId.ToString() == Settings.PlayerProfileId) != null ? " (Own Team)" : "")</div>
}
</div>
<div class="team-container">
<div class="team-title">Team #@(HuntMatch.Teams.IndexOf(Team) + 1)</div>
@foreach (var player in Team.Players)
{
<div class="team d-flex flex-row">
<div class="team-player w-25 text-nowrap overflow-hidden">
@player.Name
</div>
@if (Settings.PlayerProfileId == null || Settings.PlayerProfileId == string.Empty)
{
if (player.ProfileId != "0")
{
<div @onclick="() => { UpdateProfile(player.ProfileId.ToString()); }" class="btn btn-primary team-player" style="border-radius: 0 !important;border-width: 1px">
This is me!
</div>
}
}
<div class="team-player">
MMR: @player.Mmr
</div>
</div>
}
</div>
}
</div>
</div>
}
</div>
Expand All @@ -44,13 +83,41 @@

public HuntMatch HuntMatch { get; set; }

public Team Team { get; set; }
public Models.Settings Settings { get; set; }

public List<Accolade> Accolades { get; set; }

public int Kills { get; set; }

public int Assists { get; set; } = 0;

public int Deaths { get; set; }

public int YourKills { get; set; }

public int? EventPoints { get; set; } = null;


protected override async Task OnInitializedAsync()
{
if (Id != null)
{
HuntMatch = await Mediator.Send(new GetMatchbyIdCommand(Id));
Team = HuntMatch.Teams[0];
Accolades = await Mediator.Send((new GetAccoladesByMatchIdCommand(Id)));
Settings = await Mediator.Send(new GetSettingsCommand());
Kills = HuntMatch.Teams.Select(x => x.Players.Select(y => y.KilledByMe + y.DownedByMe + y.KilledByTeammate + y.DownedByTeammate).Sum()).Sum();
YourKills = HuntMatch.Teams.Select(x => x.Players.Select(y => y.KilledByMe + y.DownedByMe).Sum()).Sum();
if (Accolades.FirstOrDefault(x => x.Category == "accolade_players_killed_assist") != null) Assists = Accolades.FirstOrDefault(x => x.Category == "accolade_players_killed_assist").Hits;
Deaths = HuntMatch.Teams.Select(x => x.Players.Select(y => y.KilledMe + y.DownedMe).Sum()).Sum();
if (Accolades.FirstOrDefault(x => x.Category == "accolade_gained_serpent2022_event_points") != null) EventPoints = Accolades.FirstOrDefault(x => x.Category == "accolade_gained_serpent2022_event_points").Hits;
}
}

private async Task UpdateProfile(string profileId)
{
Settings.PlayerProfileId = profileId;
await Mediator.Send(new UpdateSettingsCommand(Settings));
}
}
21 changes: 19 additions & 2 deletions HuntStats/Pages/MatchList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@
@inject AppState AppState

<div class="card-container" style="max-width: 1280px;margin: auto;">
<h3>Matchasdfasdfasdes</h3>
<div class="card">
<div class="card-body">
<h3>Matches</h3>

<div class="table-wrapper">
<table class="table table-dark data-table" style="margin-bottom: 0 !important;">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Date</th>
<th scope="col">Datssse</th>
<th scope="col">Teams</th>
<th scope="col">Total Players</th>
@if (Settings.PlayerProfileId != null || Settings.PlayerProfileId != string.Empty || Settings.PlayerProfileId != "0")
{
<th>
MMR
</th>
}
<th>Actions</th>
</tr>
</thead>
Expand All @@ -39,6 +45,15 @@
<td>@match.DateTime.ToLocalTime()</td>
<td>@match.Teams.Count</td>
<td>@match.Teams.Select(x => x.Players.Count).Sum()</td>
@if (Settings.PlayerProfileId != null || Settings.PlayerProfileId != string.Empty || Settings.PlayerProfileId != "0")
{
<td>
@if (match.Teams.FirstOrDefault(x => x.Players.FirstOrDefault(y => y.ProfileId == Settings.PlayerProfileId) != null) != null)
{
@match.Teams.FirstOrDefault(x => x.Players.FirstOrDefault(y => y.ProfileId == Settings.PlayerProfileId) != null).Players.FirstOrDefault(x => x.ProfileId == Settings.PlayerProfileId).Mmr
}
</td>
}
<td>
<div @onclick='() => { NavigationManager.NavigateTo("/match/" + match.Id); }' class="btn btn-primary">
<i class="fal fa-eye"></i>
Expand All @@ -64,11 +79,13 @@
public bool RunBackgroundTask { get; set; } = false;
public string FilePath { get; set; }
public string Path { get; set; } = "";
public Models.Settings Settings { get; set; }

protected override async Task OnInitializedAsync()
{
AppState.NewMatchAdded += AppStateOnNewMatchAdded;
Matches = await Mediator.Send(new GetMatchCommand());
Settings = await Mediator.Send(new GetSettingsCommand());
}

private async void AppStateOnNewMatchAdded()
Expand Down
28 changes: 26 additions & 2 deletions HuntStats/Pages/Settings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
@inject IFolderPicker _folderPicker

<div class="card-container" style="max-width: 1280px;margin: auto;">
<h3>Settings</h3>
<div class="card">
<div class="card-body">
<h3>Settings</h3>

<form>
<div class="form-group row">
Expand All @@ -32,7 +32,7 @@
}
</div>
</div>
<div class="form-group row">
<div class="form-group row mt-3">
<label for="staticEmail" class="col-sm-4 col-form-label">Start background worker when opening application</label>
<div class="col-sm-8">
@if (HuntSettings.Path == null || HuntSettings.Path == string.Empty || FileNotFound)
Expand All @@ -49,6 +49,24 @@
}
</div>
</div>
<div class="form-group row mt-3">
<label for="staticEmail" class="col-sm-4 col-form-label">Reset selected player</label>
<div class="col-sm-8">
@if (HuntSettings.PlayerProfileId == null || HuntSettings.PlayerProfileId == string.Empty)
{
<button disabled class="btn btn-primary">
Reset
</button>
}
else
{
<div @onclick="ResetProfileId" class="btn btn-primary">
Reset
</div>
}
<small class="form-text d-block">This is the player you selected as yourself on the matchscreen.</small>
</div>
</div>
</form>
</div>
</div>
Expand Down Expand Up @@ -88,4 +106,10 @@
HuntSettings.StartWorkerOnBoot = !HuntSettings.StartWorkerOnBoot;
await _mediator.Send(new UpdateSettingsCommand(HuntSettings));
}

private async Task ResetProfileId()
{
HuntSettings.PlayerProfileId = "";
await _mediator.Send(new UpdateSettingsCommand(HuntSettings));
}
}
3 changes: 2 additions & 1 deletion HuntStats/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"profiles": {
"Windows Machine": {
"commandName": "MsixPackage",
"nativeDebugging": false
"nativeDebugging": false,
"hotReloadEnabled": true
}
}
}
Loading

0 comments on commit de31e0c

Please sign in to comment.