fix select participantsMode

This commit is contained in:
beo3000 2025-11-21 19:30:46 +01:00
parent 3e42cc1bb9
commit edb9a2eee8
14 changed files with 91 additions and 45 deletions

View File

@ -3,6 +3,7 @@
@using KoogleApp.Services @using KoogleApp.Services
@using KoogleApp.Store.Game @using KoogleApp.Store.Game
@using KoogleApp.Store.Game.Participants @using KoogleApp.Store.Game.Participants
@using KoogleApp.Store.Game.Setup
@using KoogleApp.Store.Game.ThrowPanel @using KoogleApp.Store.Game.ThrowPanel
@inherits FluxorComponent @inherits FluxorComponent
@ -10,6 +11,7 @@
@inject IState<ThrowPanelState> ThrowPanelState @inject IState<ThrowPanelState> ThrowPanelState
@inject IDispatcher Dispatcher @inject IDispatcher Dispatcher
@inject IState<ParticipantsState> ParticipantsState @inject IState<ParticipantsState> ParticipantsState
@inject IState<SetupState> SetupState
@if (ThrowPanelState.Value.IsStated) @if (ThrowPanelState.Value.IsStated)
{ {
@ -128,10 +130,9 @@
<MudPaper Class="pa-4 d-flex align-center justify-center mud-width-full" Style="height: 76px;"> <MudPaper Class="pa-4 d-flex align-center justify-center mud-width-full" Style="height: 76px;">
@if (ParticipantsState.Value != null) @if (ParticipantsState.Value != null)
{ {
<ChangePlayerSelect/> @if (SetupState.Value.ParticipantsMode == ParticipantsMode.FreeToChoose)
@if (CanSelectPlayer)
{ {
<ChangePlayerSelect />
} }
else else
{ {

View File

@ -1,13 +1,20 @@
@using KoogleApp.Store.Game.Setup @using KoogleApp.Store.Game.Setup
@using KoogleApp.Store.Game.ThrowPanel @using KoogleApp.Store.Game.ThrowPanel
@inject IDispatcher Dispatcher @inherits FluxorComponent
@inject IState<SetupState> SetupState
<MudSelect T="ParticipantsMode" Label="Spieler-Modus" HelperText="Wie wird der nächste Spieler bestimmt"
@bind-Value="Value"
OpenIcon="@Icons.Material.Filled.Mode" AdornmentColor="Color.Primary">
@foreach (var item in _values)
{
<MudSelectItem T="ParticipantsMode" Value="item.Key">@item.Value</MudSelectItem>
}
</MudSelect>
<EnumSelect Label="Spieler-Modus"
TEnum="@ParticipantsMode" TState="SetupState" HelperText="Wie wird der nächste Spieler bestimmt"
ValueSelector="@(state => state.ParticipantsMode)"
OnValueChanged="@(value => Dispatcher.Dispatch(new SetParticipantsModeAction(value)))"
EnumValues="_values" />
@code { @code {
Dictionary<ParticipantsMode, string> _values = new() Dictionary<ParticipantsMode, string> _values = new()
@ -18,4 +25,25 @@
}; };
private ParticipantsMode Value
{
get => SetupState.Value.ParticipantsMode;
set => OnValueChanged?.Invoke(value);
}
[Parameter, EditorRequired]
public Func<SetupState, ParticipantsMode> ValueSelector
{
get;
set;
} = null!;
[Parameter, EditorRequired]
public Action<ParticipantsMode> OnValueChanged
{
get;
set;
} = null!;
} }

View File

@ -8,6 +8,8 @@
@using KoogleApp.Store.Player @using KoogleApp.Store.Player
@using Dispatcher = Fluxor.Dispatcher @using Dispatcher = Fluxor.Dispatcher
@inherits FluxorComponent
@inject GameTypeService GameTypeService @inject GameTypeService GameTypeService
@inject IState<SetupState> SetupState @inject IState<SetupState> SetupState
@inject IState<PlayersState> PlayersState @inject IState<PlayersState> PlayersState
@ -21,13 +23,15 @@
</MudText> </MudText>
</TitleContent> </TitleContent>
<DialogContent> <DialogContent>
@SetupState.Value.ParticipantsMode
<MudSelect T="IKnownGame" Label="Spiel" @bind-Value="_selectedGameType" HelperText="Wähle ein Spiel aus" <MudSelect T="IKnownGame" Label="Spiel" @bind-Value="_selectedGameType" HelperText="Wähle ein Spiel aus"
OpenIcon="@Icons.Material.Filled.Mode" AdornmentColor="Color.Primary"> OpenIcon="@Icons.Material.Filled.Mode" AdornmentColor="Color.Primary">
@foreach (var item in _gameTypes) @foreach (var item in _gameTypes)
{ {
<MudSelectItem T="IKnownGame" Value="@(item)">@item.Name</MudSelectItem> <MudSelectItem T="IKnownGame" Value="@(item)">@item.Name</MudSelectItem>
} }
</MudSelect> </MudSelect>
<MudGrid> <MudGrid>
@if (_selectedSetupComponentType is not null) @if (_selectedSetupComponentType is not null)
@ -37,13 +41,13 @@
</MudItem> </MudItem>
<MudItem xs="12"> <MudItem xs="12">
<PlayerSelect @bind-SelectedValues="Players" /> <PlayerSelect @bind-SelectedValues="Players"/>
</MudItem> </MudItem>
<DynamicComponent Type="_selectedSetupComponentType"/> <DynamicComponent Type="_selectedSetupComponentType"/>
} }
</MudGrid> </MudGrid>
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
<MudButton OnClick="Cancel">Abbrechen</MudButton> <MudButton OnClick="Cancel">Abbrechen</MudButton>
@ -87,6 +91,11 @@
private void Start() private void Start()
{ {
MudDialog.Close(DialogResult.Ok(new StartParams(DayState.Value.Id, SetupState.Value.ThrowMode, SetupState.Value.ThrowsPerRound, PlayerIds, SetupState.Value.ParticipantsMode))); MudDialog.Close(DialogResult.Ok(new StartParams(
DayState.Value.Id,
SetupState.Value.ThrowMode,
SetupState.Value.ThrowsPerRound,
PlayerIds,
SetupState.Value.ParticipantsMode)));
} }
} }

