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