dev state handling

This commit is contained in:
beo3000 2025-11-21 17:53:36 +01:00
parent e2fdb23f56
commit 3e42cc1bb9
16 changed files with 168 additions and 90 deletions

View File

@ -39,7 +39,7 @@
set set
{ {
if (value != null) if (value != null)
Dispatcher.Dispatch(new SelectedPlayerChangedAction(value.Id)); Dispatcher.Dispatch(new SelectedPlayerChangedAction(ParticipantsState.Value, value.Id));
} }
} }

View File

@ -87,6 +87,6 @@
private void Start() private void Start()
{ {
MudDialog.Close(DialogResult.Ok(new StartParams(DayState.Value.Id, SetupState.Value.ThrowMode, SetupState.Value.ThrowsPerRound, PlayerIds))); MudDialog.Close(DialogResult.Ok(new StartParams(DayState.Value.Id, SetupState.Value.ThrowMode, SetupState.Value.ThrowsPerRound, PlayerIds, SetupState.Value.ParticipantsMode)));
} }
} }

View File

@ -1,13 +1,15 @@
{ {
"Id": 34, "Id": 35,
"Date": "2025-11-19T00:00:00", "Date": "2025-11-21T00:00:00",
"Status": 1, "Status": 1,
"PlayerIds": [ "PlayerIds": [
5, 5,
3, 3,
10,
12,
9 9
], ],
"CreatedAt": "2025-11-19T16:42:56.6330335", "CreatedAt": "2025-11-21T16:30:35.9889525",
"ModifiedAt": null, "ModifiedAt": null,
"ModifiedBy": "" "ModifiedBy": ""
} }

View File

