remove confusing newGame function

This commit is contained in:
Zutatensuppe 2021-04-30 01:03:43 +02:00
parent 7e0bb8357d
commit 85e9d14b02
4 changed files with 12 additions and 21 deletions

View file

@ -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,

View file

@ -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,

View file

@ -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]

View file

@ -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
}