2020-12-24 13:56:14 +01:00
|
|
|
import fs from 'fs'
|
|
|
|
|
import GameCommon from '../common/GameCommon.js'
|
|
|
|
|
import Game from '../server/Game.js'
|
|
|
|
|
|
|
|
|
|
function fix_tiles(gameId) {
|
2020-12-24 14:19:21 +01:00
|
|
|
Game.loadGame(gameId)
|
2020-12-24 13:56:14 +01:00
|
|
|
let changed = false
|
|
|
|
|
const tiles = GameCommon.getTilesSortedByZIndex(gameId)
|
|
|
|
|
for (let tile of tiles) {
|
|
|
|
|
if (tile.owner === -1) {
|
|
|
|
|
const p = GameCommon.getFinalTilePos(gameId, tile.idx)
|
|
|
|
|
if (p.x === tile.pos.x && p.y === tile.pos.y) {
|
2020-12-24 14:00:21 +01:00
|
|
|
// console.log('all good', tile.pos)
|
2020-12-24 13:56:14 +01:00
|
|
|
} else {
|
|
|
|
|
console.log('bad tile pos', tile.pos, 'should be: ', p)
|
|
|
|
|
tile.pos = p
|
|
|
|
|
GameCommon.setTile(gameId, tile.idx, tile)
|
|
|
|
|
changed = true
|
|
|
|
|
}
|
2020-12-24 14:00:21 +01:00
|
|
|
} else if (tile.owner !== 0) {
|
2020-12-24 13:58:52 +01:00
|
|
|
tile.owner = 0
|
|
|
|
|
console.log('unowning tile', tile.idx)
|
|
|
|
|
GameCommon.setTile(gameId, tile.idx, tile)
|
|
|
|
|
changed = true
|
2020-12-24 13:56:14 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (changed) {
|
|
|
|
|
Game.persistGame(gameId)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fix_tiles(process.argv[2])
|