@ -1,4 +1,5 @@
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;
namespace KoogleApp.Model namespace KoogleApp.Model
@ -14,6 +15,8 @@ namespace KoogleApp.Model
public class GameStatus public class GameStatus
{ {
public SetupState SetupState { get; set; }
public ThrowPanelState? ThrowPanelState { get; set; } public ThrowPanelState? ThrowPanelState { get; set; }
public ParticipantsState? ParticipantsState { get; set; } public ParticipantsState? ParticipantsState { get; set; }

View File

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

View File

@ -19,6 +19,7 @@ namespace KoogleApp.Services
Task SaveToDatabaseAndReset(GameStatus lastContent, string username); Task SaveToDatabaseAndReset(GameStatus lastContent, string username);
void Initialize(GameStatus content, string username); void Initialize(GameStatus content, string username);
GameStatusSnapshot GetInitialData();
} }
public class GameStatusDataService : IGameStatusDataService public class GameStatusDataService : IGameStatusDataService
@ -35,7 +36,7 @@ namespace KoogleApp.Services
} }
public GameStatusSnapshot GetCurrentData() public GameStatusSnapshot GetCurrentData()
{ {
lock (_lock) lock (_lock)
{ {
@ -57,6 +58,33 @@ namespace KoogleApp.Services
} }
} }
public GameStatusSnapshot GetInitialData()
{
lock (_lock)
{
var stateCurrent = GetCurrentData();
if (stateCurrent == null)
{
LoadFromFile();
}
if (_undoStack != null && _undoStack.Count > 0)
{
var items = _undoStack.ToList();
var state = items.First();
return new GameStatusSnapshot
{
Status = state.Status,
LastModified = state.LastModified,
LastModifiedBy = state.LastModifiedBy,
Version = state.Version
};
}
return GetCurrentData();
}
}
public Task SaveToDatabaseAndReset(GameStatus lastContent, string username) public Task SaveToDatabaseAndReset(GameStatus lastContent, string username)
{ {
UpdateData(lastContent, username); UpdateData(lastContent, username);
@ -92,7 +120,6 @@ namespace KoogleApp.Services
_redoStack.Clear(); _redoStack.Clear();
} }
} }
public void UpdateData(GameStatus content, string username) public void UpdateData(GameStatus content, string username)
{ {
if (_currentData == null) if (_currentData == null)

View File

@ -1,4 +1,5 @@
using KoogleApp.Store.Player; using KoogleApp.Store.Game.ThrowPanel;
using KoogleApp.Store.Player;
namespace KoogleApp.Store.Game.Participants namespace KoogleApp.Store.Game.Participants
{ {
@ -12,7 +13,13 @@ namespace KoogleApp.Store.Game.Participants
public record ParticipantsStateLoadedAction(ParticipantsState ParticipantsState); public record ParticipantsStateLoadedAction(ParticipantsState ParticipantsState);
public record SetParticipatingPlayersAction(int[] PlayerIds);
public record DeleteParticipantsSessionAction(); public record DeleteParticipantsSessionAction();
public record SelectedPlayerChangedAction(int Id); public record SelectedPlayerChangedAction(ParticipantsState ParticipantsState, int NewId);
} }

View File

@ -23,6 +23,23 @@ namespace KoogleApp.Store.Game.Participants
dispatcher.Dispatch(new BroadcastParticipantsStateAction(action.ParticipantsState)); dispatcher.Dispatch(new BroadcastParticipantsStateAction(action.ParticipantsState));
} }
[EffectMethod]
public async Task HandelParticipantsStateChangedAction(SelectedPlayerChangedAction action,
IDispatcher dispatcher)
{
var lst = action.ParticipantsState.PlayerIds.ToList();
lst.Remove(action.NewId);
lst.Insert(0, action.NewId);
var newState = action.ParticipantsState with
{
PlayerIds = lst.ToArray()
};
dispatcher.Dispatch(new ParticipantsStateChangedAction(newState));
dispatcher.Dispatch(new ParticipantsStateLoadedAction(newState));
}
[EffectMethod] [EffectMethod]
public async Task HandelSaveParticipantsStateAction(SaveParticipantsStateAction action, IDispatcher dispatcher) public async Task HandelSaveParticipantsStateAction(SaveParticipantsStateAction action, IDispatcher dispatcher)
{ {

View File

@ -23,18 +23,18 @@ namespace KoogleApp.Store.Game.Participants
} }
[ReducerMethod] //[ReducerMethod]
public static ParticipantsState OnSelectedPlayerChangedAction(ParticipantsState state, SelectedPlayerChangedAction action) //public static ParticipantsState OnSelectedPlayerChangedAction(ParticipantsState state, SelectedPlayerChangedAction action)
{ //{
var lst = state.PlayerIds.ToList(); // var lst = state.PlayerIds.ToList();
lst.Remove(action.Id); // lst.Remove(action.NewId);
lst.Insert(0,action.Id); // lst.Insert(0,action.NewId);
return state with // return state with
{ // {
PlayerIds = lst.ToArray() // PlayerIds = lst.ToArray()
}; // };
} //}
[ReducerMethod] [ReducerMethod]
public static ParticipantsState OnUpdateStateAfterUndoRedo(ParticipantsState state, UpdateStateAfterUndoRedo action) public static ParticipantsState OnUpdateStateAfterUndoRedo(ParticipantsState state, UpdateStateAfterUndoRedo action)

View File

@ -6,7 +6,9 @@ namespace KoogleApp.Store.Game.Setup
public record SetThrowsPerRoundAction(int ThrowsPerRound); public record SetThrowsPerRoundAction(int ThrowsPerRound);
public record SetParticipatingPlayersAction(int[] PlayerIds);
public record SetParticipantsModeAction(ParticipantsMode ParticipantsMode); public record SetParticipantsModeAction(ParticipantsMode ParticipantsMode);
public record LoadSetupStatesFromSessionAction();
public record SetupStateLoadedAction(SetupState SetupState);
} }

View File

@ -0,0 +1,38 @@
using Fluxor;
using KoogleApp.Services;
using KoogleApp.Store.Game.Participants;
namespace KoogleApp.Store.Game.Setup
{
public class SetupStateEffects(
SessionStorage sessionStorage,
HubConnectionService sharedHubService,
IGameStatusDataService dataService)
{
private readonly SessionStorage _sessionStorage = sessionStorage;
//private const string _dataFilePath = "setupState.json";
//private const string _dataFilePath = "participantsState.json";
private readonly HubConnectionService _sharedHubService = sharedHubService;
private readonly IGameStatusDataService _dataService = dataService;
[EffectMethod]
public async Task HandelLoadSetupStatesFromSessionAction(LoadSetupStatesFromSessionAction action,
IDispatcher dispatcher)
{
var data = _dataService.GetInitialData();
if (data.Status != null)
{
var state = data.Status.SetupState;
if (state != null)
{
dispatcher.Dispatch(new SetupStateLoadedAction(state));
}
}
}
}
}

