@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,541 +1,443 @@
|
|
|
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
|
-
if (
|
|
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
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
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
|
-
localStorage.setItem(
|
|
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
|
-
return [2, this.playActions(player.id, [expectedMove_1])];
|
|
444
|
-
}
|
|
445
|
-
else {
|
|
446
|
-
console.error('Tutorial expects a move that no player can play: ', expectedMove_1);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
if (!(localStore.monkeyOpponents && !this.aiProcessing)) return [3, 3];
|
|
451
|
-
player = localStore.players.find(function (player) { return player.id !== localStore.playerId && rules.isTurnToPlay(player.id); });
|
|
452
|
-
if (!player) return [3, 2];
|
|
453
|
-
this.aiProcessing = true;
|
|
454
|
-
return [4, this.getAI(player.id)(rules.game, player.id)];
|
|
455
|
-
case 1:
|
|
456
|
-
moves = _b.sent();
|
|
457
|
-
this.aiProcessing = false;
|
|
458
|
-
if (moves.length) {
|
|
459
|
-
this.playActions(player.id, moves);
|
|
460
|
-
this.autoPlayersCounter++;
|
|
461
|
-
}
|
|
462
|
-
else {
|
|
463
|
-
console.error("Player ".concat(player.id, " is active but did not return any move to play!"));
|
|
464
|
-
}
|
|
465
|
-
return [3, 3];
|
|
466
|
-
case 2:
|
|
467
|
-
if (localStore.playerId === undefined || !rules.isTurnToPlay(localStore.playerId)) {
|
|
468
|
-
console.error('Game is not over but there is no active player!');
|
|
469
|
-
}
|
|
470
|
-
_b.label = 3;
|
|
471
|
-
case 3: return [2];
|
|
472
|
-
}
|
|
473
|
-
});
|
|
474
|
-
});
|
|
475
|
-
};
|
|
476
|
-
GameLocalAPI.prototype.getAI = function (playerId) {
|
|
477
|
-
if (this.ai)
|
|
478
|
-
return this.ai;
|
|
479
|
-
var bot = new rules_api_1.RandomBot(this.Rules, playerId);
|
|
480
|
-
return function (game) { return Promise.resolve(bot.run(game)); };
|
|
481
|
-
};
|
|
482
|
-
GameLocalAPI.prototype.setPlayerName = function (name, playerId) {
|
|
483
|
-
var localStore = this.getLocalStore();
|
|
484
|
-
var player = localStore.players.find(function (player) { return player.id === (playerId || localStore.playerId); });
|
|
485
|
-
if (!player) {
|
|
486
|
-
throw new Error('Player not found');
|
|
487
|
-
}
|
|
488
|
-
player.name = name;
|
|
489
|
-
localStorage.setItem(this.storage, JSON.stringify(localStore));
|
|
490
|
-
};
|
|
491
|
-
GameLocalAPI.prototype.setAnimationsSpeed = function (speed) {
|
|
492
|
-
if (speed === void 0) { speed = 1; }
|
|
493
|
-
this.dispatch((0, Actions_1.setAnimationsSpeed)(speed));
|
|
494
|
-
localStorage.setItem('animationsSpeed', speed.toString());
|
|
495
|
-
};
|
|
496
|
-
GameLocalAPI.prototype.eject = function () {
|
|
497
|
-
};
|
|
498
|
-
GameLocalAPI.prototype.giveUp = function () {
|
|
499
|
-
};
|
|
500
|
-
GameLocalAPI.prototype.playTutorialMoves = function (quantity) {
|
|
501
|
-
var _this = this;
|
|
502
|
-
if (quantity) {
|
|
503
|
-
this.tutorialMovesToPlay += quantity;
|
|
504
|
-
this.autoPlayersCounter = 0;
|
|
505
|
-
setTimeout(function () { return _this.runAutoPlayers(); }, 100 + Math.random() * 100);
|
|
506
|
-
}
|
|
507
|
-
else {
|
|
508
|
-
this.tutorialMovesToPlay = 0;
|
|
509
|
-
}
|
|
510
|
-
};
|
|
511
|
-
return GameLocalAPI;
|
|
512
|
-
}());
|
|
513
|
-
exports.GameLocalAPI = GameLocalAPI;
|
|
514
|
-
function mimicDataTransfer(data, options) {
|
|
515
|
-
if (options === void 0) { options = {}; }
|
|
516
|
-
var _a = options.sizeWarn, sizeWarn = _a === void 0 ? 0 : _a, _b = options.duration, duration = _b === void 0 ? 100 : _b;
|
|
517
|
-
var stringData = JSON.stringify(data !== null && data !== void 0 ? data : null);
|
|
518
|
-
data = JSON.parse(stringData);
|
|
519
|
-
if (sizeWarn && stringData) {
|
|
520
|
-
if (stringData.length > sizeWarn) {
|
|
521
|
-
console.warn("Notification payload of ".concat(stringData.length, " bytes exceeds ").concat(sizeWarn, " bytes, which can cause extra http requests."), stringData);
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
return new Promise(function (resolve) { return setTimeout(function () { return resolve(data); }, duration); });
|
|
525
|
-
}
|
|
526
|
-
function verifyNonMutation(operation, getState, message) {
|
|
527
|
-
var initialState = JSON.stringify(getState());
|
|
528
|
-
var result = operation();
|
|
529
|
-
var finalState = JSON.stringify(getState());
|
|
530
|
-
(0, assert_1.default)(initialState === finalState, message);
|
|
531
|
-
return result;
|
|
532
|
-
}
|
|
533
|
-
function sortObjectKeys(value) {
|
|
534
|
-
if (typeof value !== 'object' || value === null)
|
|
535
|
-
return value;
|
|
536
|
-
return Object.keys(value).sort().reduce(function (obj, key) {
|
|
537
|
-
obj[key] = value[key];
|
|
538
|
-
return obj;
|
|
539
|
-
}, {});
|
|
540
|
-
}
|
|
1
|
+
import { applyAutomaticMoves, generatePlayersOption, getGameView, getMoveView, hasHiddenInformation, hasSecretInformation, hasUndo, isSecretAction, isWithPlayerIdOptions, isWithPlayerOptions, playAction, playActionWithViews, RandomBot, replayActions } from '@gamepark/rules-api';
|
|
2
|
+
import assert from 'assert';
|
|
3
|
+
import { receiveNotifications, setAnimationsSpeed, setGameOver } from '../../Actions';
|
|
4
|
+
import { loadGameState } from '../../Actions/loadGameState';
|
|
5
|
+
import { reportFailure } from '../../Actions/reportFailure';
|
|
6
|
+
import { Failure } from '../../Failure';
|
|
7
|
+
import { GameMode, GameSpeed, movePlayedNotification, moveUndoneNotification } from '../../Types';
|
|
8
|
+
import { findLastIndex } from '../../util/ArrayUtil';
|
|
9
|
+
export class GameLocalAPI {
|
|
10
|
+
storage;
|
|
11
|
+
gameSetup;
|
|
12
|
+
Rules;
|
|
13
|
+
ClientRules;
|
|
14
|
+
optionsSpec;
|
|
15
|
+
ai;
|
|
16
|
+
tutorial;
|
|
17
|
+
dispatch;
|
|
18
|
+
lastActionId = 0;
|
|
19
|
+
notificationsCount = 0;
|
|
20
|
+
autoPlayersCounter = 0;
|
|
21
|
+
aiProcessing = false;
|
|
22
|
+
tutorialMovesToPlay = 0;
|
|
23
|
+
constructor({ Rules, ServerRules, GameSetup, ai, game, storage, optionsSpec, tutorial }) {
|
|
24
|
+
this.storage = storage ?? game;
|
|
25
|
+
this.Rules = ServerRules ?? Rules;
|
|
26
|
+
this.gameSetup = new GameSetup();
|
|
27
|
+
this.ClientRules = Rules;
|
|
28
|
+
this.optionsSpec = optionsSpec;
|
|
29
|
+
this.ai = ai;
|
|
30
|
+
this.tutorial = tutorial;
|
|
31
|
+
}
|
|
32
|
+
init(dispatch) {
|
|
33
|
+
this.dispatch = dispatch;
|
|
34
|
+
const animationsSpeed = parseFloat(localStorage.getItem('animationsSpeed') || '1');
|
|
35
|
+
this.dispatch(setAnimationsSpeed(animationsSpeed));
|
|
36
|
+
const data = this.initLocalStore();
|
|
37
|
+
const visibleActions = data.actions.filter(action => !isSecretAction(action) || !action.secrets.some(secret => secret.recipient === data.playerId));
|
|
38
|
+
const notifications = this.getNotifications(data);
|
|
39
|
+
this.notificationsCount = notifications.length;
|
|
40
|
+
const dataToTransfer = {
|
|
41
|
+
myPlayerId: data.playerId, setup: data.setup, state: data.state, notifications,
|
|
42
|
+
players: data.players, options: data.options ?? { speed: GameSpeed.Disabled, maxSpareTime: 0, maxExceedTime: 0 },
|
|
43
|
+
mode: data.tutorial ? GameMode.TUTORIAL : GameMode.FRIENDLY, notificationsChannel: '', endDate: null, tournament: null
|
|
44
|
+
};
|
|
45
|
+
const initialGame = new this.Rules(JSON.parse(JSON.stringify(data.setup)));
|
|
46
|
+
const rules = new this.Rules(data.state);
|
|
47
|
+
const isOver = rules.isOver(data.players.map(p => p.id));
|
|
48
|
+
if (isOver) {
|
|
49
|
+
dataToTransfer.endDate = new Date();
|
|
50
|
+
}
|
|
51
|
+
if (hasHiddenInformation(initialGame) && !isOver) {
|
|
52
|
+
dataToTransfer.setup = verifyNonMutation(() => getGameView(initialGame, data.playerId), () => initialGame.game, 'getView must not change the game state');
|
|
53
|
+
if (visibleActions.length < data.actions.length) {
|
|
54
|
+
dataToTransfer.setup = JSON.parse(JSON.stringify(dataToTransfer.setup));
|
|
55
|
+
replayActions(initialGame, visibleActions);
|
|
56
|
+
dataToTransfer.state = verifyNonMutation(() => getGameView(initialGame, data.playerId), () => initialGame.game, 'getView must not change the game state');
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
if (hasHiddenInformation(rules)) {
|
|
60
|
+
dataToTransfer.state = verifyNonMutation(() => getGameView(rules, data.playerId), () => rules.game, 'getView must not change the game state');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
mimicDataTransfer(dataToTransfer).then(gameData => this.dispatch(loadGameState({
|
|
65
|
+
...(gameData), playerId: gameData.myPlayerId ?? undefined, serverTime: undefined, endDate: gameData.endDate ?? undefined,
|
|
66
|
+
tournament: gameData.tournament ?? undefined
|
|
67
|
+
})));
|
|
68
|
+
}
|
|
69
|
+
initLocalStore() {
|
|
70
|
+
const localStore = localStorage.getItem(this.storage);
|
|
71
|
+
if (localStore) {
|
|
72
|
+
const data = JSON.parse(localStore);
|
|
73
|
+
if (process.env.NODE_ENV !== 'development' && this.tutorial && !data.tutorial) {
|
|
74
|
+
return this.newTutorial();
|
|
75
|
+
}
|
|
76
|
+
if (this.tutorial?.version && data.tutorial && data.tutorial !== this.tutorial.version) {
|
|
77
|
+
return this.newTutorial();
|
|
78
|
+
}
|
|
79
|
+
if (data.actions.length > 0 && !data.actions[0].id) {
|
|
80
|
+
data.actions.forEach((action, index) => {
|
|
81
|
+
if (!action.id)
|
|
82
|
+
action.id = index.toString();
|
|
83
|
+
});
|
|
84
|
+
localStorage.setItem(this.storage, JSON.stringify(data));
|
|
85
|
+
}
|
|
86
|
+
if (data.actions.length > 0) {
|
|
87
|
+
const lastActionId = parseInt(data.actions[data.actions.length - 1].id);
|
|
88
|
+
if (!isNaN(lastActionId)) {
|
|
89
|
+
this.lastActionId = lastActionId;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return data;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
return this.tutorial ? this.newTutorial() : this.newGame();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
getNotifications(data) {
|
|
99
|
+
const rules = new this.Rules(JSON.parse(JSON.stringify(data.setup)));
|
|
100
|
+
const actions = data.actions.filter(action => !isSecretAction(action) || !action.secrets.some(secret => secret.recipient === data.playerId));
|
|
101
|
+
if (hasHiddenInformation(rules) && !new this.Rules(data.state).isOver(data.players.map(p => p.id))) {
|
|
102
|
+
const clientGame = new this.ClientRules(JSON.parse(JSON.stringify(getGameView(rules, data.playerId))), { player: data.playerId });
|
|
103
|
+
const notifications = [];
|
|
104
|
+
for (const action of actions) {
|
|
105
|
+
const moveView = verifyNonMutation(() => getMoveView(rules, JSON.parse(JSON.stringify(action.move)), data.playerId), () => rules.game, 'getMoveView must not change the state of the game');
|
|
106
|
+
clientGame.play(JSON.parse(JSON.stringify(moveView)));
|
|
107
|
+
rules.play(JSON.parse(JSON.stringify(action.move)));
|
|
108
|
+
const consequences = [];
|
|
109
|
+
for (const move of action.consequences) {
|
|
110
|
+
const moveView = verifyNonMutation(() => getMoveView(rules, JSON.parse(JSON.stringify(move)), data.playerId), () => rules.game, 'getMoveView must not change the state of the game');
|
|
111
|
+
consequences.push(moveView);
|
|
112
|
+
clientGame.play(JSON.parse(JSON.stringify(moveView)));
|
|
113
|
+
rules.play(JSON.parse(JSON.stringify(move)));
|
|
114
|
+
}
|
|
115
|
+
notifications.push(movePlayedNotification({ ...action, move: moveView, consequences }));
|
|
116
|
+
}
|
|
117
|
+
const serverGameView = JSON.parse(JSON.stringify(getGameView(rules, data.playerId)), (_, value) => sortObjectKeys(value));
|
|
118
|
+
const clientGameView = JSON.parse(JSON.stringify(clientGame.game), (_, value) => sortObjectKeys(value));
|
|
119
|
+
try {
|
|
120
|
+
assert.deepStrictEqual(serverGameView, clientGameView);
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
console.error('Something is wrong with rules.getView or rules.getMoveView implementation: the view is not the same when moveViews are applied');
|
|
124
|
+
console.error('Game view when moves are applied then getView is executed:', serverGameView);
|
|
125
|
+
console.error('Game view when moves views are applied from the setup state:', clientGameView);
|
|
126
|
+
console.error('If not fixed, there can be bugs especially with the UNDO features.');
|
|
127
|
+
}
|
|
128
|
+
return notifications;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
return actions.map(action => movePlayedNotification(action));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
newTutorial() {
|
|
135
|
+
if (!this.tutorial) {
|
|
136
|
+
throw new Error('Pass a Tutorial in the options of createGameStore first');
|
|
137
|
+
}
|
|
138
|
+
const [state, players] = this.tutorial.setupTutorial();
|
|
139
|
+
return this.initGameStore(state, players, this.tutorial.version ?? 1);
|
|
140
|
+
}
|
|
141
|
+
getGameOptions(arg = 2) {
|
|
142
|
+
const options = typeof arg === 'object' ? arg : { players: typeof arg === 'number' ? arg : 2 };
|
|
143
|
+
if (typeof options.players !== 'number' && !Array.isArray(options.players))
|
|
144
|
+
options.players = 2;
|
|
145
|
+
if (this.optionsSpec && isWithPlayerOptions(this.optionsSpec)) {
|
|
146
|
+
if (typeof options.players === 'number') {
|
|
147
|
+
options.players = [...Array(options.players)].map(() => ({}));
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
for (let i = 0; i < options.players.length; i++) {
|
|
151
|
+
if (typeof options.players[i] !== 'object')
|
|
152
|
+
options.players[i] = {};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
for (const option in this.optionsSpec.players) {
|
|
156
|
+
const playerOptionValue = this.optionsSpec.players[option];
|
|
157
|
+
const optionValues = generatePlayersOption(options.players.map((p) => p[option] ?? null), playerOptionValue);
|
|
158
|
+
for (let i = 0; i < options.players.length; i++) {
|
|
159
|
+
options.players[i][option] = optionValues[i];
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return options;
|
|
164
|
+
}
|
|
165
|
+
newGame(arg = 2) {
|
|
166
|
+
const options = this.getGameOptions(arg);
|
|
167
|
+
const playerIds = this.optionsSpec && isWithPlayerIdOptions(this.optionsSpec) ?
|
|
168
|
+
options.players.map((player) => player.id)
|
|
169
|
+
: (Array.isArray(options.players) ? options.players : [...Array(options.players)]).map((_, index) => index + 1);
|
|
170
|
+
const players = playerIds.map(id => ({ id }));
|
|
171
|
+
return this.initGameStore(this.gameSetup.setup(options), players);
|
|
172
|
+
}
|
|
173
|
+
initGameStore(game, players, tutorial) {
|
|
174
|
+
const rules = new this.Rules(game);
|
|
175
|
+
const playerId = players[0].id;
|
|
176
|
+
applyAutomaticMoves(rules);
|
|
177
|
+
const setup = JSON.parse(JSON.stringify(rules.game));
|
|
178
|
+
const localStore = { players, setup, state: rules.game, actions: [], playerId, monkeyOpponents: !!tutorial, tutorial };
|
|
179
|
+
localStorage.setItem(this.storage, JSON.stringify(localStore));
|
|
180
|
+
return localStore;
|
|
181
|
+
}
|
|
182
|
+
getLocalStore() {
|
|
183
|
+
return JSON.parse(localStorage.getItem(this.storage));
|
|
184
|
+
}
|
|
185
|
+
play(move) {
|
|
186
|
+
return mimicDataTransfer(move).then(move => {
|
|
187
|
+
const localStore = this.getLocalStore();
|
|
188
|
+
const rules = new this.Rules(localStore.state);
|
|
189
|
+
if (!verifyNonMutation(() => rules.isLegalMove(localStore.playerId, move), () => rules.game, 'isLegalMove and getLegalMoves must not change the game state')) {
|
|
190
|
+
console.error('This move is not authorized right now: ' + JSON.stringify(move));
|
|
191
|
+
if (this.tutorial) {
|
|
192
|
+
this.dispatch?.(reportFailure(Failure.TUTORIAL_MOVE_EXPECTED));
|
|
193
|
+
}
|
|
194
|
+
if (rules.getLegalMoves) {
|
|
195
|
+
console.info('Legal moves are:', rules.getLegalMoves(localStore.playerId));
|
|
196
|
+
}
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
this.autoPlayersCounter = 0;
|
|
200
|
+
this.playActions(localStore.playerId, [move]);
|
|
201
|
+
}).catch(error => {
|
|
202
|
+
console.error('The move could not be applied due to this error:', error);
|
|
203
|
+
throw error;
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
playActions(playerId, moves) {
|
|
207
|
+
const localStore = this.getLocalStore();
|
|
208
|
+
const game = new this.Rules(localStore.state);
|
|
209
|
+
const actions = [];
|
|
210
|
+
const notifications = [];
|
|
211
|
+
if (hasHiddenInformation(game)) {
|
|
212
|
+
for (const move of moves) {
|
|
213
|
+
const recipients = hasSecretInformation(game) && game.getPlayerMoveView ? localStore.players.map(player => player.id) : [];
|
|
214
|
+
const id = (++this.lastActionId).toString();
|
|
215
|
+
const { action, views } = playActionWithViews(game, move, playerId, recipients, id);
|
|
216
|
+
if (hasSecretInformation(game) && game.keepMoveSecret) {
|
|
217
|
+
for (const secretAction of localStore.actions.filter(isSecretAction)) {
|
|
218
|
+
const secretToPlayer = secretAction.secrets.find(secret => secret.recipient === localStore.playerId);
|
|
219
|
+
if (secretToPlayer && !game.keepMoveSecret(secretAction.move, localStore.playerId)) {
|
|
220
|
+
notifications.push(movePlayedNotification(secretToPlayer.action));
|
|
221
|
+
}
|
|
222
|
+
secretAction.secrets = secretAction.secrets.filter(secret => secret.recipient === undefined || game.keepMoveSecret(secretAction.move, secret.recipient));
|
|
223
|
+
if (secretAction.secrets.length === 1) {
|
|
224
|
+
delete secretAction.secrets;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
const secrets = [];
|
|
228
|
+
for (const player of localStore.players) {
|
|
229
|
+
const view = views.find(view => view.recipient === player.id) ?? views.find(view => !view.recipient);
|
|
230
|
+
if (player.id !== playerId && game.keepMoveSecret(move, player.id)) {
|
|
231
|
+
secrets.push({ recipient: player.id, action: view.action });
|
|
232
|
+
}
|
|
233
|
+
else if (player.id === localStore.playerId) {
|
|
234
|
+
notifications.push(movePlayedNotification(view.action));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
const spectatorView = views.find(view => view.recipient === undefined);
|
|
238
|
+
if (secrets.length) {
|
|
239
|
+
action.secrets = secrets;
|
|
240
|
+
secrets.push(spectatorView);
|
|
241
|
+
}
|
|
242
|
+
else if (localStore.playerId === undefined) {
|
|
243
|
+
notifications.push(movePlayedNotification(spectatorView.action));
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
const view = views.find(view => view.recipient === localStore.playerId) ?? views.find(view => !view.recipient);
|
|
248
|
+
notifications.push(movePlayedNotification(view.action));
|
|
249
|
+
}
|
|
250
|
+
actions.push(action);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
for (const move of moves) {
|
|
255
|
+
const id = (++this.lastActionId).toString();
|
|
256
|
+
const action = playAction(game, move, playerId);
|
|
257
|
+
action.id = id;
|
|
258
|
+
actions.push(action);
|
|
259
|
+
notifications.push(movePlayedNotification(action));
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const index = this.incrementNotificationsCount(notifications.length);
|
|
263
|
+
mimicDataTransfer({ notifications, index }, { sizeWarn: 9000 }).then(data => this.dispatch(receiveNotifications({
|
|
264
|
+
notifications: data.notifications,
|
|
265
|
+
notificationsIndex: data.index,
|
|
266
|
+
players: localStore.players,
|
|
267
|
+
serverTime: undefined
|
|
268
|
+
})));
|
|
269
|
+
localStore.actions.push(...actions);
|
|
270
|
+
localStorage.setItem(this.storage, JSON.stringify(localStore));
|
|
271
|
+
setTimeout(() => this.runAutoPlayers(), 100 + Math.random() * 100);
|
|
272
|
+
}
|
|
273
|
+
incrementNotificationsCount(quantity = 1) {
|
|
274
|
+
const previousValue = this.notificationsCount;
|
|
275
|
+
this.notificationsCount += quantity;
|
|
276
|
+
return previousValue;
|
|
277
|
+
}
|
|
278
|
+
undo(arg = 1, ignoreRules) {
|
|
279
|
+
if (typeof arg === 'string') {
|
|
280
|
+
mimicDataTransfer(arg).then(actionId => {
|
|
281
|
+
const localStore = this.getLocalStore();
|
|
282
|
+
const index = findLastIndex(localStore.actions, action => action.id === actionId);
|
|
283
|
+
if (index === -1)
|
|
284
|
+
return;
|
|
285
|
+
const action = localStore.actions[index];
|
|
286
|
+
if (!ignoreRules) {
|
|
287
|
+
const game = new this.Rules(localStore.state);
|
|
288
|
+
if (!hasUndo(game))
|
|
289
|
+
return console.error('This game does not have UNDO feature');
|
|
290
|
+
if (!game.canUndo(action, localStore.actions.slice(index + 1)))
|
|
291
|
+
return console.error('Trying to UNDO a move while it is forbidden');
|
|
292
|
+
}
|
|
293
|
+
localStore.actions.splice(index, 1);
|
|
294
|
+
const rules = new this.Rules(JSON.parse(JSON.stringify(localStore.setup)));
|
|
295
|
+
replayActions(rules, localStore.actions);
|
|
296
|
+
localStore.state = rules.game;
|
|
297
|
+
localStorage.setItem(this.storage, JSON.stringify(localStore));
|
|
298
|
+
if (!isSecretAction(action) || !action.secrets.some(secret => secret.recipient === localStore.playerId)) {
|
|
299
|
+
mimicDataTransfer({ notification: moveUndoneNotification(action, index), index: this.incrementNotificationsCount() }).then(data => this.dispatch(receiveNotifications({
|
|
300
|
+
notifications: [data.notification],
|
|
301
|
+
notificationsIndex: data.index,
|
|
302
|
+
players: localStore.players,
|
|
303
|
+
serverTime: undefined
|
|
304
|
+
})));
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
else if (arg > 0) {
|
|
309
|
+
const actions = this.getLocalStore().actions;
|
|
310
|
+
if (!actions.length)
|
|
311
|
+
return console.warn('Cannot undo, no actions were played yet');
|
|
312
|
+
for (let i = actions.length - 1; i > actions.length - 1 - arg; i--) {
|
|
313
|
+
this.undo(actions[i].id, true);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
startBots() {
|
|
318
|
+
const localStore = this.getLocalStore();
|
|
319
|
+
localStore.monkeyOpponents = true;
|
|
320
|
+
localStorage.setItem(this.storage, JSON.stringify(localStore));
|
|
321
|
+
this.autoPlayersCounter = 0;
|
|
322
|
+
this.runAutoPlayers();
|
|
323
|
+
}
|
|
324
|
+
stopBots() {
|
|
325
|
+
const localStore = this.getLocalStore();
|
|
326
|
+
localStore.monkeyOpponents = false;
|
|
327
|
+
localStorage.setItem(this.storage, JSON.stringify(localStore));
|
|
328
|
+
}
|
|
329
|
+
async runAutoPlayers() {
|
|
330
|
+
if (this.autoPlayersCounter > 100) {
|
|
331
|
+
console.warn('The automatic players played 100 times. There might be an infinite loop, stopping now.');
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const localStore = this.getLocalStore();
|
|
335
|
+
const rules = new this.Rules(localStore.state);
|
|
336
|
+
if (rules.isOver(localStore.players.map(player => player.id))) {
|
|
337
|
+
console.info('Game is over');
|
|
338
|
+
this.dispatch?.(setGameOver([]));
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (localStore.tutorial && this.tutorial) {
|
|
342
|
+
if (!this.tutorialMovesToPlay)
|
|
343
|
+
return;
|
|
344
|
+
const nextExpectedMove = this.tutorial.getNextMove(rules, localStore.actions.length);
|
|
345
|
+
if (nextExpectedMove) {
|
|
346
|
+
const expectedMoves = Array.isArray(nextExpectedMove) ? nextExpectedMove : [nextExpectedMove];
|
|
347
|
+
if (expectedMoves.some(expectedMove => rules.isLegalMove(localStore.playerId, expectedMove))) {
|
|
348
|
+
if (this.tutorialMovesToPlay !== Infinity) {
|
|
349
|
+
this.tutorialMovesToPlay = 0;
|
|
350
|
+
}
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
const expectedMove = expectedMoves[0];
|
|
354
|
+
const player = localStore.players.find(player => rules.isLegalMove(player.id, expectedMove));
|
|
355
|
+
if (player) {
|
|
356
|
+
this.tutorialMovesToPlay--;
|
|
357
|
+
return this.playActions(player.id, [expectedMove]);
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
console.error('Tutorial expects a move that no player can play: ', expectedMove);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
if (localStore.monkeyOpponents && !this.aiProcessing) {
|
|
365
|
+
const player = localStore.players.find(player => player.id !== localStore.playerId && rules.isTurnToPlay(player.id));
|
|
366
|
+
if (player) {
|
|
367
|
+
this.aiProcessing = true;
|
|
368
|
+
const moves = await this.getAI(player.id)(rules.game, player.id);
|
|
369
|
+
this.aiProcessing = false;
|
|
370
|
+
if (moves.length) {
|
|
371
|
+
this.playActions(player.id, moves);
|
|
372
|
+
this.autoPlayersCounter++;
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
console.error(`Player ${player.id} is active but did not return any move to play!`);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
else if (localStore.playerId === undefined || !rules.isTurnToPlay(localStore.playerId)) {
|
|
379
|
+
console.error('Game is not over but there is no active player!');
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
getAI(playerId) {
|
|
384
|
+
if (this.ai)
|
|
385
|
+
return this.ai;
|
|
386
|
+
const bot = new RandomBot(this.Rules, playerId);
|
|
387
|
+
return (game) => Promise.resolve(bot.run(game));
|
|
388
|
+
}
|
|
389
|
+
setPlayerName(name, playerId) {
|
|
390
|
+
const localStore = this.getLocalStore();
|
|
391
|
+
const player = localStore.players.find(player => player.id === (playerId || localStore.playerId));
|
|
392
|
+
if (!player) {
|
|
393
|
+
throw new Error('Player not found');
|
|
394
|
+
}
|
|
395
|
+
player.name = name;
|
|
396
|
+
localStorage.setItem(this.storage, JSON.stringify(localStore));
|
|
397
|
+
}
|
|
398
|
+
setAnimationsSpeed(speed = 1) {
|
|
399
|
+
this.dispatch(setAnimationsSpeed(speed));
|
|
400
|
+
localStorage.setItem('animationsSpeed', speed.toString());
|
|
401
|
+
}
|
|
402
|
+
eject() {
|
|
403
|
+
}
|
|
404
|
+
giveUp() {
|
|
405
|
+
}
|
|
406
|
+
playTutorialMoves(quantity) {
|
|
407
|
+
if (quantity) {
|
|
408
|
+
this.tutorialMovesToPlay += quantity;
|
|
409
|
+
this.autoPlayersCounter = 0;
|
|
410
|
+
setTimeout(() => this.runAutoPlayers(), 100 + Math.random() * 100);
|
|
411
|
+
}
|
|
412
|
+
else {
|
|
413
|
+
this.tutorialMovesToPlay = 0;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
function mimicDataTransfer(data, options = {}) {
|
|
418
|
+
const { sizeWarn = 0, duration = 100 } = options;
|
|
419
|
+
const stringData = JSON.stringify(data ?? null);
|
|
420
|
+
data = JSON.parse(stringData);
|
|
421
|
+
if (sizeWarn && stringData) {
|
|
422
|
+
if (stringData.length > sizeWarn) {
|
|
423
|
+
console.warn(`Notification payload of ${stringData.length} bytes exceeds ${sizeWarn} bytes, which can cause extra http requests.`, stringData);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return new Promise(resolve => setTimeout(() => resolve(data), duration));
|
|
427
|
+
}
|
|
428
|
+
function verifyNonMutation(operation, getState, message) {
|
|
429
|
+
const initialState = JSON.stringify(getState());
|
|
430
|
+
const result = operation();
|
|
431
|
+
const finalState = JSON.stringify(getState());
|
|
432
|
+
assert(initialState === finalState, message);
|
|
433
|
+
return result;
|
|
434
|
+
}
|
|
435
|
+
function sortObjectKeys(value) {
|
|
436
|
+
if (typeof value !== 'object' || value === null)
|
|
437
|
+
return value;
|
|
438
|
+
return Object.keys(value).sort().reduce((obj, key) => {
|
|
439
|
+
obj[key] = value[key];
|
|
440
|
+
return obj;
|
|
441
|
+
}, {});
|
|
442
|
+
}
|
|
541
443
|
//# sourceMappingURL=GameLocalAPI.js.map
|