From 85e9d14b0271aa831c6bdc5309e0628e247ce169 Mon Sep 17 00:00:00 2001 From: Zutatensuppe Date: Fri, 30 Apr 2021 01:03:43 +0200 Subject: [PATCH] remove confusing newGame function --- common/GameCommon.js | 15 +-------------- game/Game.js | 2 +- game/game.js | 6 ++++-- server/Game.js | 10 ++++++---- 4 files changed, 12 insertions(+), 21 deletions(-) diff --git a/common/GameCommon.js b/common/GameCommon.js index c636296..5b3db80 100644 --- a/common/GameCommon.js +++ b/common/GameCommon.js @@ -27,19 +27,6 @@ function __createPlayerObject(id, ts) { } } -function newGame({id, rng, puzzle, players, evtInfos, scoreMode}) { - const game = { - id: id, - rng: rng, - puzzle: puzzle, - players: players, - evtInfos: evtInfos, - scoreMode: scoreMode, - } - setGame(id, game) - return game -} - function setGame(gameId, game) { GAMES[gameId] = game } @@ -740,7 +727,7 @@ function handleInput(gameId, playerId, input, ts) { export default { __createPlayerObject, - newGame, + setGame, exists, playerExists, getRelevantPlayers, diff --git a/game/Game.js b/game/Game.js index c678e14..eaaf0eb 100644 --- a/game/Game.js +++ b/game/Game.js @@ -1,7 +1,7 @@ import GameCommon from './../common/GameCommon.js' export default { - newGame: GameCommon.newGame, + setGame: GameCommon.setGame, getRelevantPlayers: GameCommon.getRelevantPlayers, getActivePlayers: GameCommon.getActivePlayers, addPlayer: GameCommon.addPlayer, diff --git a/game/game.js b/game/game.js index 4ff6811..e486ecf 100644 --- a/game/game.js +++ b/game/game.js @@ -527,10 +527,12 @@ async function main() { if (MODE === MODE_PLAY) { const game = await Communication.connect(gameId, CLIENT_ID) - Game.newGame(Util.decodeGame(game)) + const gameObject = Util.decodeGame(game) + Game.setGame(gameObject.id, gameObject) } else if (MODE === MODE_REPLAY) { const {game, log} = await Communication.connectReplay(gameId, CLIENT_ID) - Game.newGame(Util.decodeGame(game)) + const gameObject = Util.decodeGame(game) + Game.setGame(gameObject.id, gameObject) REPLAY.log = log REPLAY.lastRealTs = Time.timestamp() REPLAY.gameStartTs = REPLAY.log[0][REPLAY.log[0].length - 1] diff --git a/server/Game.js b/server/Game.js index 0ab527d..ef7dc5c 100644 --- a/server/Game.js +++ b/server/Game.js @@ -40,7 +40,7 @@ function loadGame(gameId) { if (!Array.isArray(game.players)) { game.players = Object.values(game.players) } - GameCommon.newGame({ + const gameObject = { id: game.id, rng: { type: game.rng ? game.rng.type : '_fake_', @@ -50,7 +50,8 @@ function loadGame(gameId) { players: game.players, evtInfos: {}, scoreMode: game.scoreMode || GameCommon.SCORE_MODE_FINAL, - }) + } + GameCommon.setGame(gameObject.id, gameObject) } const changedGames = {} @@ -67,11 +68,12 @@ async function createGameObject(gameId, targetTiles, image, ts, scoreMode) { } } async function createGame(gameId, targetTiles, image, ts, scoreMode) { + const gameObject = await createGameObject(gameId, targetTiles, image, ts, scoreMode) + GameLog.create(gameId) GameLog.log(gameId, Protocol.LOG_HEADER, 1, targetTiles, image, ts, scoreMode) - const gameObject = await createGameObject(gameId, targetTiles, image, ts, scoreMode) - GameCommon.newGame(gameObject) + GameCommon.setGame(gameObject.id, gameObject) changedGames[gameId] = true }