12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- "use strict";
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = GamesManager;
- var _onlineDuelSync = _interopRequireDefault(require("./online-duel-sync"));
- function GamesManager(ioServer, mariadbConn) {
- var currentGames = new Map(); // Method to add player into a game, create or add to game syncer
- var addPlayerInGame = function addPlayerInGame(player, gameId, joinCreatedGame) {
- var isNewGame = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
- var gameOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
- if (currentGames.has(gameId)) {
- player.isPlayingGameId = gameId;
- return currentGames.get(gameId).addPlayer(player);
- } else if (joinCreatedGame === false) {
- player.isPlayingGameId = gameId;
- currentGames.set(gameId, new _onlineDuelSync.default(ioServer, mariadbConn, gameId, player, isNewGame, gameOptions));
- return true; // We are supposed to join a new game, but not there, must have been deleted in the meantime
- } else {
- console.log('error : ' + player.playerName + ' tries to join a created game that does not exist anymore');
- return false;
- }
- };
- var playerLeft = function playerLeft(player, disconnected) {
- var id = player.isPlayingGameId;
- if (currentGames.has(id)) {
- currentGames.get(id).playerLeft(player, disconnected);
- if (!currentGames.get(id).hasPlayers()) {
- currentGames.delete(id);
- mariadbConn.updateGameStatus(id, 'PAUSED');
- }
- }
- player.isPlayingGameId = -1;
- };
- return {
- addPlayerInGame: addPlayerInGame,
- playerLeft: playerLeft
- };
- }
- //# sourceMappingURL=games-manager.js.map
|