dev statehandling

This commit is contained in:
beo3000 2025-11-21 20:32:20 +01:00
parent edb9a2eee8
commit 920d9e0959
5 changed files with 46 additions and 110 deletions

View File

@ -5,12 +5,14 @@
@using KoogleApp.Store.Game.Participants
@using KoogleApp.Store.Game.Setup
@using KoogleApp.Store.Game.ThrowPanel
@using KoogleApp.Store.Player
@inherits FluxorComponent
@inject IState<ThrowPanelState> ThrowPanelState
@inject IDispatcher Dispatcher
@inject IState<ParticipantsState> ParticipantsState
@inject IState<PlayersState> PlayersState
@inject IState<SetupState> SetupState
@if (ThrowPanelState.Value.IsStated)
@ -132,11 +134,11 @@
{
@if (SetupState.Value.ParticipantsMode == ParticipantsMode.FreeToChoose)
{
<ChangePlayerSelect />
<ChangePlayerSelect />
}
else
{
<p>@($"P: {@ParticipantsState.Value.PlayerIds.FirstOrDefault()}")</p>
@ParticipantsState.GetName(PlayersState);
}
}
</MudPaper>

View File

@ -35,17 +35,17 @@
@inject IDispatcher Dispatcher
@inject IDialogService DialogService
@* @inject IGameStatusDataService _dataService; *@
@inject IGameStatusDataService DataService;
@* @ThrowPanelState.Value *@
@switch (_gameView)
{
case GameView.Throw:
<PanelToolbar>
@* @GetParticipantsState() *@
@GetSetupState();
@* @DayState.Value *@
@* @GetParticipantsState()
@GetSetupState(); *@
@if (DayState.Value.Status != DayStatus.Started)
{
@ -105,21 +105,10 @@
private bool isAuthenticated;
protected override void OnInitialized()
{
{
base.OnInitialized();
// Verbindung zum Hub aufbauen (nur einmal)
// if (!ThrowPanelState.Value.IsConnected)
{
Dispatcher.Dispatch(new ConnectToHubAction());
Dispatcher.Dispatch(new InitializeDayAction());
Dispatcher.Dispatch(new UpdateUndoRedoStateAction());
}
}
protected override void OnAfterRender(bool firstRender)
@ -127,6 +116,11 @@
if (firstRender)
{
EventAggregator.Subscribe(this);
Dispatcher.Dispatch(new ConnectToHubAction());
Dispatcher.Dispatch(new InitializeDayAction());
DataService.LoadFromFile();
}
}

View File

@ -294,6 +294,10 @@ namespace KoogleApp.Services
if (history != null)
{
if (_undoStack == null)
{
_undoStack = new Stack<GameStatusSnapshot>();
}
_undoStack.Clear();
foreach (var snapshot in history.AsEnumerable().Reverse())
{
@ -310,6 +314,10 @@ namespace KoogleApp.Services
if (redoHistory != null)
{
if (_redoStack == null)
{
_redoStack = new Stack<GameStatusSnapshot>();
}
_redoStack.Clear();
foreach (var snapshot in redoHistory.AsEnumerable().Reverse())
{

View File

@ -0,0 +1,22 @@
using Fluxor;
using KoogleApp.Store.Player;
namespace KoogleApp.Store.Game.Participants
{
public static class ParticipantsSelectors
{
//public static string GetName(IState<PlayersState> players, IState<ParticipantsState> participants)
//{
// return players.Value.Players.First(p => p.Id == participants.Value.PlayerIds.First()).Name;
//}
public static string GetName(this IState<ParticipantsState> participants, IState<PlayersState> players)
{
if (participants.Value == null || participants.Value.PlayerIds.Length == 0)
{
return string.Empty;
}
return players.Value.Players.First(p => p.Id == participants.Value.PlayerIds.First()).Name;
}
}
}

View File

@ -1,90 +0,0 @@
{
"CurrentData": {
"Status": {
"SetupState": null,
"ThrowPanelState": {
"IsStated": true,
"BellValue": false,
"Pin1State": 0,
"Pin2State": 0,
"Pin3State": 0,
"Pin4State": 0,
"Pin5State": 0,
"Pin6State": 0,
"Pin7State": 0,
"Pin8State": 0,
"Pin9State": 0,
"ThrowsPerRound": 3,
"ThrowCounterPerRound": 1,
"ThrowMode": 0,
"ThrowPanelStateStatus": 1,
"ThrowCounter": 0,
"DayId": 35
},
"ParticipantsState": {
"PlayerIds": [
5,
3,
10,
12,
9
],
"Eliminated": []
}
},
"Version": 2,
"LastModified": "2025-11-21T19:30:06.7529818+01:00",
"LastModifiedBy": "test1@test.de"
},
"UndoHistory": [
{
"Status": {
"SetupState": {
"ThrowMode": 0,
"ThrowsPerRound": 3,
"Players": [
5,
3,
10,
12,
9
],
"ParticipantsMode": 0
},
"ThrowPanelState": {
"IsStated": true,
"BellValue": false,
"Pin1State": 0,
"Pin2State": 0,
"Pin3State": 0,
"Pin4State": 0,
"Pin5State": 0,
"Pin6State": 0,
"Pin7State": 0,
"Pin8State": 0,
"Pin9State": 0,
"ThrowsPerRound": 3,
"ThrowCounterPerRound": 1,
"ThrowMode": 0,
"ThrowPanelStateStatus": 1,
"ThrowCounter": 0,
"DayId": 35
},
"ParticipantsState": {
"PlayerIds": [
5,
3,
10,
12,
9
],
"Eliminated": []
}
},
"Version": 1,
"LastModified": "2025-11-21T19:30:06.7492871+01:00",
"LastModifiedBy": "test1@test.de"
}
],
"RedoHistory": []
}