View File

@ -12,6 +12,7 @@
@using KoogleApp.Store.DayFeature @using KoogleApp.Store.DayFeature
@using KoogleApp.Store.Game @using KoogleApp.Store.Game
@using KoogleApp.Store.Game.Participants @using KoogleApp.Store.Game.Participants
@using KoogleApp.Store.Game.Setup
@using KoogleApp.Store.Game.ThrowPanel @using KoogleApp.Store.Game.ThrowPanel
@using KoogleApp.Store.Game.ThrowTimer @using KoogleApp.Store.Game.ThrowTimer
@using KoogleApp.Store.Game.UndoRedo @using KoogleApp.Store.Game.UndoRedo
@ -29,6 +30,7 @@
@inject IState<ThrowPanelState> ThrowPanelState @inject IState<ThrowPanelState> ThrowPanelState
@inject IState<DayState> DayState @inject IState<DayState> DayState
@inject IState<ParticipantsState> ParticipantsState @inject IState<ParticipantsState> ParticipantsState
@inject IState<SetupState> SetupState
@inject IDispatcher Dispatcher @inject IDispatcher Dispatcher
@inject IDialogService DialogService @inject IDialogService DialogService
@ -42,8 +44,8 @@
case GameView.Throw: case GameView.Throw:
<PanelToolbar> <PanelToolbar>
@GetParticipantsState() @* @GetParticipantsState() *@
@GetSetupState();
@if (DayState.Value.Status != DayStatus.Started) @if (DayState.Value.Status != DayStatus.Started)
{ {
@ -265,4 +267,11 @@
}); });
} }
private string GetSetupState()
{
return JsonSerializer.Serialize(SetupState.Value,new JsonSerializerOptions
{
WriteIndented = true
});
}
} }

View File

