@gamepark/react-client 7.0.0-beta.0 → 7.0.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.js +3 -7
- package/dist/Actions/ActionFailed.js.map +1 -1
- package/dist/Actions/AnimationComplete.js +3 -7
- package/dist/Actions/AnimationComplete.js.map +1 -1
- package/dist/Actions/AnimationPaused.js +3 -7
- package/dist/Actions/AnimationPaused.js.map +1 -1
- 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 +2 -4
- package/dist/Actions/GameNotificationsReceived.js +2 -9
- package/dist/Actions/GameNotificationsReceived.js.map +1 -1
- package/dist/Actions/GameOver.js +3 -7
- package/dist/Actions/GameOver.js.map +1 -1
- package/dist/Actions/GameStateLoaded.js +5 -18
- package/dist/Actions/GameStateLoaded.js.map +1 -1
- package/dist/Actions/MovePlayed.d.ts +4 -4
- package/dist/Actions/MovePlayed.js +3 -4
- package/dist/Actions/MovePlayed.js.map +1 -1
- package/dist/Actions/MoveUndone.js +3 -8
- package/dist/Actions/MoveUndone.js.map +1 -1
- package/dist/Actions/PlayerQuit.d.ts +3 -9
- 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 -11
- package/dist/Actions/index.js +7 -27
- 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.js +1 -2
- package/dist/Chat/Message.js +1 -2
- package/dist/Chat/index.js +2 -18
- package/dist/Chat/index.js.map +1 -1
- package/dist/Deckbuilding/Deck.js +1 -2
- package/dist/Deckbuilding/index.js +4 -24
- package/dist/Deckbuilding/index.js.map +1 -1
- package/dist/Deckbuilding/useDeleteDeck.d.ts +4 -1
- package/dist/Deckbuilding/useDeleteDeck.js +8 -14
- package/dist/Deckbuilding/useDeleteDeck.js.map +1 -1
- package/dist/Deckbuilding/useMyDecks.d.ts +5 -1
- package/dist/Deckbuilding/useMyDecks.js +7 -13
- package/dist/Deckbuilding/useMyDecks.js.map +1 -1
- package/dist/Deckbuilding/useSaveDeck.d.ts +7 -1
- package/dist/Deckbuilding/useSaveDeck.js +8 -14
- 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.js +1 -17
- package/dist/EjectPlayer/index.js.map +1 -1
- package/dist/Failure/Failure.js +1 -4
- package/dist/Failure/Failure.js.map +1 -1
- package/dist/Failure/index.js +1 -17
- package/dist/Failure/index.js.map +1 -1
- package/dist/GiveUp/GiveUp.js +2 -5
- package/dist/GiveUp/GiveUp.js.map +1 -1
- package/dist/GiveUp/index.js +1 -17
- package/dist/GiveUp/index.js.map +1 -1
- package/dist/Hooks/index.js +5 -21
- package/dist/Hooks/index.js.map +1 -1
- package/dist/Hooks/useChatMessages.d.ts +1 -6
- package/dist/Hooks/useChatMessages.js +35 -44
- package/dist/Hooks/useChatMessages.js.map +1 -1
- package/dist/Hooks/useMessageAuthor.js +12 -16
- package/dist/Hooks/useMessageAuthor.js.map +1 -1
- package/dist/Hooks/useOptions.js +3 -6
- package/dist/Hooks/useOptions.js.map +1 -1
- package/dist/Hooks/useRematch.d.ts +1 -1
- package/dist/Hooks/useRematch.js +16 -20
- package/dist/Hooks/useRematch.js.map +1 -1
- package/dist/Hooks/useSendMessage.d.ts +4 -1
- package/dist/Hooks/useSendMessage.js +5 -12
- 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 +1 -4
- package/dist/Log/StopLiveLog.js +4 -7
- package/dist/Log/StopLiveLog.js.map +1 -1
- package/dist/Log/index.d.ts +2 -2
- package/dist/Log/index.js +4 -20
- package/dist/Log/index.js.map +1 -1
- package/dist/Log/useLogControls.js +11 -14
- package/dist/Log/useLogControls.js.map +1 -1
- package/dist/PlayerTime/PlayerTime.js +1 -2
- package/dist/PlayerTime/index.js +1 -17
- package/dist/PlayerTime/index.js.map +1 -1
- package/dist/Rematch/RematchQueries.js +23 -13
- package/dist/Rematch/RematchQueries.js.map +1 -1
- package/dist/Rematch/index.js +1 -17
- package/dist/Rematch/index.js.map +1 -1
- package/dist/Sound/MuteSounds.d.ts +1 -4
- package/dist/Sound/MuteSounds.js +5 -8
- 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 +2 -2
- package/dist/Sound/index.js +3 -19
- package/dist/Sound/index.js.map +1 -1
- package/dist/Sound/useSoundControls.js +11 -14
- package/dist/Sound/useSoundControls.js.map +1 -1
- package/dist/Store/DisplayedAction.js +4 -10
- package/dist/Store/DisplayedAction.js.map +1 -1
- package/dist/Store/GamePageState.d.ts +0 -1
- package/dist/Store/GamePageState.js +1 -2
- 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.js +30 -41
- package/dist/Store/gameMiddleware.js.map +1 -1
- package/dist/Store/gameReducer.d.ts +2 -11
- package/dist/Store/gameReducer.js +301 -377
- package/dist/Store/gameReducer.js.map +1 -1
- package/dist/Store/index.d.ts +1 -0
- package/dist/Store/index.js +4 -19
- package/dist/Store/index.js.map +1 -1
- package/dist/Store/localMovePreviewMiddleware.js +15 -13
- 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.js +1 -2
- package/dist/Tutorial/TutorialDescription.d.ts +1 -1
- package/dist/Tutorial/TutorialDescription.js +1 -2
- package/dist/Tutorial/index.js +4 -20
- package/dist/Tutorial/index.js.map +1 -1
- package/dist/Tutorial/useTutorial.js +11 -20
- package/dist/Tutorial/useTutorial.js.map +1 -1
- package/dist/Types/GameAI.js +1 -2
- package/dist/Types/GameData.js +1 -2
- package/dist/Types/GameMessage.js +1 -2
- package/dist/Types/GameMode.js +2 -5
- package/dist/Types/GameMode.js.map +1 -1
- package/dist/Types/GameNotification.js +1 -2
- package/dist/Types/GameOptions.js +2 -5
- package/dist/Types/GameOptions.js.map +1 -1
- package/dist/Types/MovePlayedNotification.d.ts +1 -1
- package/dist/Types/MovePlayedNotification.js +3 -8
- package/dist/Types/MovePlayedNotification.js.map +1 -1
- package/dist/Types/MoveUndoneNotification.d.ts +1 -1
- package/dist/Types/MoveUndoneNotification.js +3 -8
- package/dist/Types/MoveUndoneNotification.js.map +1 -1
- package/dist/Types/Player.js +1 -2
- package/dist/Types/PlayerQuitReason.js +2 -5
- package/dist/Types/PlayerQuitReason.js.map +1 -1
- package/dist/Types/ProxyGameData.js +1 -2
- package/dist/Types/Tournament.js +1 -2
- package/dist/Types/index.js +12 -28
- package/dist/Types/index.js.map +1 -1
- package/dist/User/User.js +1 -2
- package/dist/User/index.js +2 -18
- package/dist/User/index.js.map +1 -1
- package/dist/User/useMe.js +9 -19
- package/dist/User/useMe.js.map +1 -1
- package/dist/animations/Animation.js +1 -2
- package/dist/animations/AnimationContext.d.ts +1 -1
- package/dist/animations/AnimationContext.js +1 -2
- package/dist/animations/AnimationState.js +1 -2
- package/dist/animations/AnimationStep.js +2 -5
- package/dist/animations/AnimationStep.js.map +1 -1
- package/dist/animations/Animations.js +9 -16
- 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 +1 -4
- package/dist/animations/AnimationsListenerCreator.js +24 -30
- package/dist/animations/AnimationsListenerCreator.js.map +1 -1
- package/dist/animations/animationMiddleware.d.ts +4 -0
- package/dist/animations/animationMiddleware.js +46 -0
- package/dist/animations/animationMiddleware.js.map +1 -0
- package/dist/animations/index.d.ts +0 -1
- package/dist/animations/index.js +5 -22
- package/dist/animations/index.js.map +1 -1
- package/dist/api/Client/GameClientAPI.d.ts +5 -6
- package/dist/api/Client/GameClientAPI.js +70 -119
- package/dist/api/Client/GameClientAPI.js.map +1 -1
- package/dist/api/Client/GameNotificationsListener.js +51 -104
- package/dist/api/Client/GameNotificationsListener.js.map +1 -1
- package/dist/api/Client/RemoteGameLoader.js +50 -45
- package/dist/api/Client/RemoteGameLoader.js.map +1 -1
- package/dist/api/Client/RemoteGameProvider.js +15 -51
- package/dist/api/Client/RemoteGameProvider.js.map +1 -1
- package/dist/api/Client/apollo-client.d.ts +1 -1
- package/dist/api/Client/apollo-client.js +14 -31
- package/dist/api/Client/apollo-client.js.map +1 -1
- package/dist/api/Client/index.js +4 -20
- package/dist/api/Client/index.js.map +1 -1
- package/dist/api/Client/pusher.js +5 -12
- package/dist/api/Client/pusher.js.map +1 -1
- package/dist/api/GameAPI.d.ts +2 -3
- package/dist/api/GameAPI.js +1 -2
- package/dist/api/Local/ConsoleTools.d.ts +1 -2
- package/dist/api/Local/ConsoleTools.js +15 -22
- package/dist/api/Local/ConsoleTools.js.map +1 -1
- package/dist/api/Local/GameLocalAPI.d.ts +4 -5
- package/dist/api/Local/GameLocalAPI.js +264 -363
- package/dist/api/Local/GameLocalAPI.js.map +1 -1
- package/dist/api/Local/LocalGameProvider.d.ts +1 -1
- package/dist/api/Local/LocalGameProvider.js +17 -48
- package/dist/api/Local/LocalGameProvider.js.map +1 -1
- package/dist/api/Local/index.js +1 -17
- package/dist/api/Local/index.js.map +1 -1
- package/dist/api/index.js +2 -18
- package/dist/api/index.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +16 -36
- package/dist/index.js.map +1 -1
- package/dist/util/ArrayUtil.js +4 -8
- package/dist/util/ArrayUtil.js.map +1 -1
- package/package.json +64 -62
- 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,79 +1,41 @@
|
|
|
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
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
29
|
-
default:
|
|
30
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
31
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
32
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
33
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
34
|
-
if (t[2]) _.ops.pop();
|
|
35
|
-
_.trys.pop(); continue;
|
|
36
|
-
}
|
|
37
|
-
op = body.call(thisArg, _);
|
|
38
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
39
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
-
exports.GameClientAPI = exports.GET_MESSAGE_AUTHOR = exports.NOTIFICATIONS = exports.PLAYERS_TIME = exports.AVATAR_INFO = void 0;
|
|
44
|
-
var client_1 = require("@apollo/client");
|
|
45
|
-
var Actions_1 = require("../../Actions");
|
|
46
|
-
var Failure_1 = require("../../Failure");
|
|
47
|
-
var apollo_client_1 = require("./apollo-client");
|
|
48
|
-
exports.AVATAR_INFO = (0, client_1.gql)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["fragment AvatarInfo on Avataaar {accessoriesType clotheColor clotheType eyeType eyebrowType facialHairType facialHairColor graphicType hairColor mouthType skinColor topType}"], ["fragment AvatarInfo on Avataaar {accessoriesType clotheColor clotheType eyeType eyebrowType facialHairType facialHairColor graphicType hairColor mouthType skinColor topType}"])));
|
|
49
|
-
exports.PLAYERS_TIME = (0, client_1.gql)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["fragment PlayerTime on Player { time { availableTime cumulatedDownTime cumulatedPlayTime cumulatedWaitForMeTime highestDownTime highestPlayTime lastChange playing weightedWaitForMeTime } }"], ["fragment PlayerTime on Player { time { availableTime cumulatedDownTime cumulatedPlayTime cumulatedWaitForMeTime highestDownTime highestPlayTime lastChange playing weightedWaitForMeTime } }"])));
|
|
50
|
-
exports.NOTIFICATIONS = (0, client_1.gql)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["fragment Notifications on GameNotification { playerId ... on MovePlayedNotification { actionId moveView consequences } ... on MoveUndoneNotification { actionId moveUndone } }"], ["fragment Notifications on GameNotification { playerId ... on MovePlayedNotification { actionId moveView consequences } ... on MoveUndoneNotification { actionId moveUndone } }"])));
|
|
51
|
-
var PLAY = (0, client_1.gql)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["mutation PlayMoves($gameId: String!, $moves: [JSON!]!) { playMoves(gameId: $gameId, moves: $moves) { notifications { ...Notifications } index players { id ...PlayerTime } date } } ", " ", ""], ["mutation PlayMoves($gameId: String!, $moves: [JSON!]!) { playMoves(gameId: $gameId, moves: $moves) { notifications { ...Notifications } index players { id ...PlayerTime } date } } ", " ", ""])), exports.NOTIFICATIONS, exports.PLAYERS_TIME);
|
|
52
|
-
var UNDO = (0, client_1.gql)(templateObject_5 || (templateObject_5 = __makeTemplateObject(["mutation UndoMoves($gameId: String!, $actions: [String!]!) { undoMoves(gameId: $gameId, actions: $actions) { notifications { ...Notifications } index players { id ...PlayerTime } date } } ", " ", ""], ["mutation UndoMoves($gameId: String!, $actions: [String!]!) { undoMoves(gameId: $gameId, actions: $actions) { notifications { ...Notifications } index players { id ...PlayerTime } date } } ", " ", ""])), exports.NOTIFICATIONS, exports.PLAYERS_TIME);
|
|
53
|
-
var EJECT_PLAYER = (0, client_1.gql)(templateObject_6 || (templateObject_6 = __makeTemplateObject(["mutation EjectPlayer($gameId: String!, $playerId: JSON!) { ejectPlayer(gameId: $gameId, playerId: $playerId) { notifications { ...Notifications } index players { id ...PlayerTime } date } } ", " ", ""], ["mutation EjectPlayer($gameId: String!, $playerId: JSON!) { ejectPlayer(gameId: $gameId, playerId: $playerId) { notifications { ...Notifications } index players { id ...PlayerTime } date } } ", " ", ""])), exports.NOTIFICATIONS, exports.PLAYERS_TIME);
|
|
54
|
-
var GIVE_UP = (0, client_1.gql)(templateObject_7 || (templateObject_7 = __makeTemplateObject(["mutation GiveUp($gameId: String!) { giveUp(gameId: $gameId) { notifications { ...Notifications } index players { id ...PlayerTime } date } } ", " ", ""], ["mutation GiveUp($gameId: String!) { giveUp(gameId: $gameId) { notifications { ...Notifications } index players { id ...PlayerTime } date } } ", " ", ""])), exports.NOTIFICATIONS, exports.PLAYERS_TIME);
|
|
55
|
-
var CLAIM_VICTORY = (0, client_1.gql)(templateObject_8 || (templateObject_8 = __makeTemplateObject(["mutation ClaimVictory($gameId: String!) { claimVictory(gameId: $gameId) { id endDate } }"], ["mutation ClaimVictory($gameId: String!) { claimVictory(gameId: $gameId) { id endDate } }"])));
|
|
56
|
-
exports.GET_MESSAGE_AUTHOR = (0, client_1.gql)(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n query GetMessageAuthor($id: String!) {\n user(id: $id) {\n id name avatar {...AvatarInfo}\n }\n } ", "\n"], ["\n query GetMessageAuthor($id: String!) {\n user(id: $id) {\n id name avatar {...AvatarInfo}\n }\n } ", "\n"])), exports.AVATAR_INFO);
|
|
57
|
-
var GameClientAPI = (function () {
|
|
58
|
-
function GameClientAPI(gameId) {
|
|
59
|
-
this.pendingActions = [];
|
|
1
|
+
import { CombinedGraphQLErrors, gql } from '@apollo/client';
|
|
2
|
+
import { receiveNotifications } from '../../Actions';
|
|
3
|
+
import { reportFailure } from '../../Actions/reportFailure';
|
|
4
|
+
import { Failure } from '../../Failure';
|
|
5
|
+
import { getApolloClient } from './apollo-client';
|
|
6
|
+
export const PLATFORM_URI = process.env.PLATFORM_URI ?? 'https://game-park.com';
|
|
7
|
+
export const AVATAR_INFO = gql `fragment AvatarInfo on Avataaar {accessoriesType clotheColor clotheType eyeType eyebrowType facialHairType facialHairColor graphicType hairColor mouthType skinColor topType}`;
|
|
8
|
+
export const PLAYERS_TIME = gql `fragment PlayerTime on Player { time { availableTime cumulatedDownTime cumulatedPlayTime cumulatedWaitForMeTime highestDownTime highestPlayTime lastChange playing weightedWaitForMeTime } }`;
|
|
9
|
+
export const NOTIFICATIONS = gql `fragment Notifications on GameNotification { playerId ... on MovePlayedNotification { actionId moveView consequences } ... on MoveUndoneNotification { actionId moveUndone } }`;
|
|
10
|
+
const PLAY = gql `mutation PlayMoves($gameId: String!, $moves: [JSON!]!) { playMoves(gameId: $gameId, moves: $moves) { notifications { ...Notifications } index players { id ...PlayerTime } date } } ${NOTIFICATIONS} ${PLAYERS_TIME}`;
|
|
11
|
+
const UNDO = gql `mutation UndoMoves($gameId: String!, $actions: [String!]!) { undoMoves(gameId: $gameId, actions: $actions) { notifications { ...Notifications } index players { id ...PlayerTime } date } } ${NOTIFICATIONS} ${PLAYERS_TIME}`;
|
|
12
|
+
const EJECT_PLAYER = gql `mutation EjectPlayer($gameId: String!, $playerId: JSON!) { ejectPlayer(gameId: $gameId, playerId: $playerId) { notifications { ...Notifications } index players { id ...PlayerTime } date } } ${NOTIFICATIONS} ${PLAYERS_TIME}`;
|
|
13
|
+
const GIVE_UP = gql `mutation GiveUp($gameId: String!) { giveUp(gameId: $gameId) { notifications { ...Notifications } index players { id ...PlayerTime } date } } ${NOTIFICATIONS} ${PLAYERS_TIME}`;
|
|
14
|
+
const CLAIM_VICTORY = gql `mutation ClaimVictory($gameId: String!) { claimVictory(gameId: $gameId) { id endDate } }`;
|
|
15
|
+
export const GET_MESSAGE_AUTHOR = gql `
|
|
16
|
+
query GetMessageAuthor($id: String!) {
|
|
17
|
+
user(id: $id) {
|
|
18
|
+
id name avatar {...AvatarInfo}
|
|
19
|
+
}
|
|
20
|
+
} ${AVATAR_INFO}
|
|
21
|
+
`;
|
|
22
|
+
export class GameClientAPI {
|
|
23
|
+
dispatch;
|
|
24
|
+
gameId;
|
|
25
|
+
ongoingAction;
|
|
26
|
+
pendingActions = [];
|
|
27
|
+
constructor(gameId) {
|
|
60
28
|
this.gameId = gameId;
|
|
61
29
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return [2];
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
GameClientAPI.prototype.play = function (move) {
|
|
71
|
-
var _this = this;
|
|
30
|
+
async init(dispatch) {
|
|
31
|
+
this.dispatch = dispatch;
|
|
32
|
+
}
|
|
33
|
+
play(move) {
|
|
72
34
|
if (this.pendingActions.length === 0) {
|
|
73
35
|
this.pendingActions.push({ type: 'PLAY', moves: [move] });
|
|
74
36
|
}
|
|
75
37
|
else {
|
|
76
|
-
|
|
38
|
+
const lastPendingAction = this.pendingActions[this.pendingActions.length - 1];
|
|
77
39
|
if (lastPendingAction.type === 'PLAY') {
|
|
78
40
|
lastPendingAction.moves.push(move);
|
|
79
41
|
}
|
|
@@ -82,17 +44,17 @@ var GameClientAPI = (function () {
|
|
|
82
44
|
}
|
|
83
45
|
}
|
|
84
46
|
if (!this.ongoingAction) {
|
|
85
|
-
this.ongoingAction = new Promise(
|
|
47
|
+
this.ongoingAction = new Promise(resolve => setTimeout(resolve, 50)).then(() => this.executePendingActions());
|
|
86
48
|
}
|
|
87
|
-
}
|
|
88
|
-
|
|
49
|
+
}
|
|
50
|
+
undo(action) {
|
|
89
51
|
if (typeof action === 'number')
|
|
90
52
|
return console.error('GameClientAPI can no longer undo without an action ID');
|
|
91
53
|
if (this.pendingActions.length === 0) {
|
|
92
54
|
this.pendingActions.push({ type: 'UNDO', actions: [action] });
|
|
93
55
|
}
|
|
94
56
|
else {
|
|
95
|
-
|
|
57
|
+
const lastPendingAction = this.pendingActions[this.pendingActions.length - 1];
|
|
96
58
|
if (lastPendingAction.type === 'UNDO') {
|
|
97
59
|
lastPendingAction.actions.push(action);
|
|
98
60
|
}
|
|
@@ -103,65 +65,54 @@ var GameClientAPI = (function () {
|
|
|
103
65
|
if (!this.ongoingAction) {
|
|
104
66
|
this.executePendingActions();
|
|
105
67
|
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
var _this = this;
|
|
68
|
+
}
|
|
69
|
+
executePendingActions() {
|
|
109
70
|
if (this.pendingActions.length > 0) {
|
|
110
|
-
|
|
71
|
+
const pendingAction = this.pendingActions.shift();
|
|
111
72
|
if (pendingAction.type == 'PLAY') {
|
|
112
|
-
this.ongoingAction =
|
|
73
|
+
this.ongoingAction = getApolloClient().mutate({
|
|
113
74
|
mutation: PLAY, variables: { gameId: this.gameId, moves: pendingAction.moves }
|
|
114
|
-
}).then(
|
|
75
|
+
}).then(result => result.data && this.handleGameMessageResult(result.data.playMoves));
|
|
115
76
|
}
|
|
116
77
|
else if (pendingAction.type === 'UNDO') {
|
|
117
|
-
this.ongoingAction =
|
|
78
|
+
this.ongoingAction = getApolloClient().mutate({
|
|
118
79
|
mutation: UNDO, variables: { gameId: this.gameId, actions: pendingAction.actions }
|
|
119
|
-
}).then(
|
|
80
|
+
}).then(result => result.data && this.handleGameMessageResult(result.data.undoMoves));
|
|
120
81
|
}
|
|
121
82
|
if (this.ongoingAction) {
|
|
122
|
-
this.ongoingAction = this.ongoingAction.catch(
|
|
83
|
+
this.ongoingAction = this.ongoingAction.catch(error => this.onError(error)).finally(() => this.executePendingActions());
|
|
123
84
|
}
|
|
124
85
|
}
|
|
125
86
|
else {
|
|
126
87
|
delete this.ongoingAction;
|
|
127
88
|
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
var graphQLErrors = _a.graphQLErrors, networkError = _a.networkError;
|
|
146
|
-
if (graphQLErrors) {
|
|
147
|
-
graphQLErrors.map(function (_a) {
|
|
148
|
-
var message = _a.message;
|
|
149
|
-
return _this.dispatch((0, Actions_1.actionFailed)(message));
|
|
150
|
-
});
|
|
89
|
+
}
|
|
90
|
+
handleGameMessageResult({ date, index, notifications, players }) {
|
|
91
|
+
this.dispatch(receiveNotifications({ notifications, notificationsIndex: index, players, serverTime: Date.parse(date) }));
|
|
92
|
+
}
|
|
93
|
+
eject(playerId) {
|
|
94
|
+
getApolloClient().mutate({ mutation: EJECT_PLAYER, variables: { gameId: this.gameId, playerId } })
|
|
95
|
+
.then(result => result.data && this.handleGameMessageResult(result.data.ejectPlayer));
|
|
96
|
+
}
|
|
97
|
+
giveUp() {
|
|
98
|
+
getApolloClient().mutate({ mutation: GIVE_UP, variables: { gameId: this.gameId } })
|
|
99
|
+
.then(result => result.data && this.handleGameMessageResult(result.data.giveUp));
|
|
100
|
+
}
|
|
101
|
+
onError(error) {
|
|
102
|
+
if (CombinedGraphQLErrors.is(error)) {
|
|
103
|
+
for (const graphqlFormattedError of error.errors) {
|
|
104
|
+
this.dispatch(reportFailure(graphqlFormattedError.message));
|
|
105
|
+
}
|
|
151
106
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
this.dispatch((0, Actions_1.actionFailed)(Failure_1.Failure.NETWORK));
|
|
107
|
+
else {
|
|
108
|
+
this.dispatch(reportFailure(Failure.NETWORK));
|
|
155
109
|
}
|
|
156
|
-
}
|
|
157
|
-
|
|
110
|
+
}
|
|
111
|
+
playTutorialMoves() {
|
|
158
112
|
console.error('Tutorial should only be played with local API');
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
}());
|
|
165
|
-
exports.GameClientAPI = GameClientAPI;
|
|
166
|
-
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9;
|
|
113
|
+
}
|
|
114
|
+
claimVictory() {
|
|
115
|
+
return getApolloClient().mutate({ mutation: CLAIM_VICTORY, variables: { gameId: this.gameId } });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
167
118
|
//# sourceMappingURL=GameClientAPI.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GameClientAPI.js","sourceRoot":"","sources":["../../../src/api/Client/GameClientAPI.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GameClientAPI.js","sourceRoot":"","sources":["../../../src/api/Client/GameClientAPI.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAE3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO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AAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;IACpF,CAAC;IAED,OAAO,CAAC,KAAc;QACpB,IAAI,qBAAqB,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;YACpC,KAAK,MAAM,qBAAqB,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;gBACjD,IAAI,CAAC,QAAS,CAAC,aAAa,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAA;YAC9D,CAAC;QACH,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,QAAS,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;QAChD,CAAC;IACH,CAAC;IAED,iBAAiB;QACf,OAAO,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAA;IAChE,CAAC;IAED,YAAY;QACV,OAAO,eAAe,EAAE,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IAClG,CAAC;CACF"}
|
|
@@ -1,117 +1,64 @@
|
|
|
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
|
-
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
import { useApolloClient } from '@apollo/client/react';
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
|
+
import { receiveNotifications, setGameOver } from '../../Actions';
|
|
5
|
+
import { removePlayer } from '../../Actions/removePlayer';
|
|
6
|
+
import { useGameDispatch } from '../../Store';
|
|
7
|
+
import { NOTIFICATIONS, PLAYERS_TIME } from './GameClientAPI';
|
|
8
|
+
import { pusherClient } from './pusher';
|
|
9
|
+
const GET_NOTIFICATIONS = gql `
|
|
10
|
+
query GameNotifications($gameId: String!, $start: Int) {
|
|
11
|
+
time
|
|
12
|
+
gameNotifications(gameId: $gameId, start: $start) { ...Notifications }
|
|
13
|
+
game(id: $gameId) {
|
|
14
|
+
id players { id ...PlayerTime }
|
|
15
|
+
}
|
|
16
|
+
} ${NOTIFICATIONS} ${PLAYERS_TIME}
|
|
17
|
+
`;
|
|
18
|
+
export function GameNotificationsListener({ gameId, channelName, notificationsCount }) {
|
|
19
|
+
const client = useApolloClient();
|
|
20
|
+
const dispatch = useGameDispatch();
|
|
21
|
+
const notificationsCountRef = useRef(notificationsCount);
|
|
22
|
+
const getNotifications = async (start) => {
|
|
23
|
+
const { data } = await client.query({
|
|
24
|
+
query: GET_NOTIFICATIONS,
|
|
25
|
+
variables: { gameId, start }
|
|
26
|
+
});
|
|
27
|
+
if (!data)
|
|
28
|
+
return console.error('Failed to collect game data');
|
|
29
|
+
dispatch(receiveNotifications({ notifications: data.gameNotifications, notificationsIndex: start, players: data.game.players, serverTime: data.time }));
|
|
30
|
+
if (data.gameNotifications.length > 0) {
|
|
31
|
+
notificationsCountRef.current = Math.max(notificationsCountRef.current, start + data.gameNotifications.length);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const channel = pusherClient.subscribe(channelName);
|
|
36
|
+
channel.bind('pusher:subscription_error', (error) => console.error('pusher subscription failed', error));
|
|
37
|
+
channel.bind('pusher:subscription_succeeded', () => getNotifications(notificationsCountRef.current));
|
|
38
|
+
channel.bind('moves-played', async (message) => {
|
|
39
|
+
if (!message)
|
|
40
|
+
return;
|
|
41
|
+
const { index, notifications, players, date } = message;
|
|
42
|
+
dispatch(receiveNotifications({ notifications, notificationsIndex: index, players, serverTime: Date.parse(date) }));
|
|
43
|
+
if (notifications.length) {
|
|
44
|
+
notificationsCountRef.current = Math.max(notificationsCountRef.current, index + notifications.length);
|
|
36
45
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
-
exports.GameNotificationsListener = GameNotificationsListener;
|
|
44
|
-
var client_1 = require("@apollo/client");
|
|
45
|
-
var react_1 = require("react");
|
|
46
|
-
var react_redux_1 = require("react-redux");
|
|
47
|
-
var Actions_1 = require("../../Actions");
|
|
48
|
-
var PlayerQuit_1 = require("../../Actions/PlayerQuit");
|
|
49
|
-
var GameClientAPI_1 = require("./GameClientAPI");
|
|
50
|
-
var pusher_1 = require("./pusher");
|
|
51
|
-
var GET_NOTIFICATIONS = (0, client_1.gql)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n query GameNotifications($gameId: String!, $start: Int) {\n time\n gameNotifications(gameId: $gameId, start: $start) { ...Notifications }\n game(id: $gameId) {\n id players { id ...PlayerTime }\n }\n } ", " ", "\n"], ["\n query GameNotifications($gameId: String!, $start: Int) {\n time\n gameNotifications(gameId: $gameId, start: $start) { ...Notifications }\n game(id: $gameId) {\n id players { id ...PlayerTime }\n }\n } ", " ", "\n"])), GameClientAPI_1.NOTIFICATIONS, GameClientAPI_1.PLAYERS_TIME);
|
|
52
|
-
function GameNotificationsListener(_a) {
|
|
53
|
-
var _this = this;
|
|
54
|
-
var gameId = _a.gameId, channelName = _a.channelName, notificationsCount = _a.notificationsCount;
|
|
55
|
-
var client = (0, client_1.useApolloClient)();
|
|
56
|
-
var dispatch = (0, react_redux_1.useDispatch)();
|
|
57
|
-
var notificationsCountRef = (0, react_1.useRef)(notificationsCount);
|
|
58
|
-
var getNotifications = function (start) { return __awaiter(_this, void 0, void 0, function () {
|
|
59
|
-
var data;
|
|
60
|
-
return __generator(this, function (_a) {
|
|
61
|
-
switch (_a.label) {
|
|
62
|
-
case 0: return [4, client.query({
|
|
63
|
-
query: GET_NOTIFICATIONS,
|
|
64
|
-
variables: { gameId: gameId, start: start }
|
|
65
|
-
})];
|
|
66
|
-
case 1:
|
|
67
|
-
data = (_a.sent()).data;
|
|
68
|
-
if (!data)
|
|
69
|
-
return [2, console.error('Failed to collect game data')];
|
|
70
|
-
dispatch((0, Actions_1.gameNotificationsReceived)(data.gameNotifications, start, data.game.players, data.time));
|
|
71
|
-
if (data.gameNotifications.length > 0) {
|
|
72
|
-
notificationsCountRef.current = Math.max(notificationsCountRef.current, start + data.gameNotifications.length);
|
|
73
|
-
}
|
|
74
|
-
return [2];
|
|
46
|
+
else {
|
|
47
|
+
await getNotifications(index);
|
|
75
48
|
}
|
|
76
49
|
});
|
|
77
|
-
|
|
78
|
-
(0, react_1.useEffect)(function () {
|
|
79
|
-
var channel = pusher_1.pusherClient.subscribe(channelName);
|
|
80
|
-
channel.bind('pusher:subscription_error', function (error) { return console.error('pusher subscription failed', error); });
|
|
81
|
-
channel.bind('pusher:subscription_succeeded', function () { return getNotifications(notificationsCountRef.current); });
|
|
82
|
-
channel.bind('moves-played', function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
83
|
-
var index, notifications, players, date;
|
|
84
|
-
return __generator(this, function (_a) {
|
|
85
|
-
switch (_a.label) {
|
|
86
|
-
case 0:
|
|
87
|
-
if (!message)
|
|
88
|
-
return [2];
|
|
89
|
-
index = message.index, notifications = message.notifications, players = message.players, date = message.date;
|
|
90
|
-
dispatch((0, Actions_1.gameNotificationsReceived)(notifications, index, players, Date.parse(date)));
|
|
91
|
-
if (!notifications.length) return [3, 1];
|
|
92
|
-
notificationsCountRef.current = Math.max(notificationsCountRef.current, index + notifications.length);
|
|
93
|
-
return [3, 3];
|
|
94
|
-
case 1: return [4, getNotifications(index)];
|
|
95
|
-
case 2:
|
|
96
|
-
_a.sent();
|
|
97
|
-
_a.label = 3;
|
|
98
|
-
case 3: return [2];
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}); });
|
|
102
|
-
channel.bind('game-over', function (players) {
|
|
50
|
+
channel.bind('game-over', (players) => {
|
|
103
51
|
if (players) {
|
|
104
|
-
dispatch((
|
|
52
|
+
dispatch(setGameOver(players));
|
|
105
53
|
}
|
|
106
54
|
});
|
|
107
|
-
channel.bind('player-quit',
|
|
55
|
+
channel.bind('player-quit', (data) => {
|
|
108
56
|
if (data) {
|
|
109
|
-
dispatch((
|
|
57
|
+
dispatch(removePlayer(data));
|
|
110
58
|
}
|
|
111
59
|
});
|
|
112
|
-
return
|
|
60
|
+
return () => pusherClient.unsubscribe(channelName);
|
|
113
61
|
}, []);
|
|
114
62
|
return null;
|
|
115
63
|
}
|
|
116
|
-
var templateObject_1;
|
|
117
64
|
//# sourceMappingURL=GameNotificationsListener.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GameNotificationsListener.js","sourceRoot":"","sources":["../../../src/api/Client/GameNotificationsListener.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GameNotificationsListener.js","sourceRoot":"","sources":["../../../src/api/Client/GameNotificationsListener.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AACzC,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7C,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,iBAA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AA;QAEF,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,CAAC,WAAW,CAAC,CAAA;IACpD,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -1,54 +1,60 @@
|
|
|
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
|
-
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { gql } from '@apollo/client';
|
|
3
|
+
import { useLazyQuery } from '@apollo/client/react';
|
|
4
|
+
import { useEffect, useState } from 'react';
|
|
5
|
+
import { loadGameState } from '../../Actions/loadGameState';
|
|
6
|
+
import { useGameDispatch, useGameSelector } from '../../Store';
|
|
7
|
+
import { AVATAR_INFO, NOTIFICATIONS, PLAYERS_TIME } from './GameClientAPI';
|
|
8
|
+
import { GameNotificationsListener } from './GameNotificationsListener';
|
|
9
|
+
const GET_GAME = gql `
|
|
10
|
+
query Game($id: String!) {
|
|
11
|
+
time
|
|
12
|
+
gameNotifications(gameId: $id, start: 0) { ...Notifications }
|
|
13
|
+
game(id: $id) {
|
|
14
|
+
id
|
|
15
|
+
players {
|
|
16
|
+
id userId name avatar {...AvatarInfo} quit quitReason gamePointsDelta tournamentPoints ...PlayerTime
|
|
17
|
+
}
|
|
18
|
+
options {
|
|
19
|
+
speed maxSpareTime maxExceedTime
|
|
20
|
+
}
|
|
21
|
+
notificationsChannel mode setup state myPlayerId endDate
|
|
22
|
+
tournament {
|
|
23
|
+
number signedUp
|
|
24
|
+
}
|
|
25
|
+
version
|
|
26
|
+
}
|
|
27
|
+
} ${PLAYERS_TIME} ${AVATAR_INFO} ${NOTIFICATIONS}
|
|
28
|
+
`;
|
|
29
|
+
export function RemoteGameLoader({ gameId, version = 1 }) {
|
|
30
|
+
const dispatch = useGameDispatch();
|
|
31
|
+
const isOver = useGameSelector(state => state.gameOver);
|
|
32
|
+
const [isOverForLongEnough, setIsOverForLongEnough] = useState(isOver);
|
|
33
|
+
useEffect(() => {
|
|
34
34
|
if (isOver) {
|
|
35
|
-
setTimeout(
|
|
35
|
+
setTimeout(() => setIsOverForLongEnough(isOver), 10000);
|
|
36
36
|
}
|
|
37
37
|
}, [isOver]);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
getGame({ variables: { id: gameId } }).then(
|
|
38
|
+
const [getGame, { data }] = useLazyQuery(GET_GAME);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
getGame({ variables: { id: gameId } }).then(result => {
|
|
41
41
|
if (result.data) {
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
const { game, time, gameNotifications } = result.data;
|
|
43
|
+
const remoteVersion = game.version;
|
|
44
44
|
if (remoteVersion && remoteVersion !== version) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
url.hostname =
|
|
45
|
+
const url = new URL(window.location.href);
|
|
46
|
+
const path = url.hostname.split('.');
|
|
47
|
+
url.hostname = `${path[0]}.v${remoteVersion}.${path[path.length - 2]}.${path[path.length - 1]}`;
|
|
48
48
|
window.location.href = url.href;
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
51
|
-
dispatch((
|
|
51
|
+
dispatch(loadGameState({
|
|
52
|
+
...({ ...game, notifications: gameNotifications }),
|
|
53
|
+
playerId: { ...game, notifications: gameNotifications }.myPlayerId ?? undefined,
|
|
54
|
+
serverTime: time,
|
|
55
|
+
endDate: { ...game, notifications: gameNotifications }.endDate ?? undefined,
|
|
56
|
+
tournament: { ...game, notifications: gameNotifications }.tournament ?? undefined
|
|
57
|
+
}));
|
|
52
58
|
}
|
|
53
59
|
}
|
|
54
60
|
});
|
|
@@ -56,7 +62,6 @@ function RemoteGameLoader(_a) {
|
|
|
56
62
|
if (!data || data.game.endDate || isOverForLongEnough)
|
|
57
63
|
return null;
|
|
58
64
|
else
|
|
59
|
-
return (
|
|
65
|
+
return _jsx(GameNotificationsListener, { channelName: data?.game?.notificationsChannel ?? `game=${gameId}`, gameId: gameId, notificationsCount: data.gameNotifications.length });
|
|
60
66
|
}
|
|
61
|
-
var templateObject_1;
|
|
62
67
|
//# sourceMappingURL=RemoteGameLoader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteGameLoader.js","sourceRoot":"","sources":["../../../src/api/Client/RemoteGameLoader.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RemoteGameLoader.js","sourceRoot":"","sources":["../../../src/api/Client/RemoteGameLoader.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE9D,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC1E,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAA;AAEvE,MAAM,QAAQ,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;MAkBd,YAAY,IAAI,WAAW,IAAI,aAAa;CACjD,CAAA;AAED,MAAM,UAAU,gBAAgB,CAAC,EAAE,MAAM,EAAE,OAAO,GAAG,CAA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