load single game for fixing

This commit is contained in:
Zutatensuppe 2020-12-24 14:19:21 +01:00
parent 709f90b5cf
commit 11e5c08154
2 changed files with 37 additions and 30 deletions

View file

@ -3,7 +3,7 @@ import GameCommon from '../common/GameCommon.js'
import Game from '../server/Game.js'
function fix_tiles(gameId) {
Game.loadAllGames()
Game.loadGame(gameId)
let changed = false
const tiles = GameCommon.getTilesSortedByZIndex(gameId)
for (let tile of tiles) {

View file

@ -11,16 +11,23 @@ const DATA_DIR = './../data'
function loadAllGames() {
const files = fs.readdirSync(DATA_DIR)
for (const f of files) {
if (!f.match(/\.json$/)) {
const m = f.match(/^([a-z0-9]+)\.json$/)
if (!m) {
continue
}
const file = `${DATA_DIR}/${f}`
const gameId = m[1]
loadGame(gameId)
}
}
function loadGame(gameId) {
const file = `${DATA_DIR}/${gameId}.json`
const contents = fs.readFileSync(file, 'utf-8')
let game
try {
game = JSON.parse(contents)
} catch {
console.log(`[ERR] unable to load game from file ${f}`);
console.log(`[ERR] unable to load game from file ${file}`);
}
if (typeof game.puzzle.data.started === 'undefined') {
game.puzzle.data.started = Math.round(fs.statSync(file).ctimeMs)
@ -42,7 +49,6 @@ function loadAllGames() {
players: game.players,
evtInfos: {}
})
}
}
const changedGames = {}
@ -130,6 +136,7 @@ function persistGame(gameId) {
export default {
createGameObject,
loadAllGames,
loadGame,
persistChangedGames,
persistGame,
createGame,