@ -5,8 +5,6 @@
@using MudBlazor @using MudBlazor
@inject IDispatcher Dispatcher @inject IDispatcher Dispatcher
@inject IState<SetupState> SetupState
<MudItem> <MudItem>
<ThrowModeSelect TState="SetupState" <ThrowModeSelect TState="SetupState"
@ -19,7 +17,9 @@
OnValueChanged="@(value => Dispatcher.Dispatch(new SetThrowsPerRoundAction(value)))"/> OnValueChanged="@(value => Dispatcher.Dispatch(new SetThrowsPerRoundAction(value)))"/>
</MudItem> </MudItem>
<MudItem> <MudItem>
<ParticipantsModeSelect/> <ParticipantsModeSelect
ValueSelector="@(state => state.ParticipantsMode)"
OnValueChanged="@(value => Dispatcher.Dispatch(new SetParticipantsModeAction(value)))" />
</MudItem> </MudItem>
@code { @code {

View File

@ -2,10 +2,13 @@
namespace KoogleApp.Model namespace KoogleApp.Model
{ {
public record StartParams(int DayId, ThrowMode ThrowMode, int ThrowsPerRound, int[] Participants, ParticipantsMode ParticipantsMode) public record StartParams(int DayId, ThrowMode ThrowMode, int ThrowsPerRound, int[] Participants,
ParticipantsMode ParticipantsMode)
{ {
public StartParams() : this(DayId: 0, ThrowMode: ThrowMode.Reposition, ThrowsPerRound: 3, [], ParticipantsMode: Store.Game.ThrowPanel.ParticipantsMode.FreeToChoose) public StartParams() : this(DayId: 0, ThrowMode: ThrowMode.Reposition,
ThrowsPerRound: 3, [],
ParticipantsMode: ParticipantsMode.FreeToChoose)
{ {
} }
} }

View File

@ -3,7 +3,7 @@ using KoogleApp.Store.Player;
namespace KoogleApp.Store.Game.Participants namespace KoogleApp.Store.Game.Participants
{ {
public record ParticipantsStateChangedAction(ParticipantsState? ParticipantsState); public record SaveAndBroadcastParticipantsStateAction(ParticipantsState? ParticipantsState);
public record LoadParticipantsStatesFromSessionAction(); public record LoadParticipantsStatesFromSessionAction();
@ -11,7 +11,7 @@ namespace KoogleApp.Store.Game.Participants
public record BroadcastParticipantsStateAction(ParticipantsState ParticipantsState); public record BroadcastParticipantsStateAction(ParticipantsState ParticipantsState);
public record ParticipantsStateLoadedAction(ParticipantsState ParticipantsState); public record ParticipantsStateChangedAction(ParticipantsState ParticipantsState);
public record SetParticipatingPlayersAction(int[] PlayerIds); public record SetParticipatingPlayersAction(int[] PlayerIds);

View File

@ -16,7 +16,7 @@ namespace KoogleApp.Store.Game.Participants
private readonly IGameStatusDataService _dataService = dataService; private readonly IGameStatusDataService _dataService = dataService;
[EffectMethod] [EffectMethod]
public async Task HandelParticipantsStateChangedAction(ParticipantsStateChangedAction action, IDispatcher dispatcher) public async Task HandelParticipantsStateChangedAction(SaveAndBroadcastParticipantsStateAction action, IDispatcher dispatcher)
{ {
dispatcher.Dispatch(new SaveParticipantsStateAction(action.ParticipantsState)); dispatcher.Dispatch(new SaveParticipantsStateAction(action.ParticipantsState));
@ -36,8 +36,8 @@ namespace KoogleApp.Store.Game.Participants
PlayerIds = lst.ToArray() PlayerIds = lst.ToArray()
}; };
dispatcher.Dispatch(new SaveAndBroadcastParticipantsStateAction(newState));
dispatcher.Dispatch(new ParticipantsStateChangedAction(newState)); dispatcher.Dispatch(new ParticipantsStateChangedAction(newState));
dispatcher.Dispatch(new ParticipantsStateLoadedAction(newState));
} }
[EffectMethod] [EffectMethod]
@ -95,7 +95,7 @@ namespace KoogleApp.Store.Game.Participants
if (state != null) if (state != null)
{ {
dispatcher.Dispatch(new ParticipantsStateLoadedAction(state)); dispatcher.Dispatch(new ParticipantsStateChangedAction(state));
} }
} }

View File

@ -17,7 +17,7 @@ namespace KoogleApp.Store.Game.Participants
} }
[ReducerMethod] [ReducerMethod]
public static ParticipantsState OnParticipantsState(ParticipantsState state, ParticipantsStateLoadedAction action) public static ParticipantsState OnParticipantsState(ParticipantsState state, ParticipantsStateChangedAction action)
{ {
return action.ParticipantsState; return action.ParticipantsState;
} }

View File

@ -11,4 +11,6 @@ namespace KoogleApp.Store.Game.Setup
public record LoadSetupStatesFromSessionAction(); public record LoadSetupStatesFromSessionAction();
public record SetupStateLoadedAction(SetupState SetupState); public record SetupStateLoadedAction(SetupState SetupState);
public record ResetSetupStateAction();
} }

View File

@ -6,7 +6,8 @@ namespace KoogleApp.Store.Game.Setup
[FeatureState] [FeatureState]
public record SetupState(ThrowMode ThrowMode, int ThrowsPerRound, int[] Players, ParticipantsMode ParticipantsMode) public record SetupState(ThrowMode ThrowMode, int ThrowsPerRound, int[] Players, ParticipantsMode ParticipantsMode)
{ {
public SetupState() : this(ThrowMode: ThrowMode.Reposition, ThrowsPerRound:3, Players:[], ParticipantsMode: ParticipantsMode.FreeToChoose) public SetupState() : this(ThrowMode: ThrowMode.Reposition, ThrowsPerRound:3, Players:[],
ParticipantsMode: ParticipantsMode.FreeToChoose)
{ } { }
} }
} }

