load single game for fixing
This commit is contained in:
parent
709f90b5cf
commit
11e5c08154
2 changed files with 37 additions and 30 deletions
|
|
@ -3,7 +3,7 @@ import GameCommon from '../common/GameCommon.js'
|
||||||
import Game from '../server/Game.js'
|
import Game from '../server/Game.js'
|
||||||
|
|
||||||
function fix_tiles(gameId) {
|
function fix_tiles(gameId) {
|
||||||
Game.loadAllGames()
|
Game.loadGame(gameId)
|
||||||
let changed = false
|
let changed = false
|
||||||
const tiles = GameCommon.getTilesSortedByZIndex(gameId)
|
const tiles = GameCommon.getTilesSortedByZIndex(gameId)
|
||||||
for (let tile of tiles) {
|
for (let tile of tiles) {
|
||||||
|
|
|
||||||
|
|
@ -11,40 +11,46 @@ const DATA_DIR = './../data'
|
||||||
function loadAllGames() {
|
function loadAllGames() {
|
||||||
const files = fs.readdirSync(DATA_DIR)
|
const files = fs.readdirSync(DATA_DIR)
|
||||||
for (const f of files) {
|
for (const f of files) {
|
||||||
if (!f.match(/\.json$/)) {
|
const m = f.match(/^([a-z0-9]+)\.json$/)
|
||||||
|
if (!m) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
const file = `${DATA_DIR}/${f}`
|
const gameId = m[1]
|
||||||
const contents = fs.readFileSync(file, 'utf-8')
|
loadGame(gameId)
|
||||||
let game
|
|
||||||
try {
|
|
||||||
game = JSON.parse(contents)
|
|
||||||
} catch {
|
|
||||||
console.log(`[ERR] unable to load game from file ${f}`);
|
|
||||||
}
|
|
||||||
if (typeof game.puzzle.data.started === 'undefined') {
|
|
||||||
game.puzzle.data.started = Math.round(fs.statSync(file).ctimeMs)
|
|
||||||
}
|
|
||||||
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()
|
|
||||||
}
|
|
||||||
if (!Array.isArray(game.players)) {
|
|
||||||
game.players = Object.values(game.players)
|
|
||||||
}
|
|
||||||
GameCommon.newGame({
|
|
||||||
id: game.id,
|
|
||||||
rng: {
|
|
||||||
type: game.rng ? game.rng.type : '_fake_',
|
|
||||||
obj: game.rng ? Rng.unserialize(game.rng.obj) : new Rng(),
|
|
||||||
},
|
|
||||||
puzzle: game.puzzle,
|
|
||||||
players: game.players,
|
|
||||||
evtInfos: {}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 ${file}`);
|
||||||
|
}
|
||||||
|
if (typeof game.puzzle.data.started === 'undefined') {
|
||||||
|
game.puzzle.data.started = Math.round(fs.statSync(file).ctimeMs)
|
||||||
|
}
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
if (!Array.isArray(game.players)) {
|
||||||
|
game.players = Object.values(game.players)
|
||||||
|
}
|
||||||
|
GameCommon.newGame({
|
||||||
|
id: game.id,
|
||||||
|
rng: {
|
||||||
|
type: game.rng ? game.rng.type : '_fake_',
|
||||||
|
obj: game.rng ? Rng.unserialize(game.rng.obj) : new Rng(),
|
||||||
|
},
|
||||||
|
puzzle: game.puzzle,
|
||||||
|
players: game.players,
|
||||||
|
evtInfos: {}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const changedGames = {}
|
const changedGames = {}
|
||||||
async function createGameObject(gameId, targetTiles, image, ts) {
|
async function createGameObject(gameId, targetTiles, image, ts) {
|
||||||
const seed = Util.hash(gameId + ' ' + ts)
|
const seed = Util.hash(gameId + ' ' + ts)
|
||||||
|
|
@ -130,6 +136,7 @@ function persistGame(gameId) {
|
||||||
export default {
|
export default {
|
||||||
createGameObject,
|
createGameObject,
|
||||||
loadAllGames,
|
loadAllGames,
|
||||||
|
loadGame,
|
||||||
persistChangedGames,
|
persistChangedGames,
|
||||||
persistGame,
|
persistGame,
|
||||||
createGame,
|
createGame,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue