@gamepark/react-client 6.38.5 → 7.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Actions/ActionFailed.d.ts +6 -6
- package/dist/Actions/ActionFailed.js +4 -8
- package/dist/Actions/ActionFailed.js.map +1 -1
- package/dist/Actions/AnimationComplete.d.ts +6 -6
- package/dist/Actions/AnimationComplete.js +4 -8
- package/dist/Actions/AnimationComplete.js.map +1 -1
- package/dist/Actions/AnimationPaused.d.ts +6 -6
- package/dist/Actions/AnimationPaused.js +4 -8
- package/dist/Actions/AnimationPaused.js.map +1 -1
- package/dist/Actions/AnimationStart.d.ts +5 -5
- package/dist/Actions/AnimationStart.js +1 -4
- package/dist/Actions/AnimationStart.js.map +1 -1
- package/dist/Actions/ClearFailures.d.ts +1 -5
- package/dist/Actions/ClearFailures.js +3 -9
- package/dist/Actions/ClearFailures.js.map +1 -1
- package/dist/Actions/GameNotificationsReceived.d.ts +8 -10
- package/dist/Actions/GameNotificationsReceived.js +2 -9
- package/dist/Actions/GameNotificationsReceived.js.map +1 -1
- package/dist/Actions/GameOver.d.ts +16 -16
- package/dist/Actions/GameOver.js +4 -8
- package/dist/Actions/GameOver.js.map +1 -1
- package/dist/Actions/GameStateLoaded.d.ts +16 -16
- package/dist/Actions/GameStateLoaded.js +7 -20
- package/dist/Actions/GameStateLoaded.js.map +1 -1
- package/dist/Actions/MovePlayed.d.ts +11 -11
- package/dist/Actions/MovePlayed.js +3 -2
- package/dist/Actions/MovePlayed.js.map +1 -1
- package/dist/Actions/MoveUndone.d.ts +7 -7
- package/dist/Actions/MoveUndone.js +4 -9
- package/dist/Actions/MoveUndone.js.map +1 -1
- package/dist/Actions/PlayerQuit.d.ts +5 -11
- package/dist/Actions/PlayerQuit.js +2 -19
- package/dist/Actions/PlayerQuit.js.map +1 -1
- package/dist/Actions/SetAnimationsSpeed.d.ts +1 -6
- package/dist/Actions/SetAnimationsSpeed.js +3 -9
- package/dist/Actions/SetAnimationsSpeed.js.map +1 -1
- package/dist/Actions/giveUp.d.ts +1 -0
- package/dist/Actions/giveUp.js +3 -0
- package/dist/Actions/giveUp.js.map +1 -0
- package/dist/Actions/index.d.ts +7 -12
- package/dist/Actions/index.js +7 -28
- package/dist/Actions/index.js.map +1 -1
- package/dist/Actions/loadGameState.d.ts +14 -0
- package/dist/Actions/loadGameState.js +3 -0
- package/dist/Actions/loadGameState.js.map +1 -0
- package/dist/Actions/playMove.d.ts +10 -0
- package/dist/Actions/playMove.js +3 -0
- package/dist/Actions/playMove.js.map +1 -0
- package/dist/Actions/receiveNotifications.d.ts +8 -0
- package/dist/Actions/receiveNotifications.js +3 -0
- package/dist/Actions/receiveNotifications.js.map +1 -0
- package/dist/Actions/removePlayer.d.ts +5 -0
- package/dist/Actions/removePlayer.js +3 -0
- package/dist/Actions/removePlayer.js.map +1 -0
- package/dist/Actions/reportFailure.d.ts +1 -0
- package/dist/Actions/reportFailure.js +3 -0
- package/dist/Actions/reportFailure.js.map +1 -0
- package/dist/Actions/setGameOver.d.ts +2 -0
- package/dist/Actions/setGameOver.js +3 -0
- package/dist/Actions/setGameOver.js.map +1 -0
- package/dist/Actions/startAnimation.d.ts +1 -0
- package/dist/Actions/startAnimation.js +3 -0
- package/dist/Actions/startAnimation.js.map +1 -0
- package/dist/Actions/undoMove.d.ts +5 -0
- package/dist/Actions/undoMove.js +4 -0
- package/dist/Actions/undoMove.js.map +1 -0
- package/dist/Chat/ChatChannel.d.ts +5 -5
- package/dist/Chat/ChatChannel.js +1 -2
- package/dist/Chat/Message.d.ts +6 -6
- package/dist/Chat/Message.js +1 -2
- package/dist/Chat/index.d.ts +2 -2
- package/dist/Chat/index.js +2 -18
- package/dist/Chat/index.js.map +1 -1
- package/dist/Deckbuilding/Deck.d.ts +5 -5
- package/dist/Deckbuilding/Deck.js +1 -2
- package/dist/Deckbuilding/index.d.ts +4 -4
- package/dist/Deckbuilding/index.js +4 -24
- package/dist/Deckbuilding/index.js.map +1 -1
- package/dist/Deckbuilding/useDeleteDeck.d.ts +5 -2
- package/dist/Deckbuilding/useDeleteDeck.js +9 -15
- package/dist/Deckbuilding/useDeleteDeck.js.map +1 -1
- package/dist/Deckbuilding/useMyDecks.d.ts +3 -2
- package/dist/Deckbuilding/useMyDecks.js +8 -14
- package/dist/Deckbuilding/useMyDecks.js.map +1 -1
- package/dist/Deckbuilding/useSaveDeck.d.ts +5 -2
- package/dist/Deckbuilding/useSaveDeck.js +9 -15
- package/dist/Deckbuilding/useSaveDeck.js.map +1 -1
- package/dist/EjectPlayer/EjectPlayer.d.ts +1 -6
- package/dist/EjectPlayer/EjectPlayer.js +2 -8
- package/dist/EjectPlayer/EjectPlayer.js.map +1 -1
- package/dist/EjectPlayer/index.d.ts +1 -1
- package/dist/EjectPlayer/index.js +1 -17
- package/dist/EjectPlayer/index.js.map +1 -1
- package/dist/Failure/Failure.d.ts +6 -6
- package/dist/Failure/Failure.js +6 -9
- package/dist/Failure/Failure.js.map +1 -1
- package/dist/Failure/index.d.ts +1 -1
- package/dist/Failure/index.js +1 -17
- package/dist/Failure/index.js.map +1 -1
- package/dist/GiveUp/GiveUp.d.ts +7 -7
- package/dist/GiveUp/GiveUp.js +2 -5
- package/dist/GiveUp/GiveUp.js.map +1 -1
- package/dist/GiveUp/index.d.ts +1 -1
- package/dist/GiveUp/index.js +1 -17
- package/dist/GiveUp/index.js.map +1 -1
- package/dist/Hooks/index.d.ts +5 -5
- package/dist/Hooks/index.js +5 -21
- package/dist/Hooks/index.js.map +1 -1
- package/dist/Hooks/useChatMessages.d.ts +7 -12
- package/dist/Hooks/useChatMessages.js +44 -51
- package/dist/Hooks/useChatMessages.js.map +1 -1
- package/dist/Hooks/useMessageAuthor.d.ts +4 -4
- package/dist/Hooks/useMessageAuthor.js +13 -18
- package/dist/Hooks/useMessageAuthor.js.map +1 -1
- package/dist/Hooks/useOptions.d.ts +2 -2
- package/dist/Hooks/useOptions.js +4 -8
- package/dist/Hooks/useOptions.js.map +1 -1
- package/dist/Hooks/useRematch.d.ts +7 -7
- package/dist/Hooks/useRematch.js +18 -19
- package/dist/Hooks/useRematch.js.map +1 -1
- package/dist/Hooks/useSendMessage.d.ts +4 -1
- package/dist/Hooks/useSendMessage.js +6 -14
- package/dist/Hooks/useSendMessage.js.map +1 -1
- package/dist/Log/StartLiveLog.d.ts +1 -4
- package/dist/Log/StartLiveLog.js +3 -5
- package/dist/Log/StartLiveLog.js.map +1 -1
- package/dist/Log/StopLiveLog.d.ts +2 -5
- package/dist/Log/StopLiveLog.js +6 -9
- package/dist/Log/StopLiveLog.js.map +1 -1
- package/dist/Log/index.d.ts +4 -4
- package/dist/Log/index.js +4 -20
- package/dist/Log/index.js.map +1 -1
- package/dist/Log/useLogControls.d.ts +7 -7
- package/dist/Log/useLogControls.js +18 -22
- package/dist/Log/useLogControls.js.map +1 -1
- package/dist/PlayerTime/PlayerTime.d.ts +11 -11
- package/dist/PlayerTime/PlayerTime.js +1 -2
- package/dist/PlayerTime/index.d.ts +1 -1
- package/dist/PlayerTime/index.js +1 -17
- package/dist/PlayerTime/index.js.map +1 -1
- package/dist/Rematch/RematchQueries.d.ts +19 -19
- package/dist/Rematch/RematchQueries.js +23 -13
- package/dist/Rematch/RematchQueries.js.map +1 -1
- package/dist/Rematch/index.d.ts +1 -1
- package/dist/Rematch/index.js +1 -17
- package/dist/Rematch/index.js.map +1 -1
- package/dist/Sound/MuteSounds.d.ts +2 -5
- package/dist/Sound/MuteSounds.js +7 -10
- package/dist/Sound/MuteSounds.js.map +1 -1
- package/dist/Sound/UnmuteSounds.d.ts +1 -4
- package/dist/Sound/UnmuteSounds.js +3 -5
- package/dist/Sound/UnmuteSounds.js.map +1 -1
- package/dist/Sound/index.d.ts +3 -3
- package/dist/Sound/index.js +3 -19
- package/dist/Sound/index.js.map +1 -1
- package/dist/Sound/useSoundControls.d.ts +7 -7
- package/dist/Sound/useSoundControls.js +18 -22
- package/dist/Sound/useSoundControls.js.map +1 -1
- package/dist/Store/DisplayedAction.d.ts +15 -15
- package/dist/Store/DisplayedAction.js +12 -19
- package/dist/Store/DisplayedAction.js.map +1 -1
- package/dist/Store/GamePageState.d.ts +27 -28
- package/dist/Store/GamePageState.js +1 -2
- package/dist/Store/PlayedMove.d.ts +5 -5
- package/dist/Store/PlayedMove.js +1 -2
- package/dist/Store/endAnimation.d.ts +1 -0
- package/dist/Store/endAnimation.js +3 -0
- package/dist/Store/endAnimation.js.map +1 -0
- package/dist/Store/gameMiddleware.d.ts +4 -4
- package/dist/Store/gameMiddleware.js +34 -41
- package/dist/Store/gameMiddleware.js.map +1 -1
- package/dist/Store/gameReducer.d.ts +14 -20
- package/dist/Store/gameReducer.js +462 -525
- package/dist/Store/gameReducer.js.map +1 -1
- package/dist/Store/index.d.ts +4 -3
- package/dist/Store/index.js +4 -19
- package/dist/Store/index.js.map +1 -1
- package/dist/Store/localMovePreviewMiddleware.d.ts +4 -4
- package/dist/Store/localMovePreviewMiddleware.js +19 -18
- package/dist/Store/localMovePreviewMiddleware.js.map +1 -1
- package/dist/Store/store.d.ts +13 -0
- package/dist/Store/store.js +27 -0
- package/dist/Store/store.js.map +1 -0
- package/dist/Tutorial/PlayTutorialMoves.d.ts +1 -9
- package/dist/Tutorial/PlayTutorialMoves.js +2 -6
- package/dist/Tutorial/PlayTutorialMoves.js.map +1 -1
- package/dist/Tutorial/Tutorial.d.ts +5 -5
- package/dist/Tutorial/Tutorial.js +1 -2
- package/dist/Tutorial/TutorialDescription.d.ts +7 -7
- package/dist/Tutorial/TutorialDescription.js +1 -2
- package/dist/Tutorial/index.d.ts +4 -4
- package/dist/Tutorial/index.js +4 -20
- package/dist/Tutorial/index.js.map +1 -1
- package/dist/Tutorial/useTutorial.d.ts +2 -2
- package/dist/Tutorial/useTutorial.js +12 -22
- package/dist/Tutorial/useTutorial.js.map +1 -1
- package/dist/Types/GameAI.d.ts +1 -1
- package/dist/Types/GameAI.js +1 -2
- package/dist/Types/GameData.d.ts +18 -18
- package/dist/Types/GameData.js +1 -2
- package/dist/Types/GameMessage.d.ts +8 -8
- package/dist/Types/GameMessage.js +1 -2
- package/dist/Types/GameMode.d.ts +6 -6
- package/dist/Types/GameMode.js +7 -10
- package/dist/Types/GameMode.js.map +1 -1
- package/dist/Types/GameNotification.d.ts +6 -6
- package/dist/Types/GameNotification.js +1 -2
- package/dist/Types/GameOptions.d.ts +9 -9
- package/dist/Types/GameOptions.js +5 -8
- package/dist/Types/GameOptions.js.map +1 -1
- package/dist/Types/MovePlayedNotification.d.ts +9 -9
- package/dist/Types/MovePlayedNotification.js +6 -12
- package/dist/Types/MovePlayedNotification.js.map +1 -1
- package/dist/Types/MoveUndoneNotification.d.ts +8 -8
- package/dist/Types/MoveUndoneNotification.js +6 -12
- package/dist/Types/MoveUndoneNotification.js.map +1 -1
- package/dist/Types/Player.d.ts +13 -13
- package/dist/Types/Player.js +1 -2
- package/dist/Types/PlayerQuitReason.d.ts +4 -4
- package/dist/Types/PlayerQuitReason.js +5 -8
- package/dist/Types/PlayerQuitReason.js.map +1 -1
- package/dist/Types/ProxyGameData.d.ts +13 -13
- package/dist/Types/ProxyGameData.js +1 -2
- package/dist/Types/Tournament.d.ts +4 -4
- package/dist/Types/Tournament.js +1 -2
- package/dist/Types/index.d.ts +12 -12
- package/dist/Types/index.js +12 -28
- package/dist/Types/index.js.map +1 -1
- package/dist/User/User.d.ts +6 -6
- package/dist/User/User.js +1 -2
- package/dist/User/index.d.ts +2 -2
- package/dist/User/index.js +2 -18
- package/dist/User/index.js.map +1 -1
- package/dist/User/useMe.d.ts +4 -4
- package/dist/User/useMe.js +10 -21
- package/dist/User/useMe.js.map +1 -1
- package/dist/animations/Animation.d.ts +6 -6
- package/dist/animations/Animation.js +1 -2
- package/dist/animations/AnimationContext.d.ts +8 -8
- package/dist/animations/AnimationContext.js +1 -2
- package/dist/animations/AnimationState.d.ts +6 -6
- package/dist/animations/AnimationState.js +1 -2
- package/dist/animations/AnimationStep.d.ts +6 -6
- package/dist/animations/AnimationStep.js +7 -10
- package/dist/animations/AnimationStep.js.map +1 -1
- package/dist/animations/Animations.d.ts +8 -8
- package/dist/animations/Animations.js +15 -22
- package/dist/animations/Animations.js.map +1 -1
- package/dist/animations/AnimationsListener.d.ts +6 -0
- package/dist/animations/AnimationsListener.js +54 -0
- package/dist/animations/AnimationsListener.js.map +1 -0
- package/dist/animations/AnimationsListenerCreator.d.ts +2 -4
- package/dist/animations/AnimationsListenerCreator.js +40 -50
- package/dist/animations/AnimationsListenerCreator.js.map +1 -1
- package/dist/animations/animationMiddleware.d.ts +4 -0
- package/dist/animations/animationMiddleware.js +50 -0
- package/dist/animations/animationMiddleware.js.map +1 -0
- package/dist/animations/index.d.ts +5 -6
- package/dist/animations/index.js +5 -22
- package/dist/animations/index.js.map +1 -1
- package/dist/api/Client/GameClientAPI.d.ts +24 -24
- package/dist/api/Client/GameClientAPI.js +116 -165
- package/dist/api/Client/GameClientAPI.js.map +1 -1
- package/dist/api/Client/GameNotificationsListener.d.ts +5 -5
- package/dist/api/Client/GameNotificationsListener.js +62 -113
- package/dist/api/Client/GameNotificationsListener.js.map +1 -1
- package/dist/api/Client/RemoteGameLoader.d.ts +4 -5
- package/dist/api/Client/RemoteGameLoader.js +66 -62
- package/dist/api/Client/RemoteGameLoader.js.map +1 -1
- package/dist/api/Client/RemoteGameProvider.d.ts +7 -7
- package/dist/api/Client/RemoteGameProvider.js +19 -70
- package/dist/api/Client/RemoteGameProvider.js.map +1 -1
- package/dist/api/Client/apollo-client.d.ts +2 -2
- package/dist/api/Client/apollo-client.js +40 -58
- package/dist/api/Client/apollo-client.js.map +1 -1
- package/dist/api/Client/index.d.ts +4 -3
- package/dist/api/Client/index.js +4 -19
- package/dist/api/Client/index.js.map +1 -1
- package/dist/api/Client/pusher.d.ts +2 -0
- package/dist/api/Client/pusher.js +9 -0
- package/dist/api/Client/pusher.js.map +1 -0
- package/dist/api/GameAPI.d.ts +10 -10
- package/dist/api/GameAPI.js +1 -2
- package/dist/api/Local/ConsoleTools.d.ts +25 -25
- package/dist/api/Local/ConsoleTools.js +78 -86
- package/dist/api/Local/ConsoleTools.js.map +1 -1
- package/dist/api/Local/GameLocalAPI.d.ts +44 -44
- package/dist/api/Local/GameLocalAPI.js +442 -540
- package/dist/api/Local/GameLocalAPI.js.map +1 -1
- package/dist/api/Local/LocalGameProvider.d.ts +15 -15
- package/dist/api/Local/LocalGameProvider.js +18 -58
- package/dist/api/Local/LocalGameProvider.js.map +1 -1
- package/dist/api/Local/index.d.ts +1 -1
- package/dist/api/Local/index.js +1 -17
- package/dist/api/Local/index.js.map +1 -1
- package/dist/api/index.d.ts +2 -2
- package/dist/api/index.js +2 -18
- package/dist/api/index.js.map +1 -1
- package/dist/index.d.ts +16 -18
- package/dist/index.js +16 -36
- package/dist/index.js.map +1 -1
- package/dist/util/ArrayUtil.d.ts +2 -2
- package/dist/util/ArrayUtil.js +16 -21
- package/dist/util/ArrayUtil.js.map +1 -1
- package/package.json +66 -65
- package/dist/Actions/ActionType.d.ts +0 -3
- package/dist/Actions/ActionType.js +0 -8
- package/dist/Actions/ActionType.js.map +0 -1
- package/dist/Scoring/ScoringDescription.d.ts +0 -8
- package/dist/Scoring/ScoringDescription.js +0 -3
- package/dist/Scoring/ScoringDescription.js.map +0 -1
- package/dist/Scoring/index.d.ts +0 -1
- package/dist/Scoring/index.js +0 -18
- package/dist/Scoring/index.js.map +0 -1
- package/dist/util/TimeUtil.d.ts +0 -2
- package/dist/util/TimeUtil.js +0 -27
- package/dist/util/TimeUtil.js.map +0 -1
|
@@ -1,526 +1,463 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
function
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
draft.
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
if (
|
|
324
|
-
draft.
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
function refreshLegalMoves(draft) {
|
|
466
|
-
if (draft.playerId !== undefined) {
|
|
467
|
-
var rules = new GameRules(draft.state, draft.client);
|
|
468
|
-
draft.legalMoves = (0, immer_1.castDraft)(rules.getLegalMoves(draft.playerId));
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
function animateUndoneAction(action, draft, step) {
|
|
472
|
-
if (step === void 0) { step = animations_1.AnimationStep.BEFORE_UNDO; }
|
|
473
|
-
var move = (0, DisplayedAction_1.getAnimatedMove)(action, step);
|
|
474
|
-
var duration = animations.getDuration(move, getAnimationContext(action, draft, step)) / draft.animationsSpeed;
|
|
475
|
-
if (duration > 0) {
|
|
476
|
-
action.animation = { id: draft.animationIncrement++, duration: duration, step: step };
|
|
477
|
-
}
|
|
478
|
-
else if (step === animations_1.AnimationStep.BEFORE_UNDO) {
|
|
479
|
-
undoNextMove(action, draft);
|
|
480
|
-
}
|
|
481
|
-
else if (action.played > 0) {
|
|
482
|
-
animateUndoneAction(action, draft);
|
|
483
|
-
}
|
|
484
|
-
else {
|
|
485
|
-
refreshLegalMoves(draft);
|
|
486
|
-
if (!action.cancelPending) {
|
|
487
|
-
draft.actions.splice(draft.actions.indexOf(action), 1);
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
function getAnimationContext(action, draft, step) {
|
|
492
|
-
return __assign(__assign({}, context), { action: action, game: draft.state, playerId: draft.playerId, step: step });
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
exports.gameReducer = gameReducer;
|
|
496
|
-
function getGameAfterAnimations(state, Rules) {
|
|
497
|
-
if (!state.actions || !state.setup) {
|
|
498
|
-
throw new Error('Cannot play move before game history is loaded');
|
|
499
|
-
}
|
|
500
|
-
if (state.actions.some(function (action) { return action.animation || action.cancelled; })) {
|
|
501
|
-
var rules_2 = new Rules(JSON.parse(JSON.stringify(state.setup)), state.client);
|
|
502
|
-
var actionsToReplay = state.actions.filter(function (action) { return !action.delayed && !action.cancelled; });
|
|
503
|
-
actionsToReplay.forEach(function (action) { return replayAction(rules_2, action); });
|
|
504
|
-
return rules_2;
|
|
505
|
-
}
|
|
506
|
-
else {
|
|
507
|
-
return new Rules(JSON.parse(JSON.stringify(state.state)), { player: state.playerId });
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
exports.getGameAfterAnimations = getGameAfterAnimations;
|
|
511
|
-
var estimatedLatency = 100;
|
|
512
|
-
function approximateTimeDelta(serverTime, clientTimeDelta) {
|
|
513
|
-
return Math.min(serverTime + estimatedLatency - new Date().getTime(), clientTimeDelta || Infinity);
|
|
514
|
-
}
|
|
515
|
-
function replayActions(rules, actions, previousState) {
|
|
516
|
-
actions.forEach(function (action) { return replayAction(rules, action); });
|
|
517
|
-
if ((0, rules_api_1.hasUndo)(rules) && rules.restoreTransientState)
|
|
518
|
-
rules.restoreTransientState(previousState);
|
|
519
|
-
}
|
|
520
|
-
exports.replayActions = replayActions;
|
|
521
|
-
function replayAction(rules, action) {
|
|
522
|
-
rules.play(JSON.parse(JSON.stringify(action.move)), { local: action.local, transient: action.transient });
|
|
523
|
-
action.consequences.forEach(function (move) { return rules.play(JSON.parse(JSON.stringify(move)), { local: action.local, transient: action.transient }); });
|
|
524
|
-
}
|
|
525
|
-
exports.replayAction = replayAction;
|
|
1
|
+
import { hasUndo, hasUnpredictableMoves, loopWithFuse } from '@gamepark/rules-api';
|
|
2
|
+
import { createReducer } from '@reduxjs/toolkit';
|
|
3
|
+
import assert from 'assert';
|
|
4
|
+
import { isEqual, merge } from 'es-toolkit';
|
|
5
|
+
import { uniqueId } from 'es-toolkit/compat';
|
|
6
|
+
import { castDraft } from 'immer';
|
|
7
|
+
import { clearFailures, giveUp, playMove, receiveNotifications, setAnimationsSpeed, setGameOver, undoMove } from '../Actions';
|
|
8
|
+
import { loadGameState } from '../Actions/loadGameState';
|
|
9
|
+
import { removePlayer } from '../Actions/removePlayer';
|
|
10
|
+
import { reportFailure } from '../Actions/reportFailure';
|
|
11
|
+
import { startAnimation } from '../Actions/startAnimation';
|
|
12
|
+
import { Animations, AnimationStep } from '../animations';
|
|
13
|
+
import { Failure } from '../Failure';
|
|
14
|
+
import { startLiveLog, stopLiveLog } from '../Log';
|
|
15
|
+
import { muteSounds, soundsMuted, unmuteSounds } from '../Sound';
|
|
16
|
+
import { isMovePlayedNotification, isMoveUndoneNotification } from '../Types';
|
|
17
|
+
import { findLastIndex, findLastItem } from '../util/ArrayUtil';
|
|
18
|
+
import { getAnimatedMove } from './DisplayedAction';
|
|
19
|
+
import { endAnimation } from './endAnimation';
|
|
20
|
+
export function gameReducer(context) {
|
|
21
|
+
const GameRules = context?.Rules;
|
|
22
|
+
const animations = context?.animations ?? new Animations();
|
|
23
|
+
const initialState = {
|
|
24
|
+
players: [], pendingNotifications: [], nextNotificationIndex: 0, legalMoves: [], failures: [],
|
|
25
|
+
animationIncrement: 0, animationsSpeed: 1,
|
|
26
|
+
soundsMuted: soundsMuted(), clientTimeDelta: 0, liveLogStopped: false
|
|
27
|
+
};
|
|
28
|
+
return createReducer(initialState, (builder) => {
|
|
29
|
+
builder.addCase(loadGameState, (draft, { payload }) => {
|
|
30
|
+
if (payload.serverTime) {
|
|
31
|
+
draft.clientTimeDelta = approximateTimeDelta(payload.serverTime, draft.clientTimeDelta);
|
|
32
|
+
}
|
|
33
|
+
draft.players = payload.players;
|
|
34
|
+
draft.options = payload.options;
|
|
35
|
+
draft.playerId = payload.playerId;
|
|
36
|
+
draft.state = payload.state;
|
|
37
|
+
if (payload.playerId !== undefined) {
|
|
38
|
+
draft.legalMoves = castDraft(new GameRules(payload.state).getLegalMoves(payload.playerId));
|
|
39
|
+
}
|
|
40
|
+
draft.setup = payload.setup;
|
|
41
|
+
draft.gameOver = !!payload.endDate;
|
|
42
|
+
draft.gameMode = payload.mode;
|
|
43
|
+
draft.tournament = payload.tournament;
|
|
44
|
+
draft.nextNotificationIndex = payload.notifications.length;
|
|
45
|
+
if (!payload.endDate) {
|
|
46
|
+
draft.client = { player: payload.playerId };
|
|
47
|
+
}
|
|
48
|
+
setActionsFromPastNotifications(draft, payload.notifications);
|
|
49
|
+
});
|
|
50
|
+
builder.addCase(receiveNotifications, (draft, { payload }) => {
|
|
51
|
+
if (payload.serverTime) {
|
|
52
|
+
draft.clientTimeDelta = approximateTimeDelta(payload.serverTime, draft.clientTimeDelta);
|
|
53
|
+
}
|
|
54
|
+
for (const player of draft.players) {
|
|
55
|
+
const newPlayerTime = payload.players.find(p => p.id === player.id)?.time;
|
|
56
|
+
player.time = newPlayerTime ?? player.time;
|
|
57
|
+
}
|
|
58
|
+
if (payload.notificationsIndex == 0 && !draft.actions) {
|
|
59
|
+
setActionsFromPastNotifications(draft, payload.notifications);
|
|
60
|
+
}
|
|
61
|
+
for (let i = Math.max(draft.nextNotificationIndex - payload.notificationsIndex, 0); i < payload.notifications.length; i++) {
|
|
62
|
+
draft.pendingNotifications.push({ ...payload.notifications[i], index: i + payload.notificationsIndex });
|
|
63
|
+
}
|
|
64
|
+
draft.pendingNotifications.sort((n1, n2) => n1.index - n2.index);
|
|
65
|
+
if (draft.state) {
|
|
66
|
+
applyPendingNotifications(draft);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
builder.addCase(playMove, (draft, { payload: { move, options } }) => {
|
|
70
|
+
if (!draft.state)
|
|
71
|
+
throw new Error('Cannot play move before game state is loaded');
|
|
72
|
+
if (!draft.actions)
|
|
73
|
+
throw new Error('Cannot play move before game history is loaded');
|
|
74
|
+
const transient = options?.transient;
|
|
75
|
+
const local = options?.local ?? transient;
|
|
76
|
+
if (draft.playerId === undefined && !local)
|
|
77
|
+
throw new Error('Spectators cannot play');
|
|
78
|
+
const action = {
|
|
79
|
+
id: 'local-' + uniqueId(),
|
|
80
|
+
playerId: draft.playerId,
|
|
81
|
+
move,
|
|
82
|
+
consequences: [],
|
|
83
|
+
played: 0,
|
|
84
|
+
pending: !local,
|
|
85
|
+
local,
|
|
86
|
+
transient
|
|
87
|
+
};
|
|
88
|
+
const rules = getGameAfterAnimations(draft, GameRules);
|
|
89
|
+
const isUnpredictable = (move) => hasUnpredictableMoves(rules) && rules.isUnpredictableMove(move, action.playerId);
|
|
90
|
+
if (!local && (options?.delayed || isUnpredictable(move))) {
|
|
91
|
+
action.delayed = true;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
action.consequences = [];
|
|
95
|
+
const pendingMoves = rules.play(JSON.parse(JSON.stringify(move)), { local, transient });
|
|
96
|
+
loopWithFuse(() => {
|
|
97
|
+
const move = pendingMoves.shift();
|
|
98
|
+
if (!move || isUnpredictable(move))
|
|
99
|
+
return false;
|
|
100
|
+
action.consequences.push(move);
|
|
101
|
+
pendingMoves.unshift(...rules.play(JSON.parse(JSON.stringify(move)), { local, transient }));
|
|
102
|
+
return true;
|
|
103
|
+
}, { errorFn: () => new Error(`Infinite loop detected while applying move consequences: ${JSON.stringify(action)})`) });
|
|
104
|
+
if (options?.skipAnimation) {
|
|
105
|
+
playNextMove(action, draft);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
animatePlayedAction(action, draft);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (!transient || action.animation) {
|
|
112
|
+
draft.actions.push(action);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
builder.addCase(undoMove, (draft, { payload: { actionId, delayed } }) => {
|
|
116
|
+
if (!draft.actions || !draft.setup || !draft.state) {
|
|
117
|
+
return console.error('Cannot undo before actions history is loaded');
|
|
118
|
+
}
|
|
119
|
+
const action = findLastItem(draft.actions, action => action.id === actionId);
|
|
120
|
+
if (!action)
|
|
121
|
+
return console.error(`Could not find action to undo with this id: ${actionId}`);
|
|
122
|
+
if (!action.local && draft.playerId === undefined) {
|
|
123
|
+
return console.error('Spectators cannot undo moves');
|
|
124
|
+
}
|
|
125
|
+
action.cancelled = true;
|
|
126
|
+
if (!action.local) {
|
|
127
|
+
action.cancelPending = true;
|
|
128
|
+
}
|
|
129
|
+
if (!action.local && (delayed || !new GameRules(draft.state, draft.client).isTurnToPlay(draft.playerId))) {
|
|
130
|
+
action.delayed = true;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
animateUndoneAction(action, draft);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
builder.addCase(reportFailure, (draft, { payload: reason }) => {
|
|
137
|
+
if (draft.actions) {
|
|
138
|
+
switch (reason) {
|
|
139
|
+
case Failure.UNDO_FORBIDDEN:
|
|
140
|
+
for (const action of draft.actions) {
|
|
141
|
+
if (action.cancelPending) {
|
|
142
|
+
action.cancelled = false;
|
|
143
|
+
action.cancelPending = false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
break;
|
|
147
|
+
default:
|
|
148
|
+
draft.actions = draft.actions.filter(action => !action.pending);
|
|
149
|
+
const rules = new GameRules(JSON.parse(JSON.stringify(draft.setup)), draft.client);
|
|
150
|
+
replayActions(rules, draft.actions, draft.state);
|
|
151
|
+
draft.state = rules.game;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
draft.failures.push(reason);
|
|
155
|
+
});
|
|
156
|
+
builder.addCase(clearFailures, (draft) => {
|
|
157
|
+
draft.failures = [];
|
|
158
|
+
});
|
|
159
|
+
builder.addCase(startAnimation, (draft, { payload: actionId }) => {
|
|
160
|
+
if (!draft.actions)
|
|
161
|
+
return;
|
|
162
|
+
const action = draft.actions.find(action => action.id === actionId);
|
|
163
|
+
if (action) {
|
|
164
|
+
animateAction(action, draft);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
builder.addCase(endAnimation, (draft, { payload: animationId }) => {
|
|
168
|
+
if (draft.actions) {
|
|
169
|
+
const action = draft.actions.find(action => action.animation?.id === animationId);
|
|
170
|
+
if (!action) {
|
|
171
|
+
return console.error('endAnimation action received but not animation found with provided id');
|
|
172
|
+
}
|
|
173
|
+
const step = action.animation?.step;
|
|
174
|
+
if (action.transient) {
|
|
175
|
+
draft.actions.splice(draft.actions.indexOf(action), 1);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
delete action.animation;
|
|
179
|
+
}
|
|
180
|
+
if (step === AnimationStep.BEFORE_MOVE) {
|
|
181
|
+
playNextMove(action, draft);
|
|
182
|
+
}
|
|
183
|
+
else if (step === AnimationStep.BEFORE_UNDO) {
|
|
184
|
+
undoNextMove(action, draft);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
refreshLegalMoves(draft);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
builder.addCase(setAnimationsSpeed, (draft, { payload: speed }) => {
|
|
192
|
+
draft.animationsSpeed = speed;
|
|
193
|
+
});
|
|
194
|
+
builder.addCase(giveUp, (draft) => {
|
|
195
|
+
draft.playerId = undefined;
|
|
196
|
+
});
|
|
197
|
+
builder.addCase(muteSounds, (draft) => {
|
|
198
|
+
draft.soundsMuted = true;
|
|
199
|
+
});
|
|
200
|
+
builder.addCase(unmuteSounds, (draft) => {
|
|
201
|
+
draft.soundsMuted = false;
|
|
202
|
+
});
|
|
203
|
+
builder.addCase(startLiveLog, (draft) => {
|
|
204
|
+
draft.liveLogStopped = false;
|
|
205
|
+
});
|
|
206
|
+
builder.addCase(stopLiveLog, (draft) => {
|
|
207
|
+
draft.liveLogStopped = true;
|
|
208
|
+
});
|
|
209
|
+
builder.addCase(removePlayer, (draft, { payload: { playerId, reason } }) => {
|
|
210
|
+
const player = draft.players.find(p => p.id === playerId);
|
|
211
|
+
if (player) {
|
|
212
|
+
player.quit = true;
|
|
213
|
+
player.quitReason = reason;
|
|
214
|
+
}
|
|
215
|
+
if (draft.playerId === playerId) {
|
|
216
|
+
delete draft.playerId;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
builder.addCase(setGameOver, (draft, { payload: players }) => {
|
|
220
|
+
draft.gameOver = true;
|
|
221
|
+
for (const player of draft.players) {
|
|
222
|
+
const newPlayerData = players.find(p => p.id === player.id) ?? {};
|
|
223
|
+
merge(player, newPlayerData);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
function playNextMove(action, draft) {
|
|
228
|
+
const consequenceIndex = action.played === 0 ? undefined : action.played - 1;
|
|
229
|
+
const move = consequenceIndex === undefined ? action.move : action.consequences[consequenceIndex];
|
|
230
|
+
const rules = new GameRules(draft.state, draft.client);
|
|
231
|
+
rules.play(JSON.parse(JSON.stringify(move)), { local: action.local, transient: action.transient });
|
|
232
|
+
action.played++;
|
|
233
|
+
if (!action.local && !action.transient && !action.pending) {
|
|
234
|
+
draft.playedMoves.push({ actionId: action.id, move, consequenceIndex });
|
|
235
|
+
}
|
|
236
|
+
animatePlayedAction(action, draft, AnimationStep.AFTER_MOVE);
|
|
237
|
+
}
|
|
238
|
+
function undoNextMove(action, draft) {
|
|
239
|
+
const rules = new GameRules(JSON.parse(JSON.stringify(draft.setup)), draft.client);
|
|
240
|
+
action.played--;
|
|
241
|
+
const actionsPlayed = draft.actions.filter(action => action.played > 0)
|
|
242
|
+
.map(action => ({
|
|
243
|
+
...action,
|
|
244
|
+
consequences: action.consequences.slice(0, action.played - 1)
|
|
245
|
+
}));
|
|
246
|
+
replayActions(rules, actionsPlayed, draft.state);
|
|
247
|
+
draft.state = rules.game;
|
|
248
|
+
animateUndoneAction(action, draft, AnimationStep.AFTER_UNDO);
|
|
249
|
+
}
|
|
250
|
+
function setActionsFromPastNotifications(draft, notifications) {
|
|
251
|
+
draft.actions = [];
|
|
252
|
+
draft.playedMoves = [];
|
|
253
|
+
for (let i = 0; i < draft.nextNotificationIndex; i++) {
|
|
254
|
+
const notification = notifications[i];
|
|
255
|
+
if (isMovePlayedNotification(notification)) {
|
|
256
|
+
const action = {
|
|
257
|
+
id: notification.actionId ?? undefined,
|
|
258
|
+
playerId: notification.playerId, move: notification.moveView,
|
|
259
|
+
consequences: notification.consequences,
|
|
260
|
+
played: 1 + notification.consequences.length
|
|
261
|
+
};
|
|
262
|
+
draft.actions.push(action);
|
|
263
|
+
draft.playedMoves.push({ actionId: action.id, move: action.move });
|
|
264
|
+
for (let consequenceIndex = 0; consequenceIndex < action.consequences.length; consequenceIndex++) {
|
|
265
|
+
const consequence = action.consequences[consequenceIndex];
|
|
266
|
+
draft.playedMoves.push({ actionId: action.id, move: consequence, consequenceIndex });
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
else if (isMoveUndoneNotification(notification)) {
|
|
270
|
+
const index = notification.actionId ? findLastIndex(draft.actions, action => action.id === notification.actionId) : notification.moveUndone;
|
|
271
|
+
if (index !== -1) {
|
|
272
|
+
draft.actions.splice(index, 1);
|
|
273
|
+
}
|
|
274
|
+
draft.playedMoves = draft.playedMoves.filter((playedMove) => playedMove.actionId !== notification.actionId);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function applyPendingNotifications(draft) {
|
|
279
|
+
if (!draft.actions) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
while (draft.pendingNotifications.length && draft.pendingNotifications[0].index <= draft.nextNotificationIndex) {
|
|
283
|
+
const notification = draft.pendingNotifications.shift();
|
|
284
|
+
if (notification.index < draft.nextNotificationIndex) {
|
|
285
|
+
console.info('A notification was received twice: ' + JSON.stringify(notification));
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
draft.nextNotificationIndex++;
|
|
289
|
+
applyNotification(draft, notification);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function applyNotification(draft, notification) {
|
|
294
|
+
if (isMovePlayedNotification(notification)) {
|
|
295
|
+
applyMovePlayedNotification(draft, notification);
|
|
296
|
+
}
|
|
297
|
+
else if (isMoveUndoneNotification(notification)) {
|
|
298
|
+
applyMoveUndoneNotification(draft, notification);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
function applyMovePlayedNotification(draft, notification) {
|
|
302
|
+
assert(draft.actions !== undefined, 'Cannot apply a notification before action history is loaded');
|
|
303
|
+
let action;
|
|
304
|
+
if (notification.playerId === draft.playerId) {
|
|
305
|
+
action = draft.actions.find(action => action.pending && action.playerId == notification.playerId);
|
|
306
|
+
}
|
|
307
|
+
if (action) {
|
|
308
|
+
action.id = notification.actionId ?? undefined;
|
|
309
|
+
action.pending = false;
|
|
310
|
+
if (action.delayed) {
|
|
311
|
+
action.move = notification.moveView;
|
|
312
|
+
action.consequences = notification.consequences;
|
|
313
|
+
delete action.delayed;
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
if (action.played !== 0) {
|
|
317
|
+
draft.playedMoves.push({ actionId: action.id, move: action.move });
|
|
318
|
+
for (let consequenceIndex = 0; consequenceIndex < action.played - 1; consequenceIndex++) {
|
|
319
|
+
const consequence = action.consequences[consequenceIndex];
|
|
320
|
+
draft.playedMoves.push({ actionId: action.id, move: consequence, consequenceIndex });
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (!isEqual(JSON.parse(JSON.stringify(action.move)), JSON.parse(JSON.stringify(notification.moveView)))) {
|
|
324
|
+
const rules = new GameRules(draft.state);
|
|
325
|
+
if (hasUnpredictableMoves(rules) && rules.canIgnoreServerDifference
|
|
326
|
+
&& rules.canIgnoreServerDifference(action.move, notification.moveView)) {
|
|
327
|
+
action.move = notification.moveView;
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
console.error('An action was played and executed immediately:', JSON.parse(JSON.stringify(action.move)), ', but the notifications does not contain the same data:', JSON.parse(JSON.stringify(notification.moveView)), '(use the "delayed" parameter to postpone execution if the outcome cannot be anticipated).');
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
if (action.consequences.length > notification.consequences.length) {
|
|
334
|
+
console.error('The server returned less consequences that what was played locally:', action.consequences, notification.consequences);
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
for (let i = 0; i < action.consequences.length; i++) {
|
|
338
|
+
if (!isEqual(JSON.parse(JSON.stringify(action.consequences[i])), JSON.parse(JSON.stringify(notification.consequences[i])))) {
|
|
339
|
+
const rules = new GameRules(draft.state);
|
|
340
|
+
if (hasUnpredictableMoves(rules) && rules.canIgnoreServerDifference
|
|
341
|
+
&& rules.canIgnoreServerDifference(action.consequences[i], notification.consequences[i])) {
|
|
342
|
+
action.consequences[i] = notification.consequences[i];
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
console.error(`Consequence #${i} was played on the client, but the server returned a different consequence:`, JSON.parse(JSON.stringify(action.consequences[i])), notification.consequences[i]);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
action.consequences.push(...notification.consequences.slice(action.consequences.length));
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
draft.actions.splice(findLastIndex(draft.actions, action => !action.pending) + 1, 0, {
|
|
355
|
+
id: notification.actionId ?? undefined,
|
|
356
|
+
playerId: notification.playerId,
|
|
357
|
+
move: notification.moveView,
|
|
358
|
+
consequences: notification.consequences,
|
|
359
|
+
played: 0
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
function applyMoveUndoneNotification(draft, notification) {
|
|
364
|
+
assert(draft.actions !== undefined, 'Cannot apply a notification before action history is loaded');
|
|
365
|
+
const index = findLastIndex(draft.actions, action => action.id === notification.actionId);
|
|
366
|
+
if (index === -1)
|
|
367
|
+
return console.error(`Received move undone notification, but action ${notification.actionId} is unknown`);
|
|
368
|
+
const cancelledAction = draft.actions[index];
|
|
369
|
+
if (!cancelledAction.played && !cancelledAction.animation) {
|
|
370
|
+
draft.actions.splice(index, 1);
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
cancelledAction.cancelled = true;
|
|
374
|
+
delete cancelledAction.cancelPending;
|
|
375
|
+
delete cancelledAction.delayed;
|
|
376
|
+
}
|
|
377
|
+
draft.playedMoves = draft.playedMoves.filter((move) => move.actionId !== notification.actionId);
|
|
378
|
+
}
|
|
379
|
+
function animateAction(action, draft) {
|
|
380
|
+
if (!action.cancelled) {
|
|
381
|
+
animatePlayedAction(action, draft);
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
animateUndoneAction(action, draft);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
function animatePlayedAction(action, draft, step = AnimationStep.BEFORE_MOVE) {
|
|
388
|
+
if (action.activePlayers === undefined) {
|
|
389
|
+
const rules = new GameRules(draft.state, draft.client);
|
|
390
|
+
action.activePlayers = draft.players.map(p => p.id).filter(p => rules.isTurnToPlay(p));
|
|
391
|
+
}
|
|
392
|
+
const move = getAnimatedMove(action, step);
|
|
393
|
+
const duration = animations.getDuration(move, getAnimationContext(action, draft, step)) / draft.animationsSpeed;
|
|
394
|
+
if (duration > 0) {
|
|
395
|
+
action.animation = { id: draft.animationIncrement++, duration, step };
|
|
396
|
+
}
|
|
397
|
+
else if (step === AnimationStep.BEFORE_MOVE) {
|
|
398
|
+
playNextMove(action, draft);
|
|
399
|
+
}
|
|
400
|
+
else if (action.played <= action.consequences.length) {
|
|
401
|
+
animatePlayedAction(action, draft);
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
refreshLegalMoves(draft);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
function refreshLegalMoves(draft) {
|
|
408
|
+
if (draft.playerId !== undefined) {
|
|
409
|
+
const rules = new GameRules(draft.state, draft.client);
|
|
410
|
+
draft.legalMoves = castDraft(rules.getLegalMoves(draft.playerId));
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function animateUndoneAction(action, draft, step = AnimationStep.BEFORE_UNDO) {
|
|
414
|
+
const move = getAnimatedMove(action, step);
|
|
415
|
+
const duration = animations.getDuration(move, getAnimationContext(action, draft, step)) / draft.animationsSpeed;
|
|
416
|
+
if (duration > 0) {
|
|
417
|
+
action.animation = { id: draft.animationIncrement++, duration, step };
|
|
418
|
+
}
|
|
419
|
+
else if (step === AnimationStep.BEFORE_UNDO) {
|
|
420
|
+
undoNextMove(action, draft);
|
|
421
|
+
}
|
|
422
|
+
else if (action.played > 0) {
|
|
423
|
+
animateUndoneAction(action, draft);
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
refreshLegalMoves(draft);
|
|
427
|
+
if (!action.cancelPending) {
|
|
428
|
+
draft.actions.splice(draft.actions.indexOf(action), 1);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
function getAnimationContext(action, draft, step) {
|
|
433
|
+
return { ...context, action: action, game: draft.state, playerId: draft.playerId, step };
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
export function getGameAfterAnimations(state, Rules) {
|
|
437
|
+
if (!state.actions || !state.setup) {
|
|
438
|
+
throw new Error('Cannot play move before game history is loaded');
|
|
439
|
+
}
|
|
440
|
+
if (state.actions.some(action => action.animation || action.cancelled)) {
|
|
441
|
+
const rules = new Rules(JSON.parse(JSON.stringify(state.setup)), state.client);
|
|
442
|
+
const actionsToReplay = state.actions.filter(action => !action.delayed && !action.cancelled);
|
|
443
|
+
actionsToReplay.forEach(action => replayAction(rules, action));
|
|
444
|
+
return rules;
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
return new Rules(JSON.parse(JSON.stringify(state.state)), { player: state.playerId });
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
const estimatedLatency = 100;
|
|
451
|
+
function approximateTimeDelta(serverTime, clientTimeDelta) {
|
|
452
|
+
return Math.min(serverTime + estimatedLatency - new Date().getTime(), clientTimeDelta || Infinity);
|
|
453
|
+
}
|
|
454
|
+
export function replayActions(rules, actions, previousState) {
|
|
455
|
+
actions.forEach(action => replayAction(rules, action));
|
|
456
|
+
if (hasUndo(rules) && rules.restoreTransientState)
|
|
457
|
+
rules.restoreTransientState(previousState);
|
|
458
|
+
}
|
|
459
|
+
export function replayAction(rules, action) {
|
|
460
|
+
rules.play(JSON.parse(JSON.stringify(action.move)), { local: action.local, transient: action.transient });
|
|
461
|
+
action.consequences.forEach(move => rules.play(JSON.parse(JSON.stringify(move)), { local: action.local, transient: action.transient }));
|
|
462
|
+
}
|
|
526
463
|
//# sourceMappingURL=gameReducer.js.map
|