View File

@ -20,6 +20,7 @@ namespace KoogleApp.Store.Game.ThrowPanel
private readonly ILogger<ThrowPanelEffects> _logger; private readonly ILogger<ThrowPanelEffects> _logger;
private readonly HubConnectionService _sharedHubService; private readonly HubConnectionService _sharedHubService;
private readonly IState<ThrowPanelState> _throwPanelState; private readonly IState<ThrowPanelState> _throwPanelState;
private readonly IState<SetupState> _setupState;
private readonly SessionStorage _sessionStorage; private readonly SessionStorage _sessionStorage;
private readonly string _dataFilePath = "ThrowPanelState.json"; private readonly string _dataFilePath = "ThrowPanelState.json";
private readonly AuthenticationStateProvider _authenticationStateProvider; private readonly AuthenticationStateProvider _authenticationStateProvider;
@ -32,6 +33,7 @@ namespace KoogleApp.Store.Game.ThrowPanel
ILogger<ThrowPanelEffects> logger, ILogger<ThrowPanelEffects> logger,
HubConnectionService sharedHubService, HubConnectionService sharedHubService,
IState<ThrowPanelState> throwPanelState, IState<ThrowPanelState> throwPanelState,
IState<SetupState> setupState,
AuthenticationStateProvider authenticationStateProvider, AuthenticationStateProvider authenticationStateProvider,
IGameStatusDataService dataService, IGameStatusDataService dataService,
SessionStorage sessionStorage) SessionStorage sessionStorage)
@ -65,7 +67,7 @@ namespace KoogleApp.Store.Game.ThrowPanel
setupState = new SetupState(startStopAction.StartParams.ThrowMode, setupState = new SetupState(startStopAction.StartParams.ThrowMode,
startStopAction.StartParams.ThrowsPerRound, startStopAction.StartParams.Participants, startStopAction.StartParams.ThrowsPerRound, startStopAction.StartParams.Participants,
ParticipantsMode: startStopAction.StartParams.ParticipantsMode); ParticipantsMode: startStopAction.StartParams.ParticipantsMode);
var username = await GetUsername(); var username = await GetUsername();
_dataService.Initialize(new GameStatus() _dataService.Initialize(new GameStatus()
{ {
@ -82,13 +84,14 @@ namespace KoogleApp.Store.Game.ThrowPanel
ThrowPanelState = _throwPanelState.Value with { ThrowPanelStateStatus = ThrowPanelStateStatus.GameEnd }, ThrowPanelState = _throwPanelState.Value with { ThrowPanelStateStatus = ThrowPanelStateStatus.GameEnd },
}, username); }, username);
dispatcher.Dispatch(new UpdateUndoRedoStateAction()); dispatcher.Dispatch(new UpdateUndoRedoStateAction());
participantsState = new ParticipantsState();
} }
// reset settings and all relevant states for the next game
dispatcher.Dispatch(new ThrowPanelStateChangedAction(_throwPanelState.Value, true, ParticipantsState: participantsState)); dispatcher.Dispatch(new ThrowPanelStateChangedAction(_throwPanelState.Value, true, ParticipantsState: participantsState));
if (participantsState != null) dispatcher.Dispatch(new ParticipantsStateChangedAction(participantsState));
{ dispatcher.Dispatch(new ResetSetupStateAction()); // TODO: not reduced
dispatcher.Dispatch(new ParticipantsStateChangedAction(participantsState));
}
} }
[EffectMethod] [EffectMethod]

View File

@ -33,7 +33,7 @@
} }
}, },
"Version": 2, "Version": 2,
"LastModified": "2025-11-21T17:52:34.7010655+01:00", "LastModified": "2025-11-21T19:30:06.7529818+01:00",
"LastModifiedBy": "test1@test.de" "LastModifiedBy": "test1@test.de"
}, },
"UndoHistory": [ "UndoHistory": [
@ -49,7 +49,7 @@
12, 12,
9 9
], ],
"ParticipantsMode": 1 "ParticipantsMode": 0
}, },
"ThrowPanelState": { "ThrowPanelState": {
"IsStated": true, "IsStated": true,
@ -82,7 +82,7 @@
} }
}, },
"Version": 1, "Version": 1,
"LastModified": "2025-11-21T17:52:34.6986698+01:00", "LastModified": "2025-11-21T19:30:06.7492871+01:00",
"LastModifiedBy": "test1@test.de" "LastModifiedBy": "test1@test.de"
} }
], ],

View File

@ -1,10 +0,0 @@
{
"PlayerIds": [
12,
5,
3,
10,
9
],
"Eliminated": []
}