From 0dcebdd7189b2b6ae65d80c51427f54f130449ce Mon Sep 17 00:00:00 2001 From: Zutatensuppe Date: Mon, 7 Dec 2020 01:16:12 +0100 Subject: [PATCH] fix missing data --- server/Game.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/server/Game.js b/server/Game.js index 6e0ea21..283c600 100644 --- a/server/Game.js +++ b/server/Game.js @@ -1,6 +1,7 @@ import fs from 'fs' import { createPuzzle } from './Puzzle.js' import GameCommon from './../common/GameCommon.js' +import Util from './../common/Util.js' async function createGame(gameId, targetTiles, image) { GameCommon.newGame({ @@ -23,6 +24,13 @@ function loadAllGames() { const file = `${DATA_DIR}/${f}` const contents = fs.readFileSync(file, 'utf-8') const game = JSON.parse(contents) + if (typeof game.puzzle.data.started === 'undefined') { + game.puzzle.data.started = Math.round(fs.statSync(file).atimeMs) + } + if (typeof game.puzzle.data.finished === 'undefined') { + let unfinished = game.puzzle.tiles.map(Util.decodeTile).find(t => t.owner !== -1) + game.puzzle.data.finished = unfinished ? 0 : Util.timestamp() + } GameCommon.newGame({ id: game.id, puzzle: game.puzzle,