KoogleApp/src/Koogle.Web/Components/Game/Training/TrainingSetup.razor

127 lines
4.0 KiB
Plaintext

@using Koogle.Application.Games.Training
@using Koogle.Domain.Enums
@using MudBlazor
<MudPaper Class="pa-4">
<MudText Typo="Typo.h6" Class="mb-4">Training-Einstellungen</MudText>
<MudStack Spacing="4">
<MudSelect T="ThrowMode"
@bind-Value="_options.ThrowMode"
Label="Wurf-Modus"
Variant="Variant.Outlined"
HelperText="In die Vollen: Kegel werden nach jedem Wurf aufgestellt. Abräumen: Kegel bleiben liegen.">
<MudSelectItem Value="ThrowMode.Reposition">In die Vollen</MudSelectItem>
<MudSelectItem Value="ThrowMode.Decrease">Abräumen</MudSelectItem>
</MudSelect>
<MudNumericField T="int"
@bind-Value="_options.ThrowsPerRound"
Label="Würfe pro Runde"
Variant="Variant.Outlined"
Min="1"
Max="5"
HelperText="Anzahl Würfe bevor der nächste Spieler an der Reihe ist (1-5)" />
<MudSelect T="ParticipantsMode"
@bind-Value="_options.ParticipantsMode"
Label="Spieler-Rotation"
Variant="Variant.Outlined"
HelperText="Automatisch: Spieler wechseln nach der Runde. Frei wählbar: Jeder kann werfen.">
<MudSelectItem Value="ParticipantsMode.GameLogic">Automatisch</MudSelectItem>
<MudSelectItem Value="ParticipantsMode.FreeToChoose">Frei wählbar</MudSelectItem>
</MudSelect>
</MudStack>
<MudDivider Class="my-4" />
<MudText Typo="Typo.body2" Color="Color.Secondary">
Training ist ein freies Übungsspiel. Es gibt keinen Gewinner - nur Statistiken.
Das Spiel muss manuell beendet werden.
</MudText>
</MudPaper>
@code {
/// <summary>
/// Callback when setup options change.
/// </summary>
[Parameter]
public EventCallback<object> OnOptionsChanged { get; set; }
/// <summary>
/// Initial setup options.
/// </summary>
[Parameter]
public object? InitialOptions { get; set; }
private TrainingSetupOptionsInternal _options = new();
protected override void OnInitialized()
{
if (InitialOptions is TrainingSetupOptions options)
{
_options = new TrainingSetupOptionsInternal
{
ThrowMode = options.ThrowMode,
ThrowsPerRound = options.ThrowsPerRound,
ParticipantsMode = options.ParticipantsMode
};
}
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await NotifyOptionsChanged();
}
}
private async Task NotifyOptionsChanged()
{
var options = new TrainingSetupOptions
{
ThrowMode = _options.ThrowMode,
ThrowsPerRound = _options.ThrowsPerRound,
ParticipantsMode = _options.ParticipantsMode
};
await OnOptionsChanged.InvokeAsync(options);
}
/// <summary>
/// Gets the current setup options.
/// </summary>
public TrainingSetupOptions GetOptions() => new()
{
ThrowMode = _options.ThrowMode,
ThrowsPerRound = _options.ThrowsPerRound,
ParticipantsMode = _options.ParticipantsMode
};
// Internal mutable class for two-way binding
private class TrainingSetupOptionsInternal
{
private ThrowMode _throwMode = ThrowMode.Reposition;
private int _throwsPerRound = 3;
private ParticipantsMode _participantsMode = ParticipantsMode.GameLogic;
public ThrowMode ThrowMode
{
get => _throwMode;
set => _throwMode = value;
}
public int ThrowsPerRound
{
get => _throwsPerRound;
set => _throwsPerRound = value;
}
public ParticipantsMode ParticipantsMode
{
get => _participantsMode;
set => _participantsMode = value;
}
}
}