2021-05-22 13:19:39 +02:00
|
|
|
import GameCommon from '../src/common/GameCommon'
|
|
|
|
|
import { logger } from '../src/common/Util'
|
2021-07-12 01:28:14 +02:00
|
|
|
import Db from '../src/server/Db'
|
|
|
|
|
import { DB_FILE, DB_PATCHES_DIR } from '../src/server/Dirs'
|
2021-05-22 13:19:39 +02:00
|
|
|
import GameStorage from '../src/server/GameStorage'
|
2021-04-13 20:18:41 +02:00
|
|
|
|
|
|
|
|
const log = logger('fix_tiles.js')
|
|
|
|
|
|
2021-07-12 01:28:14 +02:00
|
|
|
const db = new Db(DB_FILE, DB_PATCHES_DIR)
|
|
|
|
|
db.patch(true)
|
|
|
|
|
|
2020-12-24 13:56:14 +01:00
|
|
|
function fix_tiles(gameId) {
|
2021-07-12 01:28:14 +02:00
|
|
|
GameStorage.loadGameFromDb(db, gameId)
|
2020-12-24 13:56:14 +01:00
|
|
|
let changed = false
|
2021-05-29 15:36:03 +02:00
|
|
|
const tiles = GameCommon.getPiecesSortedByZIndex(gameId)
|
2020-12-24 13:56:14 +01:00
|
|
|
for (let tile of tiles) {
|
|
|
|
|
if (tile.owner === -1) {
|
2021-05-29 15:36:03 +02:00
|
|
|
const p = GameCommon.getFinalPiecePos(gameId, tile.idx)
|
2020-12-24 13:56:14 +01:00
|
|
|
if (p.x === tile.pos.x && p.y === tile.pos.y) {
|
2021-04-13 20:19:04 +02:00
|
|
|
// log.log('all good', tile.pos)
|
2020-12-24 13:56:14 +01:00
|
|
|
} else {
|
2021-04-13 20:18:41 +02:00
|
|
|
log.log('bad tile pos', tile.pos, 'should be: ', p)
|
2020-12-24 13:56:14 +01:00
|
|
|
tile.pos = p
|
2021-05-29 15:36:03 +02:00
|
|
|
GameCommon.setPiece(gameId, tile.idx, tile)
|
2020-12-24 13:56:14 +01:00
|
|
|
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
|
2021-04-13 20:18:41 +02:00
|
|
|
log.log('unowning tile', tile.idx)
|
2021-05-29 15:36:03 +02:00
|
|
|
GameCommon.setPiece(gameId, tile.idx, tile)
|
2020-12-24 13:58:52 +01:00
|
|
|
changed = true
|
2020-12-24 13:56:14 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (changed) {
|
2021-07-12 01:28:14 +02:00
|
|
|
GameStorage.persistGameToDb(db, gameId)
|
2020-12-24 13:56:14 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fix_tiles(process.argv[2])
|