View File

@ -1,4 +1,6 @@
using Fluxor; using Fluxor;
using KoogleApp.Store.Game.Participants;
using KoogleApp.Store.Game.ThrowPanel;
namespace KoogleApp.Store.Game.Setup namespace KoogleApp.Store.Game.Setup
{ {
@ -39,5 +41,11 @@ namespace KoogleApp.Store.Game.Setup
ParticipantsMode = action.ParticipantsMode ParticipantsMode = action.ParticipantsMode
}; };
} }
[ReducerMethod]
public static SetupState OnSetupStateLoadedAction(SetupState state, SetupStateLoadedAction action)
{
return action.SetupState;
}
} }
} }

View File

@ -1,5 +1,6 @@
using KoogleApp.Model; using KoogleApp.Model;
using KoogleApp.Store.Game.Participants; using KoogleApp.Store.Game.Participants;
using KoogleApp.Store.Game.Setup;
namespace KoogleApp.Store.Game.ThrowPanel namespace KoogleApp.Store.Game.ThrowPanel
{ {

View File

@ -55,17 +55,23 @@ namespace KoogleApp.Store.Game.ThrowPanel
public async Task HandleStartAction(StartStopAction startStopAction, IDispatcher dispatcher) public async Task HandleStartAction(StartStopAction startStopAction, IDispatcher dispatcher)
{ {
ParticipantsState? participantsState = null; ParticipantsState? participantsState = null;
SetupState? setupState = null;
if (startStopAction.StartParams != null) // start action if (startStopAction.StartParams != null) // start action
{ {
dispatcher.Dispatch(new SetParticipatingPlayersAction(startStopAction.StartParams.Participants)); dispatcher.Dispatch(new SetParticipatingPlayersAction(startStopAction.StartParams.Participants));
// here we just want to pass the participants with ThrowPanelStateChangedAction - therefore we create a copy of ParticipantsState - I think this is valid just for the startup of a new game // here we just want to pass the participants with ThrowPanelStateChangedAction - therefore we create a copy of ParticipantsState - I think this is valid just for the startup of a new game
participantsState = new ParticipantsState(startStopAction.StartParams.Participants, []); participantsState = new ParticipantsState(startStopAction.StartParams.Participants, []);
setupState = new SetupState(startStopAction.StartParams.ThrowMode,
startStopAction.StartParams.ThrowsPerRound, startStopAction.StartParams.Participants,
ParticipantsMode: startStopAction.StartParams.ParticipantsMode);
var username = await GetUsername(); var username = await GetUsername();
_dataService.Initialize(new GameStatus() _dataService.Initialize(new GameStatus()
{ {
ThrowPanelState = _throwPanelState.Value, ThrowPanelState = _throwPanelState.Value,
ParticipantsState = participantsState,
SetupState = setupState
}, username); }, username);
} }
else // stop action else // stop action
@ -220,14 +226,15 @@ namespace KoogleApp.Store.Game.ThrowPanel
} }
[EffectMethod] [EffectMethod]
public async Task HandelLoadStateAction(LoadAllStatesFromSessionAction allStatesFromSessionAction, IDispatcher dispatcher) public async Task HandelLoadAllStatesFromSessionAction(LoadAllStatesFromSessionAction allStatesFromSessionAction, IDispatcher dispatcher)
{ {
dispatcher.Dispatch(new LoadThrowPanelStatesFromSessionAction()); dispatcher.Dispatch(new LoadThrowPanelStatesFromSessionAction());
dispatcher.Dispatch(new LoadParticipantsStatesFromSessionAction()); dispatcher.Dispatch(new LoadParticipantsStatesFromSessionAction());
dispatcher.Dispatch(new LoadSetupStatesFromSessionAction());
} }
[EffectMethod] [EffectMethod]
public async Task HandelLoadStateAction(LoadThrowPanelStatesFromSessionAction allStatesFromSessionAction, IDispatcher dispatcher) public async Task HandelLoadThrowPanelStatesFromSessionAction(LoadThrowPanelStatesFromSessionAction allStatesFromSessionAction, IDispatcher dispatcher)
{ {
var state = await _sessionStorage.GetThrowPanelStateAsync(); var state = await _sessionStorage.GetThrowPanelStateAsync();

View File

@ -1,6 +1,7 @@
{ {
"CurrentData": { "CurrentData": {
"Status": { "Status": {
"SetupState": null,
"ThrowPanelState": { "ThrowPanelState": {
"IsStated": true, "IsStated": true,
"BellValue": false, "BellValue": false,
@ -14,62 +15,42 @@
"Pin8State": 0, "Pin8State": 0,
"Pin9State": 0, "Pin9State": 0,
"ThrowsPerRound": 3, "ThrowsPerRound": 3,
"ThrowCounterPerRound": 2, "ThrowCounterPerRound": 1,
"ThrowMode": 0, "ThrowMode": 0,
"ThrowPanelStateStatus": 3, "ThrowPanelStateStatus": 1,
"ThrowCounter": 1, "ThrowCounter": 0,
"DayId": 34 "DayId": 35
}, },
"ParticipantsState": { "ParticipantsState": {
"PlayerIds": [ "PlayerIds": [
5, 5,
3, 3,
10,
12,
9 9
], ],
"Eliminated": [] "Eliminated": []
} }
}, },
"Version": 4, "Version": 2,
"LastModified": "2025-11-21T14:49:53.2943989+01:00", "LastModified": "2025-11-21T17:52:34.7010655+01:00",
"LastModifiedBy": "test1@test.de" "LastModifiedBy": "test1@test.de"
}, },
"UndoHistory": [ "UndoHistory": [
{ {
"Status": { "Status": {
"ThrowPanelState": { "SetupState": {
"IsStated": true,
"BellValue": false,
"Pin1State": 0,
"Pin2State": 0,
"Pin3State": 0,
"Pin4State": 1,
"Pin5State": 1,
"Pin6State": 1,
"Pin7State": 1,
"Pin8State": 1,
"Pin9State": 1,
"ThrowsPerRound": 3,
"ThrowCounterPerRound": 1,
"ThrowMode": 0, "ThrowMode": 0,
"ThrowPanelStateStatus": 2, "ThrowsPerRound": 3,
"ThrowCounter": 0, "Players": [
"DayId": 34
},
"ParticipantsState": {
"PlayerIds": [
5, 5,
3, 3,
10,
12,
9 9
], ],
"Eliminated": [] "ParticipantsMode": 1
} },
},
"Version": 3,
"LastModified": "2025-11-21T14:49:53.289455+01:00",
"LastModifiedBy": "test1@test.de"
},
{
"Status": {
"ThrowPanelState": { "ThrowPanelState": {
"IsStated": true, "IsStated": true,
"BellValue": false, "BellValue": false,
@ -87,46 +68,21 @@
"ThrowMode": 0, "ThrowMode": 0,
"ThrowPanelStateStatus": 1, "ThrowPanelStateStatus": 1,
"ThrowCounter": 0, "ThrowCounter": 0,
"DayId": 34 "DayId": 35
}, },
"ParticipantsState": { "ParticipantsState": {
"PlayerIds": [ "PlayerIds": [
5, 5,
3, 3,
10,
12,
9 9
], ],
"Eliminated": [] "Eliminated": []
} }
}, },
"Version": 2,
"LastModified": "2025-11-21T14:49:31.5450392+01:00",
"LastModifiedBy": "test1@test.de"
},
{
"Status": {
"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": 34
},
"ParticipantsState": null
},
"Version": 1, "Version": 1,
"LastModified": "2025-11-21T14:49:31.5423511+01:00", "LastModified": "2025-11-21T17:52:34.6986698+01:00",
"LastModifiedBy": "test1@test.de" "LastModifiedBy": "test1@test.de"
} }
], ],

View File

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