From edb9a2eee82df2205ac1f157640ced55ed45fbae Mon Sep 17 00:00:00 2001 From: beo3000 Date: Fri, 21 Nov 2025 19:30:46 +0100 Subject: [PATCH] fix select participantsMode --- .../Components/Controls/NumberPanel.razor | 7 ++-- .../Controls/ParticipantsModeSelect.razor | 40 ++++++++++++++++--- .../Components/Dialogs/StartGameDialog.razor | 17 ++++++-- KoogleApp/Components/Pages/Game.razor | 13 +++++- KoogleApp/Games/Training/Setup.razor | 6 +-- KoogleApp/Model/StartParams.cs | 7 +++- KoogleApp/Store/Game/Participants/Actions.cs | 4 +- KoogleApp/Store/Game/Participants/Effects.cs | 6 +-- KoogleApp/Store/Game/Participants/Reducers.cs | 2 +- KoogleApp/Store/Game/Setup/Actions.cs | 2 + KoogleApp/Store/Game/Setup/State.cs | 3 +- KoogleApp/Store/Game/ThrowPanel/Effects.cs | 13 +++--- KoogleApp/appdata.json | 6 +-- KoogleApp/participantsState.json | 10 ----- 14 files changed, 91 insertions(+), 45 deletions(-) delete mode 100644 KoogleApp/participantsState.json diff --git a/KoogleApp/Components/Controls/NumberPanel.razor b/KoogleApp/Components/Controls/NumberPanel.razor index 0d504c7..0802a8f 100644 --- a/KoogleApp/Components/Controls/NumberPanel.razor +++ b/KoogleApp/Components/Controls/NumberPanel.razor @@ -3,6 +3,7 @@ @using KoogleApp.Services @using KoogleApp.Store.Game @using KoogleApp.Store.Game.Participants +@using KoogleApp.Store.Game.Setup @using KoogleApp.Store.Game.ThrowPanel @inherits FluxorComponent @@ -10,6 +11,7 @@ @inject IState ThrowPanelState @inject IDispatcher Dispatcher @inject IState ParticipantsState +@inject IState SetupState @if (ThrowPanelState.Value.IsStated) { @@ -128,10 +130,9 @@ @if (ParticipantsState.Value != null) { - - @if (CanSelectPlayer) + @if (SetupState.Value.ParticipantsMode == ParticipantsMode.FreeToChoose) { - + } else { diff --git a/KoogleApp/Components/Controls/ParticipantsModeSelect.razor b/KoogleApp/Components/Controls/ParticipantsModeSelect.razor index d11ea88..69cb3db 100644 --- a/KoogleApp/Components/Controls/ParticipantsModeSelect.razor +++ b/KoogleApp/Components/Controls/ParticipantsModeSelect.razor @@ -1,13 +1,20 @@ @using KoogleApp.Store.Game.Setup @using KoogleApp.Store.Game.ThrowPanel -@inject IDispatcher Dispatcher +@inherits FluxorComponent + +@inject IState SetupState + + + @foreach (var item in _values) + { + @item.Value + } + - @code { Dictionary _values = new() @@ -18,4 +25,25 @@ }; + private ParticipantsMode Value + { + get => SetupState.Value.ParticipantsMode; + set => OnValueChanged?.Invoke(value); + } + + [Parameter, EditorRequired] + public Func ValueSelector + { + get; + set; + } = null!; + + + [Parameter, EditorRequired] + public Action OnValueChanged + { + get; + set; + } = null!; + } diff --git a/KoogleApp/Components/Dialogs/StartGameDialog.razor b/KoogleApp/Components/Dialogs/StartGameDialog.razor index 9a592fa..5375911 100644 --- a/KoogleApp/Components/Dialogs/StartGameDialog.razor +++ b/KoogleApp/Components/Dialogs/StartGameDialog.razor @@ -8,6 +8,8 @@ @using KoogleApp.Store.Player @using Dispatcher = Fluxor.Dispatcher +@inherits FluxorComponent + @inject GameTypeService GameTypeService @inject IState SetupState @inject IState PlayersState @@ -21,13 +23,15 @@ + @SetupState.Value.ParticipantsMode + @foreach (var item in _gameTypes) { @item.Name } - + @if (_selectedSetupComponentType is not null) @@ -37,13 +41,13 @@ - + } - + Abbrechen @@ -87,6 +91,11 @@ 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))); } } diff --git a/KoogleApp/Components/Pages/Game.razor b/KoogleApp/Components/Pages/Game.razor index 709fc95..1bd591c 100644 --- a/KoogleApp/Components/Pages/Game.razor +++ b/KoogleApp/Components/Pages/Game.razor @@ -12,6 +12,7 @@ @using KoogleApp.Store.DayFeature @using KoogleApp.Store.Game @using KoogleApp.Store.Game.Participants +@using KoogleApp.Store.Game.Setup @using KoogleApp.Store.Game.ThrowPanel @using KoogleApp.Store.Game.ThrowTimer @using KoogleApp.Store.Game.UndoRedo @@ -29,6 +30,7 @@ @inject IState ThrowPanelState @inject IState DayState @inject IState ParticipantsState +@inject IState SetupState @inject IDispatcher Dispatcher @inject IDialogService DialogService @@ -42,8 +44,8 @@ case GameView.Throw: - @GetParticipantsState() - + @* @GetParticipantsState() *@ + @GetSetupState(); @if (DayState.Value.Status != DayStatus.Started) { @@ -265,4 +267,11 @@ }); } + private string GetSetupState() + { + return JsonSerializer.Serialize(SetupState.Value,new JsonSerializerOptions + { + WriteIndented = true + }); + } } diff --git a/KoogleApp/Games/Training/Setup.razor b/KoogleApp/Games/Training/Setup.razor index 9599c84..ae76566 100644 --- a/KoogleApp/Games/Training/Setup.razor +++ b/KoogleApp/Games/Training/Setup.razor @@ -5,8 +5,6 @@ @using MudBlazor @inject IDispatcher Dispatcher -@inject IState SetupState - - + @code { diff --git a/KoogleApp/Model/StartParams.cs b/KoogleApp/Model/StartParams.cs index d89afd2..b683ab3 100644 --- a/KoogleApp/Model/StartParams.cs +++ b/KoogleApp/Model/StartParams.cs @@ -2,10 +2,13 @@ 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) { } } diff --git a/KoogleApp/Store/Game/Participants/Actions.cs b/KoogleApp/Store/Game/Participants/Actions.cs index 18f0ffb..8a1514b 100644 --- a/KoogleApp/Store/Game/Participants/Actions.cs +++ b/KoogleApp/Store/Game/Participants/Actions.cs @@ -3,7 +3,7 @@ using KoogleApp.Store.Player; namespace KoogleApp.Store.Game.Participants { - public record ParticipantsStateChangedAction(ParticipantsState? ParticipantsState); + public record SaveAndBroadcastParticipantsStateAction(ParticipantsState? ParticipantsState); public record LoadParticipantsStatesFromSessionAction(); @@ -11,7 +11,7 @@ namespace KoogleApp.Store.Game.Participants public record BroadcastParticipantsStateAction(ParticipantsState ParticipantsState); - public record ParticipantsStateLoadedAction(ParticipantsState ParticipantsState); + public record ParticipantsStateChangedAction(ParticipantsState ParticipantsState); public record SetParticipatingPlayersAction(int[] PlayerIds); diff --git a/KoogleApp/Store/Game/Participants/Effects.cs b/KoogleApp/Store/Game/Participants/Effects.cs index 2e5a4af..7ad0226 100644 --- a/KoogleApp/Store/Game/Participants/Effects.cs +++ b/KoogleApp/Store/Game/Participants/Effects.cs @@ -16,7 +16,7 @@ namespace KoogleApp.Store.Game.Participants private readonly IGameStatusDataService _dataService = dataService; [EffectMethod] - public async Task HandelParticipantsStateChangedAction(ParticipantsStateChangedAction action, IDispatcher dispatcher) + public async Task HandelParticipantsStateChangedAction(SaveAndBroadcastParticipantsStateAction action, IDispatcher dispatcher) { dispatcher.Dispatch(new SaveParticipantsStateAction(action.ParticipantsState)); @@ -36,8 +36,8 @@ namespace KoogleApp.Store.Game.Participants PlayerIds = lst.ToArray() }; + dispatcher.Dispatch(new SaveAndBroadcastParticipantsStateAction(newState)); dispatcher.Dispatch(new ParticipantsStateChangedAction(newState)); - dispatcher.Dispatch(new ParticipantsStateLoadedAction(newState)); } [EffectMethod] @@ -95,7 +95,7 @@ namespace KoogleApp.Store.Game.Participants if (state != null) { - dispatcher.Dispatch(new ParticipantsStateLoadedAction(state)); + dispatcher.Dispatch(new ParticipantsStateChangedAction(state)); } } diff --git a/KoogleApp/Store/Game/Participants/Reducers.cs b/KoogleApp/Store/Game/Participants/Reducers.cs index 32ea977..1065cdf 100644 --- a/KoogleApp/Store/Game/Participants/Reducers.cs +++ b/KoogleApp/Store/Game/Participants/Reducers.cs @@ -17,7 +17,7 @@ namespace KoogleApp.Store.Game.Participants } [ReducerMethod] - public static ParticipantsState OnParticipantsState(ParticipantsState state, ParticipantsStateLoadedAction action) + public static ParticipantsState OnParticipantsState(ParticipantsState state, ParticipantsStateChangedAction action) { return action.ParticipantsState; } diff --git a/KoogleApp/Store/Game/Setup/Actions.cs b/KoogleApp/Store/Game/Setup/Actions.cs index dd3a252..83ff279 100644 --- a/KoogleApp/Store/Game/Setup/Actions.cs +++ b/KoogleApp/Store/Game/Setup/Actions.cs @@ -11,4 +11,6 @@ namespace KoogleApp.Store.Game.Setup public record LoadSetupStatesFromSessionAction(); public record SetupStateLoadedAction(SetupState SetupState); + + public record ResetSetupStateAction(); } diff --git a/KoogleApp/Store/Game/Setup/State.cs b/KoogleApp/Store/Game/Setup/State.cs index 4c74534..04c1a90 100644 --- a/KoogleApp/Store/Game/Setup/State.cs +++ b/KoogleApp/Store/Game/Setup/State.cs @@ -6,7 +6,8 @@ namespace KoogleApp.Store.Game.Setup [FeatureState] 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) { } } } diff --git a/KoogleApp/Store/Game/ThrowPanel/Effects.cs b/KoogleApp/Store/Game/ThrowPanel/Effects.cs index 048f2ca..7d97871 100644 --- a/KoogleApp/Store/Game/ThrowPanel/Effects.cs +++ b/KoogleApp/Store/Game/ThrowPanel/Effects.cs @@ -20,6 +20,7 @@ namespace KoogleApp.Store.Game.ThrowPanel private readonly ILogger _logger; private readonly HubConnectionService _sharedHubService; private readonly IState _throwPanelState; + private readonly IState _setupState; private readonly SessionStorage _sessionStorage; private readonly string _dataFilePath = "ThrowPanelState.json"; private readonly AuthenticationStateProvider _authenticationStateProvider; @@ -32,6 +33,7 @@ namespace KoogleApp.Store.Game.ThrowPanel ILogger logger, HubConnectionService sharedHubService, IState throwPanelState, + IState setupState, AuthenticationStateProvider authenticationStateProvider, IGameStatusDataService dataService, SessionStorage sessionStorage) @@ -65,7 +67,7 @@ namespace KoogleApp.Store.Game.ThrowPanel setupState = new SetupState(startStopAction.StartParams.ThrowMode, startStopAction.StartParams.ThrowsPerRound, startStopAction.StartParams.Participants, ParticipantsMode: startStopAction.StartParams.ParticipantsMode); - + var username = await GetUsername(); _dataService.Initialize(new GameStatus() { @@ -82,13 +84,14 @@ namespace KoogleApp.Store.Game.ThrowPanel ThrowPanelState = _throwPanelState.Value with { ThrowPanelStateStatus = ThrowPanelStateStatus.GameEnd }, }, username); 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)); - if (participantsState != null) - { - dispatcher.Dispatch(new ParticipantsStateChangedAction(participantsState)); - } + dispatcher.Dispatch(new ParticipantsStateChangedAction(participantsState)); + dispatcher.Dispatch(new ResetSetupStateAction()); // TODO: not reduced } [EffectMethod] diff --git a/KoogleApp/appdata.json b/KoogleApp/appdata.json index 06d712c..9443f39 100644 --- a/KoogleApp/appdata.json +++ b/KoogleApp/appdata.json @@ -33,7 +33,7 @@ } }, "Version": 2, - "LastModified": "2025-11-21T17:52:34.7010655+01:00", + "LastModified": "2025-11-21T19:30:06.7529818+01:00", "LastModifiedBy": "test1@test.de" }, "UndoHistory": [ @@ -49,7 +49,7 @@ 12, 9 ], - "ParticipantsMode": 1 + "ParticipantsMode": 0 }, "ThrowPanelState": { "IsStated": true, @@ -82,7 +82,7 @@ } }, "Version": 1, - "LastModified": "2025-11-21T17:52:34.6986698+01:00", + "LastModified": "2025-11-21T19:30:06.7492871+01:00", "LastModifiedBy": "test1@test.de" } ], diff --git a/KoogleApp/participantsState.json b/KoogleApp/participantsState.json deleted file mode 100644 index 19db104..0000000 --- a/KoogleApp/participantsState.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "PlayerIds": [ - 12, - 5, - 3, - 10, - 9 - ], - "Eliminated": [] -} \ No newline at end of file