Better move error visibility

This commit is contained in:
2024-11-03 14:36:37 -06:00
parent 7258ac29a0
commit 8a415a6c9d
7 changed files with 148 additions and 29 deletions

View File

@@ -31,13 +31,11 @@
<h3>Capturing and the Hand</h3>
<h3>The King and "Check"</h3>
<h3>Victory</h3>
</main>
@code {
private bool show = true;
private string activeSessionName = string.Empty;
private Task OnLoginChanged()
{
StateHasChanged();
@@ -48,4 +46,10 @@
activeSessionName = s.SessionId.ToString();
StateHasChanged();
}
private void OnClickClose()
{
show = false;
StateHasChanged();
}
}

View File

@@ -14,8 +14,6 @@
@if (showPromotePrompt)
{
<!-- Promote prompt -->
<!-- TODO: Add a background div which prevents mouse inputs to the board while this decision is being made. -->
<section class="promote-prompt">
<p>Do you wish to promote?</p>
<div>
@@ -25,10 +23,17 @@
</div>
</section>
}
@if (showError)
{
<div class="errorModal">
<TemporaryModal OnClickClose="HideError">
<p>That is not a valid move.</p>
</TemporaryModal>
</div>
}
</Stretch>
</Stretch>
@code {
@code {
[Parameter, EditorRequired]
public WhichPlayer Perspective { get; set; }
[Parameter, EditorRequired]
@@ -37,6 +42,7 @@
private WhichPiece? selectedPieceFromHand;
private bool showPromotePrompt;
private string? moveTo;
private bool showError = false;
protected override void OnParametersSet()
{
@@ -96,6 +102,7 @@
if (!success)
{
selectedPieceFromHand = null;
showError = true;
}
}
StateHasChanged();
@@ -119,9 +126,12 @@
else
{
var success = await ShogiApi.Move(Session.SessionId, new MovePieceCommand(selectedBoardPosition, position, false));
Console.WriteLine("Success? {0}", success);
if (!success)
{
selectedBoardPosition = null;
showError = true;
Console.WriteLine("Show error");
}
}
StateHasChanged();
@@ -149,11 +159,16 @@
{
if (selectedBoardPosition != null && moveTo != null)
{
await ShogiApi.Move(Session.SessionId, new MovePieceCommand(selectedBoardPosition, moveTo, shouldPromote));
showError = await ShogiApi.Move(Session.SessionId, new MovePieceCommand(selectedBoardPosition, moveTo, shouldPromote));
showPromotePrompt = false;
return;
}
throw new InvalidOperationException("Unexpected scenario during OnClickPromotionChoice.");
}
void HideError()
{
showError = false;
}
}

View File

@@ -8,7 +8,12 @@
box-shadow: 1px 1px 1px #444;
text-align: center;
z-index: 101;
background-color: #444;
border: 1px solid black;
}
}
.errorModal {
position: absolute;
top: 1rem;
right: 1rem;
}

View File

@@ -1,4 +1,3 @@
.SearchPage {
background-color: var(--contrast-color);
padding: 0 0.5rem;
}