Ajoute l Elo et les statistiques de parties
This commit is contained in:
@@ -160,7 +160,7 @@
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
<input @bind="WhitePlayerName" @bind:event="oninput" name="whiteName" type="text" maxlength="40" placeholder="Blanc" />
|
||||
<input @bind="WhitePlayerName" @bind:event="oninput" name="whiteName" type="text" maxlength="40" placeholder="Blanc" disabled="@HasLockedPlaySession" />
|
||||
</label>
|
||||
|
||||
<label class="field player-name-field">
|
||||
@@ -178,7 +178,7 @@
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
<input @bind="BlackPlayerName" @bind:event="oninput" name="blackName" type="text" maxlength="40" placeholder="Noir" />
|
||||
<input @bind="BlackPlayerName" @bind:event="oninput" name="blackName" type="text" maxlength="40" placeholder="Noir" disabled="@HasLockedPlaySession" />
|
||||
</label>
|
||||
|
||||
@if (!string.IsNullOrWhiteSpace(SetupError))
|
||||
@@ -297,6 +297,7 @@
|
||||
<span>@TimingText</span>
|
||||
<span>@TimeImpact</span>
|
||||
<span>@QuotaText</span>
|
||||
<span>@StatsEligibilityText</span>
|
||||
</div>
|
||||
|
||||
<div class="setup-actions span-2">
|
||||
@@ -386,6 +387,9 @@
|
||||
private long _knownCollaborativeRevision;
|
||||
private string? _appliedActiveSessionId;
|
||||
private string? ConnectedPlayerName;
|
||||
private string? ConnectedPlayerSubject;
|
||||
private string? AssignedWhiteSubject;
|
||||
private string? AssignedBlackSubject;
|
||||
private string? SetupError;
|
||||
private string? SocialLoadError;
|
||||
private string? InviteActionError;
|
||||
@@ -395,12 +399,21 @@
|
||||
|
||||
private string SetupBodyClass => UsesMoveLimit ? string.Empty : "time-setup-mode";
|
||||
private bool CanUseConnectedPlayerName => !string.IsNullOrWhiteSpace(ConnectedPlayerName);
|
||||
private bool HasLockedPlaySession => Realtime.ActivePlaySession is not null;
|
||||
private string WhitePlayerName
|
||||
{
|
||||
get => Form.WhiteName;
|
||||
set
|
||||
{
|
||||
Form.WhiteName = value;
|
||||
if (!HasLockedPlaySession &&
|
||||
!string.IsNullOrWhiteSpace(AssignedWhiteSubject) &&
|
||||
AssignedWhiteSubject == ConnectedPlayerSubject &&
|
||||
!SamePlayerName(value, ConnectedPlayerName))
|
||||
{
|
||||
AssignedWhiteSubject = null;
|
||||
}
|
||||
|
||||
SetupError = null;
|
||||
}
|
||||
}
|
||||
@@ -411,6 +424,14 @@
|
||||
set
|
||||
{
|
||||
Form.BlackName = value;
|
||||
if (!HasLockedPlaySession &&
|
||||
!string.IsNullOrWhiteSpace(AssignedBlackSubject) &&
|
||||
AssignedBlackSubject == ConnectedPlayerSubject &&
|
||||
!SamePlayerName(value, ConnectedPlayerName))
|
||||
{
|
||||
AssignedBlackSubject = null;
|
||||
}
|
||||
|
||||
SetupError = null;
|
||||
}
|
||||
}
|
||||
@@ -449,6 +470,13 @@
|
||||
? $"Quota actif : {CurrentPreset.Quota} coups par joueur."
|
||||
: $"Quota actif : {CurrentPreset.Quota} coups par joueur et par Block.";
|
||||
|
||||
private string StatsEligibilityText =>
|
||||
Realtime.ActivePlaySession is not null
|
||||
? "Match classe : les deux comptes sont identifies, la partie mettra a jour l'Elo et les statistiques."
|
||||
: !string.IsNullOrWhiteSpace(AssignedWhiteSubject) || !string.IsNullOrWhiteSpace(AssignedBlackSubject)
|
||||
? "Match amical : la partie sera enregistree pour le ou les comptes lies, sans impact Elo."
|
||||
: "Match local uniquement : aucun compte joueur n'est lie des deux cotes, rien ne sera ajoute aux statistiques serveur.";
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
AuthenticationStateProvider.AuthenticationStateChanged += HandleAuthenticationStateChanged;
|
||||
@@ -508,6 +536,9 @@
|
||||
{
|
||||
IsAuthenticated = false;
|
||||
ConnectedPlayerName = null;
|
||||
ConnectedPlayerSubject = null;
|
||||
AssignedWhiteSubject = null;
|
||||
AssignedBlackSubject = null;
|
||||
ResetSocialState();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
return;
|
||||
@@ -515,6 +546,7 @@
|
||||
|
||||
IsAuthenticated = true;
|
||||
fallbackName = BuildConnectedPlayerFallback(user);
|
||||
ConnectedPlayerSubject = ResolveSubject(user);
|
||||
|
||||
var response = await Http.GetAsync("api/users/me");
|
||||
if (!response.IsSuccessStatusCode)
|
||||
@@ -523,6 +555,9 @@
|
||||
{
|
||||
IsAuthenticated = false;
|
||||
ConnectedPlayerName = null;
|
||||
ConnectedPlayerSubject = null;
|
||||
AssignedWhiteSubject = null;
|
||||
AssignedBlackSubject = null;
|
||||
ResetSocialState();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
return;
|
||||
@@ -607,11 +642,20 @@
|
||||
|
||||
await Store.EnsureLoadedAsync();
|
||||
var match = MatchEngine.CreateMatch(Form.ToMatchConfig());
|
||||
if (!string.IsNullOrWhiteSpace(Realtime.ActivePlaySession?.SessionId))
|
||||
if (Realtime.ActivePlaySession is { } session)
|
||||
{
|
||||
match.CollaborationSessionId = Realtime.ActivePlaySession.SessionId;
|
||||
match.CollaborationSessionId = session.SessionId;
|
||||
match.WhiteSubject = NormalizeOptional(session.WhiteSubject);
|
||||
match.BlackSubject = NormalizeOptional(session.BlackSubject);
|
||||
match.Config.WhiteName = session.WhiteName;
|
||||
match.Config.BlackName = session.BlackName;
|
||||
await Realtime.EnsureJoinedPlaySessionAsync(match.CollaborationSessionId);
|
||||
}
|
||||
else
|
||||
{
|
||||
match.WhiteSubject = NormalizeOptional(AssignedWhiteSubject);
|
||||
match.BlackSubject = NormalizeOptional(AssignedBlackSubject);
|
||||
}
|
||||
|
||||
Store.SetCurrent(match);
|
||||
|
||||
@@ -632,6 +676,8 @@
|
||||
private void LoadDemo()
|
||||
{
|
||||
Form = SetupFormModel.CreateDemo();
|
||||
AssignedWhiteSubject = null;
|
||||
AssignedBlackSubject = null;
|
||||
SetupError = null;
|
||||
}
|
||||
|
||||
@@ -758,6 +804,8 @@
|
||||
|
||||
Form.WhiteName = session.WhiteName;
|
||||
Form.BlackName = session.BlackName;
|
||||
AssignedWhiteSubject = NormalizeOptional(session.WhiteSubject);
|
||||
AssignedBlackSubject = NormalizeOptional(session.BlackSubject);
|
||||
SetupError = null;
|
||||
_appliedActiveSessionId = session.SessionId;
|
||||
}
|
||||
@@ -771,10 +819,12 @@
|
||||
|
||||
var connectedName = ConnectedPlayerName!;
|
||||
Form.WhiteName = connectedName;
|
||||
AssignedWhiteSubject = NormalizeOptional(ConnectedPlayerSubject);
|
||||
|
||||
if (SamePlayerName(Form.BlackName, connectedName))
|
||||
if (SamePlayerName(Form.BlackName, connectedName) || string.Equals(AssignedBlackSubject, ConnectedPlayerSubject, StringComparison.Ordinal))
|
||||
{
|
||||
Form.BlackName = "Noir";
|
||||
AssignedBlackSubject = null;
|
||||
}
|
||||
|
||||
SetupError = null;
|
||||
@@ -789,10 +839,12 @@
|
||||
|
||||
var connectedName = ConnectedPlayerName!;
|
||||
Form.BlackName = connectedName;
|
||||
AssignedBlackSubject = NormalizeOptional(ConnectedPlayerSubject);
|
||||
|
||||
if (SamePlayerName(Form.WhiteName, connectedName))
|
||||
if (SamePlayerName(Form.WhiteName, connectedName) || string.Equals(AssignedWhiteSubject, ConnectedPlayerSubject, StringComparison.Ordinal))
|
||||
{
|
||||
Form.WhiteName = "Blanc";
|
||||
AssignedWhiteSubject = null;
|
||||
}
|
||||
|
||||
SetupError = null;
|
||||
@@ -824,6 +876,8 @@
|
||||
{
|
||||
Form.WhiteName = snapshot.Match.Config.WhiteName;
|
||||
Form.BlackName = snapshot.Match.Config.BlackName;
|
||||
AssignedWhiteSubject = NormalizeOptional(snapshot.Match.WhiteSubject);
|
||||
AssignedBlackSubject = NormalizeOptional(snapshot.Match.BlackSubject);
|
||||
SetupError = null;
|
||||
}
|
||||
|
||||
@@ -885,9 +939,16 @@
|
||||
user.FindFirst("preferred_username")?.Value,
|
||||
user.FindFirst(ClaimTypes.Email)?.Value);
|
||||
|
||||
private static string? ResolveSubject(ClaimsPrincipal user)
|
||||
=> user.FindFirst("sub")?.Value
|
||||
?? user.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
|
||||
private static string? FirstNonEmpty(params string?[] candidates)
|
||||
=> candidates.FirstOrDefault(candidate => !string.IsNullOrWhiteSpace(candidate));
|
||||
|
||||
private static string? NormalizeOptional(string? value)
|
||||
=> string.IsNullOrWhiteSpace(value) ? null : value.Trim();
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
AuthenticationStateProvider.AuthenticationStateChanged -= HandleAuthenticationStateChanged;
|
||||
|
||||
Reference in New Issue
Block a user