update model state
This commit is contained in:
parent
ed55bfda43
commit
ee1df61b74
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
@if (TrainingState.Value != null)
|
||||
{
|
||||
<p>@TrainingState.Value.TestField</p>
|
||||
<p>@TrainingState.Value</p>
|
||||
}
|
||||
|
||||
@code {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,16 @@ namespace KoogleApp.Games.Training
|
|||
public IGameModel InitGameModel(StartParams startParams)
|
||||
{
|
||||
_gameModel = new TrainingState();
|
||||
|
||||
var dict = new Dictionary<int, ThrowModel>();
|
||||
|
||||
foreach (var participant in startParams.Participants)
|
||||
{
|
||||
var tm = new ThrowModel() with { PlayerId = participant };
|
||||
dict.Add(participant, tm);
|
||||
}
|
||||
|
||||
_gameModel = _gameModel with { Throws = dict };
|
||||
return _gameModel;
|
||||
}
|
||||
|
||||
|
|
@ -41,8 +51,16 @@ namespace KoogleApp.Games.Training
|
|||
res.Add(new SelectedNextPlayerIds(afterParticipantsState));
|
||||
}
|
||||
|
||||
var playerId = progress.BeforeParticipantsState.PlayerIds.First();
|
||||
|
||||
var newModel = ((TrainingState)(progress.GameModel)) with { TestField = "lorem ipsum" };
|
||||
var ts = progress.GameModel as TrainingState;
|
||||
var tm = ts.Throws[playerId];
|
||||
ts.Throws[playerId] = tm with
|
||||
{
|
||||
ThrowCount = tm.ThrowCount+1
|
||||
};
|
||||
|
||||
var newModel = ((TrainingState)(progress.GameModel)) with { Throws = ts.Throws };
|
||||
|
||||
res.Add(new UpdateTrainingStateAction(newModel));
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace KoogleApp.Games.Training
|
|||
[ReducerMethod]
|
||||
public static TrainingState OnTestActions(TrainingState state, UpdateTrainingStateAction action)
|
||||
{
|
||||
return state with { TestField = action.TrainingState.TestField };
|
||||
return action.TrainingState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,11 +3,32 @@ using System.Text.Json.Serialization;
|
|||
|
||||
namespace KoogleApp.Games.Training
|
||||
{
|
||||
[FeatureState]
|
||||
//[JsonPolymorphic(UnknownDerivedTypeHandling = JsonUnknownDerivedTypeHandling.FallBackToBaseType)]
|
||||
public record TrainingState(string TestField) : IGameModel
|
||||
|
||||
public record ThrowModel
|
||||
{
|
||||
public TrainingState():this(TestField:"DefaultValue TrainingState")
|
||||
public int PlayerId { get; set; }
|
||||
|
||||
public int TeamNr { get; set; }
|
||||
|
||||
public int PinCount { get; set; }
|
||||
|
||||
public int CircleCount { get; set; }
|
||||
|
||||
public int SinkCount { get; set; }
|
||||
|
||||
public int StrikeCount { get; set; }
|
||||
|
||||
public int ClearedCount { get; set; }
|
||||
|
||||
public int ThrowCount { get; set; }
|
||||
|
||||
public int BellCount { get; set; }
|
||||
}
|
||||
|
||||
[FeatureState]
|
||||
public record TrainingState(Dictionary<int,ThrowModel> Throws) : IGameModel
|
||||
{
|
||||
public TrainingState():this([])
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ namespace KoogleApp.Services
|
|||
return GetCurrentData();
|
||||
}
|
||||
}
|
||||
public StartParams? StartParams => GetInitialData().Status.StartParams;
|
||||
public StartParams? StartParams => GetInitialData()?.Status?.StartParams;
|
||||
|
||||
|
||||
public Task SaveToDatabaseAndReset(GameStatus lastContent, string username)
|
||||
|
|
|
|||
|
|
@ -1,141 +0,0 @@
|
|||
{
|
||||
"CurrentData": {
|
||||
"Status": {
|
||||
"StartParams": 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": 2,
|
||||
"ThrowMode": 0,
|
||||
"ThrowPanelStateStatus": 3,
|
||||
"ThrowCounter": 1,
|
||||
"DayId": 35
|
||||
},
|
||||
"ParticipantsState": {
|
||||
"PlayerIds": [
|
||||
5,
|
||||
3,
|
||||
10,
|
||||
12,
|
||||
9
|
||||
],
|
||||
"Eliminated": []
|
||||
},
|
||||
"GameModel": {
|
||||
"$type": "TrainingState",
|
||||
"TestField": "lorem ipsum"
|
||||
}
|
||||
},
|
||||
"Version": 3,
|
||||
"LastModified": "2025-11-25T16:54:41.0021528+01:00",
|
||||
"LastModifiedBy": "test1@test.de"
|
||||
},
|
||||
"UndoHistory": [
|
||||
{
|
||||
"Status": {
|
||||
"StartParams": null,
|
||||
"ThrowPanelState": {
|
||||
"IsStated": true,
|
||||
"BellValue": false,
|
||||
"Pin1State": 0,
|
||||
"Pin2State": 0,
|
||||
"Pin3State": 0,
|
||||
"Pin4State": 0,
|
||||
"Pin5State": 0,
|
||||
"Pin6State": 0,
|
||||
"Pin7State": 0,
|
||||
"Pin8State": 0,
|
||||
"Pin9State": 1,
|
||||
"ThrowsPerRound": 3,
|
||||
"ThrowCounterPerRound": 1,
|
||||
"ThrowMode": 0,
|
||||
"ThrowPanelStateStatus": 2,
|
||||
"ThrowCounter": 0,
|
||||
"DayId": 35
|
||||
},
|
||||
"ParticipantsState": {
|
||||
"PlayerIds": [
|
||||
5,
|
||||
3,
|
||||
10,
|
||||
12,
|
||||
9
|
||||
],
|
||||
"Eliminated": []
|
||||
},
|
||||
"GameModel": {
|
||||
"$type": "TrainingState",
|
||||
"TestField": "DefaultValue TrainingState"
|
||||
}
|
||||
},
|
||||
"Version": 2,
|
||||
"LastModified": "2025-11-25T16:54:39.3461194+01:00",
|
||||
"LastModifiedBy": "test1@test.de"
|
||||
},
|
||||
{
|
||||
"Status": {
|
||||
"StartParams": {
|
||||
"DayId": 35,
|
||||
"ThrowMode": 0,
|
||||
"ThrowsPerRound": 3,
|
||||
"Participants": [
|
||||
5,
|
||||
3,
|
||||
10,
|
||||
12,
|
||||
9
|
||||
],
|
||||
"ParticipantsMode": 1,
|
||||
"KnownGameType": "GameTraining"
|
||||
},
|
||||
"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": []
|
||||
},
|
||||
"GameModel": {
|
||||
"$type": "TrainingState",
|
||||
"TestField": "DefaultValue TrainingState"
|
||||
}
|
||||
},
|
||||
"Version": 1,
|
||||
"LastModified": "2025-11-25T15:54:32.8809692Z",
|
||||
"LastModifiedBy": "test1@test.de"
|
||||
}
|
||||
],
|
||||
"RedoHistory": []
|
||||
}
|
||||
Loading…
Reference in New Issue