{"version":3,"sources":["../../src/game-server/games-manager.js"],"names":["GamesManager","ioServer","mariadbConn","currentGames","Map","addPlayerInGame","player","gameId","joinCreatedGame","isNewGame","gameOptions","has","isPlayingGameId","get","addPlayer","set","OnlineDuelSync","console","log","playerName","playerLeft","disconnected","id","hasPlayers","delete","updateGameStatus"],"mappings":";;;;;;;;;AAAA;;AAEe,SAASA,YAAT,CAAsBC,QAAtB,EAAgCC,WAAhC,EAA6C;AAC1D,MAAIC,YAAY,GAAG,IAAIC,GAAJ,EAAnB,CAD0D,CAG1D;;AACA,MAAIC,eAAe,GAAG,SAAlBA,eAAkB,CACpBC,MADoB,EAEpBC,MAFoB,EAGpBC,eAHoB,EAMpB;AAAA,QAFAC,SAEA,uEAFY,KAEZ;AAAA,QADAC,WACA,uEADc,EACd;;AACA,QAAIP,YAAY,CAACQ,GAAb,CAAiBJ,MAAjB,CAAJ,EAA8B;AAC5BD,MAAAA,MAAM,CAACM,eAAP,GAAyBL,MAAzB;AACA,aAAOJ,YAAY,CAACU,GAAb,CAAiBN,MAAjB,EAAyBO,SAAzB,CAAmCR,MAAnC,CAAP;AACD,KAHD,MAGO,IAAIE,eAAe,KAAK,KAAxB,EAA+B;AACpCF,MAAAA,MAAM,CAACM,eAAP,GAAyBL,MAAzB;AACAJ,MAAAA,YAAY,CAACY,GAAb,CACER,MADF,EAEE,IAAIS,uBAAJ,CACEf,QADF,EAEEC,WAFF,EAGEK,MAHF,EAIED,MAJF,EAKEG,SALF,EAMEC,WANF,CAFF;AAWA,aAAO,IAAP,CAboC,CAepC;AACD,KAhBM,MAgBA;AACLO,MAAAA,OAAO,CAACC,GAAR,CACE,aACEZ,MAAM,CAACa,UADT,GAEE,2DAHJ;AAKA,aAAO,KAAP;AACD;AACF,GAlCD;;AAoCA,MAAIC,UAAU,GAAG,SAAbA,UAAa,CAASd,MAAT,EAAiBe,YAAjB,EAA+B;AAC9C,QAAIC,EAAE,GAAGhB,MAAM,CAACM,eAAhB;;AAEA,QAAIT,YAAY,CAACQ,GAAb,CAAiBW,EAAjB,CAAJ,EAA0B;AACxBnB,MAAAA,YAAY,CAACU,GAAb,CAAiBS,EAAjB,EAAqBF,UAArB,CAAgCd,MAAhC,EAAwCe,YAAxC;;AACA,UAAI,CAAClB,YAAY,CAACU,GAAb,CAAiBS,EAAjB,EAAqBC,UAArB,EAAL,EAAwC;AACtCpB,QAAAA,YAAY,CAACqB,MAAb,CAAoBF,EAApB;AACApB,QAAAA,WAAW,CAACuB,gBAAZ,CAA6BH,EAA7B,EAAiC,QAAjC;AACD;AACF;;AAEDhB,IAAAA,MAAM,CAACM,eAAP,GAAyB,CAAC,CAA1B;AACD,GAZD;;AAcA,SAAO;AACLP,IAAAA,eAAe,EAAfA,eADK;AAELe,IAAAA,UAAU,EAAVA;AAFK,GAAP;AAID","sourcesContent":["import OnlineDuelSync from './online-duel-sync';\r\n\r\nexport default function GamesManager(ioServer, mariadbConn) {\r\n let currentGames = new Map();\r\n\r\n // Method to add player into a game, create or add to game syncer\r\n let addPlayerInGame = function(\r\n player,\r\n gameId,\r\n joinCreatedGame,\r\n isNewGame = false,\r\n gameOptions = {}\r\n ) {\r\n if (currentGames.has(gameId)) {\r\n player.isPlayingGameId = gameId;\r\n return currentGames.get(gameId).addPlayer(player);\r\n } else if (joinCreatedGame === false) {\r\n player.isPlayingGameId = gameId;\r\n currentGames.set(\r\n gameId,\r\n new OnlineDuelSync(\r\n ioServer,\r\n mariadbConn,\r\n gameId,\r\n player,\r\n isNewGame,\r\n gameOptions\r\n )\r\n );\r\n return true;\r\n\r\n // We are supposed to join a new game, but not there, must have been deleted in the meantime\r\n } else {\r\n console.log(\r\n 'error : ' +\r\n player.playerName +\r\n ' tries to join a created game that does not exist anymore'\r\n );\r\n return false;\r\n }\r\n };\r\n\r\n let playerLeft = function(player, disconnected) {\r\n let id = player.isPlayingGameId;\r\n\r\n if (currentGames.has(id)) {\r\n currentGames.get(id).playerLeft(player, disconnected);\r\n if (!currentGames.get(id).hasPlayers()) {\r\n currentGames.delete(id);\r\n mariadbConn.updateGameStatus(id, 'PAUSED');\r\n }\r\n }\r\n\r\n player.isPlayingGameId = -1;\r\n };\r\n\r\n return {\r\n addPlayerInGame,\r\n playerLeft\r\n };\r\n}\r\n"],"file":"games-manager.js"}