@using Fluxor @using Koogle.Application.DTOs @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 @using Koogle.Web.Store.GameState @using MudBlazor @inject IState DayState @inject IDispatcher Dispatcher @inject GameDefinitionRegistry GameRegistry @* Step 1: Game Type Selection *@ @* Step 2: Participant Selection *@ @* Step 3: Game-specific Setup *@ @if (_selectedDefinition != null) { } else { Wähle zuerst einen Spieltyp aus. } @* Step 4: Common Options *@ @* *@ @* Validation errors *@ @if (!string.IsNullOrEmpty(_validationError)) { @_validationError } @* Game info summary *@ @if (CanStartGame()) { Spieltyp: @_selectedDefinition?.DisplayName Teilnehmer: @_selectedParticipantIds.Count Spieler Modus: @GetThrowModeLabel() } Abbrechen @if (_isStarting) { Starte... } else { Spiel starten } @code { private DynamicComponent? dynamicComponentRef; /// /// ID of the day to start the game for. /// [Parameter] public Guid DayId { get; set; } /// /// Cascade parameter for the dialog instance. /// [CascadingParameter] private IMudDialogInstance? MudDialog { get; set; } // State private int _currentStep = 1; private string? _selectedGameType; 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 string? _validationError; private bool _isStarting; protected override void OnInitialized() { // Get available participants from the selected day var selectedDay = DayState.Value.SelectedDay; if (selectedDay != null) { _availableParticipants = selectedDay.Participants; // Pre-select all participants _selectedParticipantIds = selectedDay.Participants.Select(p => p.PersonId).ToList(); } } private void OnGameDefinitionChanged(IGameDefinition? definition) { _selectedDefinition = definition; // _gameSpecificSetupOptions = null; _validationError = null; if (definition != null) { _currentStep = 2; } } private Dictionary GetSetupParameters() { return new Dictionary { ["OnOptionsChanged"] = EventCallback.Factory.Create(this, OnSetupOptionsChanged), // ["InitialOptions"] = _gameSpecificSetupOptions! }; } private void OnSetupOptionsChanged(object options) { // _gameSpecificSetupOptions = options; _validationError = null; } private bool CanStartGame() { if (_selectedDefinition == null) return false; if (_selectedParticipantIds.Count == 0) return false; return true; } private Task StartGame() { if (!CanStartGame() || _selectedDefinition == null) return Task.CompletedTask; _isStarting = true; _validationError = null; 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(setup); if (!validationResult.IsValid) { _validationError = string.Join(", ", validationResult.Errors); _isStarting = false; return Task.CompletedTask; } // Create initial game model and setup var playerIds = _selectedParticipantIds.ToArray(); var initialModel = logicService.CreateInitialModel(playerIds, setup); // Dispatch start game action var action = new StartGameAction( DayId: DayId, GameTypeName: _selectedDefinition.Name, PlayerIds: playerIds, ThrowMode: setup.ThrowMode, ThrowsPerRound: setup.ThrowsPerRound, ParticipantsMode: setup.ParticipantsMode, InitialGameModel: initialModel, Setup: setup); Dispatcher.Dispatch(action); // Close dialog MudDialog?.Close(DialogResult.Ok(true)); } catch (Exception ex) { _validationError = $"Fehler beim Starten: {ex.Message}"; } finally { _isStarting = false; } return Task.CompletedTask; } private void Cancel() { MudDialog?.Cancel(); } private string GetThrowModeLabel() { 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) { var setupModel = (dynamicComponentRef.Instance as IGameSetupControl).GameSetupModel; // setupModel.DayId = DayState.Value.Id; // setupModel.KnownGameType = SetupState.Value.Game.GetType().Name; // setupModel.Participants = PlayerIds; return setupModel; } }