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