fix older replays
This commit is contained in:
parent
d009f84156
commit
2b0dc392da
10 changed files with 105 additions and 54 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import fs from 'fs'
|
||||
import Protocol from '../common/Protocol'
|
||||
import Time from '../common/Time'
|
||||
import { Timestamp } from '../common/Types'
|
||||
import { DefaultScoreMode, DefaultShapeMode, DefaultSnapMode, Timestamp } from '../common/Types'
|
||||
import { logger } from './../common/Util'
|
||||
import { DATA_DIR } from './../server/Dirs'
|
||||
|
||||
|
|
@ -82,10 +82,16 @@ const get = (
|
|||
return []
|
||||
}
|
||||
|
||||
const log = fs.readFileSync(file, 'utf-8').split("\n")
|
||||
return log.filter(line => !!line).map(line => {
|
||||
const lines = fs.readFileSync(file, 'utf-8').split("\n")
|
||||
const log = lines.filter(line => !!line).map(line => {
|
||||
return JSON.parse(`[${line}]`)
|
||||
})
|
||||
if (offset === 0 && log.length > 0) {
|
||||
log[0][5] = DefaultScoreMode(log[0][5])
|
||||
log[0][6] = DefaultShapeMode(log[0][6])
|
||||
log[0][7] = DefaultSnapMode(log[0][7])
|
||||
}
|
||||
return log
|
||||
}
|
||||
|
||||
export default {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import fs from 'fs'
|
||||
import GameCommon from './../common/GameCommon'
|
||||
import { Game, Piece, ScoreMode, ShapeMode, SnapMode } from './../common/Types'
|
||||
import { DefaultScoreMode, DefaultShapeMode, DefaultSnapMode, Game, Piece } from './../common/Types'
|
||||
import Util, { logger } from './../common/Util'
|
||||
import { Rng } from './../common/Rng'
|
||||
import { DATA_DIR } from './Dirs'
|
||||
|
|
@ -58,9 +58,9 @@ function loadGame(gameId: string): void {
|
|||
puzzle: game.puzzle,
|
||||
players: game.players,
|
||||
evtInfos: {},
|
||||
scoreMode: game.scoreMode || ScoreMode.FINAL,
|
||||
shapeMode: game.shapeMode || ShapeMode.ANY,
|
||||
snapMode: game.snapMode || SnapMode.NORMAL,
|
||||
scoreMode: DefaultScoreMode(game.scoreMode),
|
||||
shapeMode: DefaultShapeMode(game.shapeMode),
|
||||
snapMode: DefaultSnapMode(game.snapMode),
|
||||
}
|
||||
GameCommon.setGame(gameObject.id, gameObject)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,9 +89,9 @@ app.get('/api/replay-data', async (req, res): Promise<void> => {
|
|||
log[0][2],
|
||||
log[0][3],
|
||||
log[0][4],
|
||||
log[0][5] || ScoreMode.FINAL,
|
||||
log[0][6] || ShapeMode.NORMAL,
|
||||
log[0][7] || SnapMode.NORMAL,
|
||||
log[0][5],
|
||||
log[0][6],
|
||||
log[0][7],
|
||||
)
|
||||
}
|
||||
res.send({ log, game: game ? Util.encodeGame(game) : null })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue