dev state handling
This commit is contained in:
parent
e2fdb23f56
commit
3e42cc1bb9
|
|
@ -39,7 +39,7 @@
|
|||
set
|
||||
{
|
||||
if (value != null)
|
||||
Dispatcher.Dispatch(new SelectedPlayerChangedAction(value.Id));
|
||||
Dispatcher.Dispatch(new SelectedPlayerChangedAction(ParticipantsState.Value, value.Id));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -87,6 +87,6 @@
|
|||
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,15 @@
|
|||
{
|
||||
"Id": 34,
|
||||
"Date": "2025-11-19T00:00:00",
|
||||
"Id": 35,
|
||||
"Date": "2025-11-21T00:00:00",
|
||||
"Status": 1,
|
||||
"PlayerIds": [
|
||||
5,
|
||||
3,
|
||||
10,
|
||||
12,
|
||||
9
|
||||
],
|
||||
"CreatedAt": "2025-11-19T16:42:56.6330335",
|
||||
"CreatedAt": "2025-11-21T16:30:35.9889525",
|
||||
"ModifiedAt": null,
|
||||
"ModifiedBy": ""
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using KoogleApp.Store.Game.Participants;
|
||||
using KoogleApp.Store.Game.Setup;
|
||||
using KoogleApp.Store.Game.ThrowPanel;
|
||||
|
||||
namespace KoogleApp.Model
|
||||
|
|
@ -14,6 +15,8 @@ namespace KoogleApp.Model
|
|||
|
||||
public class GameStatus
|
||||
{
|
||||
public SetupState SetupState { get; set; }
|
||||
|
||||
public ThrowPanelState? ThrowPanelState { get; set; }
|
||||
|
||||
public ParticipantsState? ParticipantsState { get; set; }
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ namespace KoogleApp.Services
|
|||
Task SaveToDatabaseAndReset(GameStatus lastContent, string username);
|
||||
|
||||
void Initialize(GameStatus content, string username);
|
||||
GameStatusSnapshot GetInitialData();
|
||||
}
|
||||
|
||||
public class GameStatusDataService : IGameStatusDataService
|
||||
|
|
@ -35,7 +36,7 @@ namespace KoogleApp.Services
|
|||
|
||||
}
|
||||
|
||||
public GameStatusSnapshot GetCurrentData()
|
||||
public GameStatusSnapshot GetCurrentData()
|
||||
{
|
||||
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)
|
||||
{
|
||||
UpdateData(lastContent, username);
|
||||
|
|
@ -92,7 +120,6 @@ namespace KoogleApp.Services
|
|||
_redoStack.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateData(GameStatus content, string username)
|
||||
{
|
||||
if (_currentData == null)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using KoogleApp.Store.Player;
|
||||
using KoogleApp.Store.Game.ThrowPanel;
|
||||
using KoogleApp.Store.Player;
|
||||
|
||||
namespace KoogleApp.Store.Game.Participants
|
||||
{
|
||||
|
|
@ -12,7 +13,13 @@ namespace KoogleApp.Store.Game.Participants
|
|||
|
||||
public record ParticipantsStateLoadedAction(ParticipantsState ParticipantsState);
|
||||
|
||||
public record SetParticipatingPlayersAction(int[] PlayerIds);
|
||||
|
||||
public record DeleteParticipantsSessionAction();
|
||||
|
||||
public record SelectedPlayerChangedAction(int Id);
|
||||
public record SelectedPlayerChangedAction(ParticipantsState ParticipantsState, int NewId);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,23 @@ namespace KoogleApp.Store.Game.Participants
|
|||
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]
|
||||
public async Task HandelSaveParticipantsStateAction(SaveParticipantsStateAction action, IDispatcher dispatcher)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -23,18 +23,18 @@ namespace KoogleApp.Store.Game.Participants
|
|||
}
|
||||
|
||||
|
||||
[ReducerMethod]
|
||||
public static ParticipantsState OnSelectedPlayerChangedAction(ParticipantsState state, SelectedPlayerChangedAction action)
|
||||
{
|
||||
var lst = state.PlayerIds.ToList();
|
||||
lst.Remove(action.Id);
|
||||
lst.Insert(0,action.Id);
|
||||
//[ReducerMethod]
|
||||
//public static ParticipantsState OnSelectedPlayerChangedAction(ParticipantsState state, SelectedPlayerChangedAction action)
|
||||
//{
|
||||
// var lst = state.PlayerIds.ToList();
|
||||
// lst.Remove(action.NewId);
|
||||
// lst.Insert(0,action.NewId);
|
||||
|
||||
return state with
|
||||
{
|
||||
PlayerIds = lst.ToArray()
|
||||
};
|
||||
}
|
||||
// return state with
|
||||
// {
|
||||
// PlayerIds = lst.ToArray()
|
||||
// };
|
||||
//}
|
||||
|
||||
[ReducerMethod]
|
||||
public static ParticipantsState OnUpdateStateAfterUndoRedo(ParticipantsState state, UpdateStateAfterUndoRedo action)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@ namespace KoogleApp.Store.Game.Setup
|
|||
|
||||
public record SetThrowsPerRoundAction(int ThrowsPerRound);
|
||||
|
||||
public record SetParticipatingPlayersAction(int[] PlayerIds);
|
||||
|
||||
public record SetParticipantsModeAction(ParticipantsMode ParticipantsMode);
|
||||
|
||||
public record LoadSetupStatesFromSessionAction();
|
||||
|
||||
public record SetupStateLoadedAction(SetupState SetupState);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
using Fluxor;
|
||||
using KoogleApp.Store.Game.Participants;
|
||||
using KoogleApp.Store.Game.ThrowPanel;
|
||||
|
||||
namespace KoogleApp.Store.Game.Setup
|
||||
{
|
||||
|
|
@ -39,5 +41,11 @@ namespace KoogleApp.Store.Game.Setup
|
|||
ParticipantsMode = action.ParticipantsMode
|
||||
};
|
||||
}
|
||||
|
||||
[ReducerMethod]
|
||||
public static SetupState OnSetupStateLoadedAction(SetupState state, SetupStateLoadedAction action)
|
||||
{
|
||||
return action.SetupState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using KoogleApp.Model;
|
||||
using KoogleApp.Store.Game.Participants;
|
||||
using KoogleApp.Store.Game.Setup;
|
||||
|
||||
namespace KoogleApp.Store.Game.ThrowPanel
|
||||
{
|
||||
|
|
|
|||
|
|
@ -55,17 +55,23 @@ namespace KoogleApp.Store.Game.ThrowPanel
|
|||
public async Task HandleStartAction(StartStopAction startStopAction, IDispatcher dispatcher)
|
||||
{
|
||||
ParticipantsState? participantsState = null;
|
||||
SetupState? setupState = null;
|
||||
if (startStopAction.StartParams != null) // start action
|
||||
{
|
||||
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
|
||||
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();
|
||||
_dataService.Initialize(new GameStatus()
|
||||
{
|
||||
ThrowPanelState = _throwPanelState.Value,
|
||||
ParticipantsState = participantsState,
|
||||
SetupState = setupState
|
||||
}, username);
|
||||
}
|
||||
else // stop action
|
||||
|
|
@ -220,14 +226,15 @@ namespace KoogleApp.Store.Game.ThrowPanel
|
|||
}
|
||||
|
||||
[EffectMethod]
|
||||
public async Task HandelLoadStateAction(LoadAllStatesFromSessionAction allStatesFromSessionAction, IDispatcher dispatcher)
|
||||
public async Task HandelLoadAllStatesFromSessionAction(LoadAllStatesFromSessionAction allStatesFromSessionAction, IDispatcher dispatcher)
|
||||
{
|
||||
dispatcher.Dispatch(new LoadThrowPanelStatesFromSessionAction());
|
||||
dispatcher.Dispatch(new LoadParticipantsStatesFromSessionAction());
|
||||
dispatcher.Dispatch(new LoadSetupStatesFromSessionAction());
|
||||
}
|
||||
|
||||
[EffectMethod]
|
||||
public async Task HandelLoadStateAction(LoadThrowPanelStatesFromSessionAction allStatesFromSessionAction, IDispatcher dispatcher)
|
||||
public async Task HandelLoadThrowPanelStatesFromSessionAction(LoadThrowPanelStatesFromSessionAction allStatesFromSessionAction, IDispatcher dispatcher)
|
||||
{
|
||||
var state = await _sessionStorage.GetThrowPanelStateAsync();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"CurrentData": {
|
||||
"Status": {
|
||||
"SetupState": null,
|
||||
"ThrowPanelState": {
|
||||
"IsStated": true,
|
||||
"BellValue": false,
|
||||
|
|
@ -14,62 +15,42 @@
|
|||
"Pin8State": 0,
|
||||
"Pin9State": 0,
|
||||
"ThrowsPerRound": 3,
|
||||
"ThrowCounterPerRound": 2,
|
||||
"ThrowCounterPerRound": 1,
|
||||
"ThrowMode": 0,
|
||||
"ThrowPanelStateStatus": 3,
|
||||
"ThrowCounter": 1,
|
||||
"DayId": 34
|
||||
"ThrowPanelStateStatus": 1,
|
||||
"ThrowCounter": 0,
|
||||
"DayId": 35
|
||||
},
|
||||
"ParticipantsState": {
|
||||
"PlayerIds": [
|
||||
5,
|
||||
3,
|
||||
10,
|
||||
12,
|
||||
9
|
||||
],
|
||||
"Eliminated": []
|
||||
}
|
||||
},
|
||||
"Version": 4,
|
||||
"LastModified": "2025-11-21T14:49:53.2943989+01:00",
|
||||
"Version": 2,
|
||||
"LastModified": "2025-11-21T17:52:34.7010655+01:00",
|
||||
"LastModifiedBy": "test1@test.de"
|
||||
},
|
||||
"UndoHistory": [
|
||||
{
|
||||
"Status": {
|
||||
"ThrowPanelState": {
|
||||
"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,
|
||||
"SetupState": {
|
||||
"ThrowMode": 0,
|
||||
"ThrowPanelStateStatus": 2,
|
||||
"ThrowCounter": 0,
|
||||
"DayId": 34
|
||||
},
|
||||
"ParticipantsState": {
|
||||
"PlayerIds": [
|
||||
"ThrowsPerRound": 3,
|
||||
"Players": [
|
||||
5,
|
||||
3,
|
||||
10,
|
||||
12,
|
||||
9
|
||||
],
|
||||
"Eliminated": []
|
||||
}
|
||||
},
|
||||
"Version": 3,
|
||||
"LastModified": "2025-11-21T14:49:53.289455+01:00",
|
||||
"LastModifiedBy": "test1@test.de"
|
||||
},
|
||||
{
|
||||
"Status": {
|
||||
"ParticipantsMode": 1
|
||||
},
|
||||
"ThrowPanelState": {
|
||||
"IsStated": true,
|
||||
"BellValue": false,
|
||||
|
|
@ -87,46 +68,21 @@
|
|||
"ThrowMode": 0,
|
||||
"ThrowPanelStateStatus": 1,
|
||||
"ThrowCounter": 0,
|
||||
"DayId": 34
|
||||
"DayId": 35
|
||||
},
|
||||
"ParticipantsState": {
|
||||
"PlayerIds": [
|
||||
5,
|
||||
3,
|
||||
10,
|
||||
12,
|
||||
9
|
||||
],
|
||||
"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,
|
||||
"LastModified": "2025-11-21T14:49:31.5423511+01:00",
|
||||
"LastModified": "2025-11-21T17:52:34.6986698+01:00",
|
||||
"LastModifiedBy": "test1@test.de"
|
||||
}
|
||||
],
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"PlayerIds": [
|
||||
12,
|
||||
5,
|
||||
3,
|
||||
10,
|
||||
9
|
||||
],
|
||||
"Eliminated": []
|
||||
}
|
||||
Loading…
Reference in New Issue