From 92dfb47a08fa9ddf4eb6dc6d780d349aa5c3e436 Mon Sep 17 00:00:00 2001 From: beo3000 Date: Sat, 27 Dec 2025 13:15:18 +0100 Subject: [PATCH] refactoring GameSetup --- .../Interfaces/IGameSetupControl.cs | 14 +++ .../Components/Game/GameSetupDialog.razor | 118 ++++++++---------- .../Components/Game/GameTypeSelector.razor | 17 ++- .../Components/Game/Shit/ShitSetup.razor | 20 ++- .../Game/Training/TrainingSetup.razor | 13 ++ 5 files changed, 112 insertions(+), 70 deletions(-) create mode 100644 src/Koogle.Application/Interfaces/IGameSetupControl.cs diff --git a/src/Koogle.Application/Interfaces/IGameSetupControl.cs b/src/Koogle.Application/Interfaces/IGameSetupControl.cs new file mode 100644 index 0000000..623fe80 --- /dev/null +++ b/src/Koogle.Application/Interfaces/IGameSetupControl.cs @@ -0,0 +1,14 @@ +using Koogle.Application.Games; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Koogle.Application.Interfaces +{ + public interface IGameSetupControl + { + IGameSetupModel GameSetupModel { get; } + } +} diff --git a/src/Koogle.Web/Components/Game/GameSetupDialog.razor b/src/Koogle.Web/Components/Game/GameSetupDialog.razor index f0a7018..f3d15d1 100644 --- a/src/Koogle.Web/Components/Game/GameSetupDialog.razor +++ b/src/Koogle.Web/Components/Game/GameSetupDialog.razor @@ -3,6 +3,7 @@ @using Koogle.Application.Games @using Koogle.Application.Games.Shit @using Koogle.Application.Games.Training +@using Koogle.Application.Interfaces @using Koogle.Domain.Enums @using Koogle.Domain.Interfaces @using Koogle.Web.Store.DayState @@ -23,13 +24,23 @@ OnGameDefinitionChanged="OnGameDefinitionChanged" /> - @* Step 2: Game-specific Setup *@ - + + + + @* Step 3: Game-specific Setup *@ + @if (_selectedDefinition != null) { } else @@ -40,23 +51,14 @@ } - @* Step 3: Participant Selection *@ - - - - @* Step 4: Common Options *@ - - + *@ @* Validation errors *@ @@ -79,7 +81,7 @@ Teilnehmer: @_selectedParticipantIds.Count Spieler - Modus: @GetThrowModeLabel(_throwMode) + Modus: @GetThrowModeLabel() @@ -107,6 +109,8 @@ @code { + private DynamicComponent? dynamicComponentRef; + /// /// ID of the day to start the game for. /// @@ -125,10 +129,10 @@ private IGameDefinition? _selectedDefinition; private IReadOnlyList _availableParticipants = []; private IReadOnlyList _selectedParticipantIds = []; - private object? _gameSpecificSetupOptions; - private ThrowMode _throwMode = ThrowMode.Reposition; - private int _throwsPerRound = 3; - private ParticipantsMode _participantsMode = ParticipantsMode.GameLogic; + // private object? _gameSpecificSetupOptions; + // private ThrowMode _throwMode = ThrowMode.Reposition; + // private int _throwsPerRound = 3; + // private ParticipantsMode _participantsMode = ParticipantsMode.GameLogic; private string? _validationError; private bool _isStarting; @@ -147,7 +151,7 @@ private void OnGameDefinitionChanged(IGameDefinition? definition) { _selectedDefinition = definition; - _gameSpecificSetupOptions = null; + // _gameSpecificSetupOptions = null; _validationError = null; if (definition != null) @@ -161,13 +165,13 @@ return new Dictionary { ["OnOptionsChanged"] = EventCallback.Factory.Create(this, OnSetupOptionsChanged), - ["InitialOptions"] = _gameSpecificSetupOptions! + // ["InitialOptions"] = _gameSpecificSetupOptions! }; } private void OnSetupOptionsChanged(object options) { - _gameSpecificSetupOptions = options; + // _gameSpecificSetupOptions = options; _validationError = null; } @@ -192,9 +196,12 @@ try { + // Create typed setup model based on game type + IGameSetupModel? setup = CreateSetupModel(_selectedDefinition.Name); + // Validate setup options var logicService = GameRegistry.GetLogicService(_selectedDefinition.Name); - var validationResult = logicService.ValidateSetup(_gameSpecificSetupOptions); + var validationResult = logicService.ValidateSetup(setup); if (!validationResult.IsValid) { @@ -206,19 +213,17 @@ // Create initial game model and setup var playerIds = _selectedParticipantIds.ToArray(); - // Create typed setup model based on game type - IGameSetupModel? setup = CreateSetupModel(_selectedDefinition.Name); - var initialModel = logicService.CreateInitialModel(playerIds, setup ?? _gameSpecificSetupOptions); + var initialModel = logicService.CreateInitialModel(playerIds, setup); // Dispatch start game action var action = new StartGameAction( DayId: DayId, GameTypeName: _selectedDefinition.Name, PlayerIds: playerIds, - ThrowMode: _throwMode, - ThrowsPerRound: _throwsPerRound, - ParticipantsMode: _participantsMode, + ThrowMode: setup.ThrowMode, + ThrowsPerRound: setup.ThrowsPerRound, + ParticipantsMode: setup.ParticipantsMode, InitialGameModel: initialModel, Setup: setup); @@ -244,48 +249,29 @@ MudDialog?.Cancel(); } - private string GetThrowModeLabel(ThrowMode mode) => mode switch + private string GetThrowModeLabel() { - ThrowMode.Reposition => "In die Vollen", - ThrowMode.Decrease => "Abräumen", - _ => mode.ToString() - }; + IGameSetupModel? setup = CreateSetupModel(_selectedDefinition.Name); + switch (setup.ThrowMode) + { + case ThrowMode.Reposition: + return "In die Vollen"; + case ThrowMode.Decrease: + return "Abräumen"; + } + + return ""; + } private IGameSetupModel? CreateSetupModel(string gameTypeName) { - return gameTypeName switch - { - "Shit" => CreateShitSetup(), - "Training" => CreateTrainingSetup(), - _ => null - }; + var setupModel = (dynamicComponentRef.Instance as IGameSetupControl).GameSetupModel; + // setupModel.DayId = DayState.Value.Id; + // setupModel.KnownGameType = SetupState.Value.Game.GetType().Name; + // setupModel.Participants = PlayerIds; + return setupModel; } - private ShitGameSetup CreateShitSetup() - { - // Extract game-specific options if available - var shitNumber = 5; - var startNumber = 50; - - if (_gameSpecificSetupOptions is ShitGameSetup existingSetup) - { - shitNumber = existingSetup.ShitNumber; - startNumber = existingSetup.StartNumber; - } - - return ShitGameSetup.Create( - throwMode: _throwMode, - throwsPerRound: _throwsPerRound, - participantsMode: _participantsMode, - shitNumber: shitNumber, - startNumber: startNumber); - } - - private TrainingGameSetup CreateTrainingSetup() - { - return TrainingGameSetup.Create( - throwMode: _throwMode, - throwsPerRound: _throwsPerRound, - participantsMode: _participantsMode); - } + + } diff --git a/src/Koogle.Web/Components/Game/GameTypeSelector.razor b/src/Koogle.Web/Components/Game/GameTypeSelector.razor index 6ed285f..fa77595 100644 --- a/src/Koogle.Web/Components/Game/GameTypeSelector.razor +++ b/src/Koogle.Web/Components/Game/GameTypeSelector.razor @@ -6,8 +6,19 @@ Spieltyp auswählen - - + + + @foreach (var definition in _gameDefinitions) + { + + + + @definition.DisplayName + + + } + + @* @foreach (var definition in _gameDefinitions) { } - + *@ @if (_gameDefinitions.Count == 0) { diff --git a/src/Koogle.Web/Components/Game/Shit/ShitSetup.razor b/src/Koogle.Web/Components/Game/Shit/ShitSetup.razor index 18977c7..bbbb3c6 100644 --- a/src/Koogle.Web/Components/Game/Shit/ShitSetup.razor +++ b/src/Koogle.Web/Components/Game/Shit/ShitSetup.razor @@ -1,10 +1,11 @@ +@using Koogle.Application.Games @using Koogle.Application.Games.Shit @using Koogle.Application.Interfaces @using Koogle.Domain.Enums @using MudBlazor @inject ITriggerService TriggerService - +@implements IGameSetupControl Scheiss-Spiel Einstellungen @@ -130,4 +131,21 @@ public int StartNumber { get; set; } = 50; public ParticipantsMode ParticipantsMode { get; set; } = ParticipantsMode.GameLogic; } + + public IGameSetupModel GameSetupModel => CreateShitSetup(); + + private ShitGameSetup CreateShitSetup() + { + // Extract game-specific options if available + var shitNumber = 5; + var startNumber = 50; + + return ShitGameSetup.Create( + throwMode: ThrowMode.Reposition, + throwsPerRound: int.MaxValue, + participantsMode: ParticipantsMode.GameLogic, + shitNumber: _options.ShitNumber, + startNumber: _options.StartNumber); + } + } diff --git a/src/Koogle.Web/Components/Game/Training/TrainingSetup.razor b/src/Koogle.Web/Components/Game/Training/TrainingSetup.razor index f19b519..33d1e87 100644 --- a/src/Koogle.Web/Components/Game/Training/TrainingSetup.razor +++ b/src/Koogle.Web/Components/Game/Training/TrainingSetup.razor @@ -1,7 +1,10 @@ +@using Koogle.Application.Games @using Koogle.Application.Games.Training @using Koogle.Domain.Enums @using MudBlazor +@using Koogle.Application.Interfaces; +@implements IGameSetupControl Training-Einstellungen @@ -123,4 +126,14 @@ set => _participantsMode = value; } } + + public IGameSetupModel GameSetupModel => CreateTrainingSetup(); + + private TrainingGameSetup CreateTrainingSetup() + { + return TrainingGameSetup.Create( + throwMode: _options.ThrowMode, + throwsPerRound: _options.ThrowsPerRound, + participantsMode: _options.ParticipantsMode); + } }