add script to fix bad tiles
This commit is contained in:
parent
35364c1058
commit
5f890b40f5
3 changed files with 48 additions and 14 deletions
|
|
@ -660,6 +660,7 @@ export default {
|
|||
getFirstOwnedTile,
|
||||
getTileDrawOffset,
|
||||
getTileDrawSize,
|
||||
getFinalTilePos,
|
||||
getStartTs,
|
||||
getFinishTs,
|
||||
handleInput,
|
||||
|
|
|
|||
27
scripts/fix_tiles.js
Normal file
27
scripts/fix_tiles.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import fs from 'fs'
|
||||
import GameCommon from '../common/GameCommon.js'
|
||||
import Game from '../server/Game.js'
|
||||
|
||||
function fix_tiles(gameId) {
|
||||
Game.loadAllGames()
|
||||
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) {
|
||||
console.log('all good', tile.pos)
|
||||
} else {
|
||||
console.log('bad tile pos', tile.pos, 'should be: ', p)
|
||||
tile.pos = p
|
||||
GameCommon.setTile(gameId, tile.idx, tile)
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
Game.persistGame(gameId)
|
||||
}
|
||||
}
|
||||
|
||||
fix_tiles(process.argv[2])
|
||||
|
|
@ -105,9 +105,16 @@ function handleInput(gameId, playerId, input, ts) {
|
|||
}
|
||||
|
||||
function persistChangedGames() {
|
||||
for (const game of GameCommon.getAllGames()) {
|
||||
for (const gameId of Object.keys(changedGames)) {
|
||||
persistGame(gameId)
|
||||
}
|
||||
}
|
||||
|
||||
function persistGame(gameId) {
|
||||
const game = GameCommon.get(gameId)
|
||||
if (game.id in changedGames) {
|
||||
delete changedGames[game.id]
|
||||
}
|
||||
fs.writeFileSync(`${DATA_DIR}/${game.id}.json`, JSON.stringify({
|
||||
id: game.id,
|
||||
rng: {
|
||||
|
|
@ -119,13 +126,12 @@ function persistChangedGames() {
|
|||
}))
|
||||
console.info(`[INFO] persisted game ${game.id}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
createGameObject,
|
||||
loadAllGames,
|
||||
persistChangedGames,
|
||||
persistGame,
|
||||
createGame,
|
||||
addPlayer,
|
||||
handleInput,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue