no longer store pgn storage format in Game
This commit is contained in:
parent
3c197e0f26
commit
895c677049
|
@ -89,9 +89,6 @@ object BSONHandlers {
|
|||
val createdAt = r date F.createdAt
|
||||
val status = r.get[Status](F.status)
|
||||
|
||||
val pgnFormat =
|
||||
if (r contains F.huffmanPgn) PgnStorage.Huffman else PgnStorage.OldBin
|
||||
|
||||
lila.mon.game.fetch()
|
||||
|
||||
val loadChess: () => chess.Game = () => {
|
||||
|
@ -148,7 +145,6 @@ object BSONHandlers {
|
|||
bb <- r bytesO F.blackClockHistory
|
||||
history <- BinaryFormat.clockHistory.read(clk.limit, bw, bb, (status == Status.Outoftime).option(turnColor))
|
||||
} yield history,
|
||||
pgnStorage = pgnFormat,
|
||||
status = status,
|
||||
daysPerTurn = r intO F.daysPerTurn,
|
||||
binaryMoveTimes = r bytesO F.moveTimes,
|
||||
|
@ -195,8 +191,11 @@ object BSONHandlers {
|
|||
F.tvAt -> o.metadata.tvAt.map(w.date),
|
||||
F.analysed -> w.boolO(o.metadata.analysed)
|
||||
) ++ {
|
||||
o.pgnStorage match {
|
||||
case f @ PgnStorage.OldBin => $doc(
|
||||
if (o.variant.standard)
|
||||
$doc(F.huffmanPgn -> PgnStorage.Huffman.encode(o.pgnMoves take Game.maxPlies))
|
||||
else {
|
||||
val f = PgnStorage.OldBin
|
||||
$doc(
|
||||
F.oldPgn -> f.encode(o.pgnMoves take Game.maxPlies),
|
||||
F.binaryPieces -> BinaryFormat.piece.write(o.board.pieces),
|
||||
F.positionHashes -> o.history.positionHashes,
|
||||
|
@ -205,13 +204,9 @@ object BSONHandlers {
|
|||
castles = o.history.castles,
|
||||
lastMove = o.history.lastMove
|
||||
)),
|
||||
// since variants are always OldBin
|
||||
F.checkCount -> o.history.checkCount.nonEmpty.option(o.history.checkCount),
|
||||
F.crazyData -> o.board.crazyData
|
||||
)
|
||||
case f @ PgnStorage.Huffman => $doc(
|
||||
F.huffmanPgn -> f.encode(o.pgnMoves take Game.maxPlies)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ case class Game(
|
|||
blackPlayer: Player,
|
||||
loadChess: () => ChessGame,
|
||||
loadClockHistory: () => Option[ClockHistory] = () => Some(ClockHistory()),
|
||||
pgnStorage: PgnStorage,
|
||||
status: Status,
|
||||
daysPerTurn: Option[Int],
|
||||
binaryMoveTimes: Option[ByteArray] = None,
|
||||
|
@ -640,7 +639,6 @@ object Game {
|
|||
whitePlayer = whitePlayer,
|
||||
blackPlayer = blackPlayer,
|
||||
loadChess = () => chess,
|
||||
pgnStorage = PgnStorage(chess.situation.board.variant, List(whitePlayer.userId, blackPlayer.userId).flatten),
|
||||
status = Status.Created,
|
||||
daysPerTurn = daysPerTurn,
|
||||
mode = mode,
|
||||
|
|
|
@ -55,20 +55,19 @@ private[game] object GameDiff {
|
|||
|
||||
val w = lila.db.BSON.writer
|
||||
|
||||
a.pgnStorage match {
|
||||
case f @ PgnStorage.OldBin =>
|
||||
d(oldPgn, _.pgnMoves, writeBytes compose f.encode)
|
||||
d(binaryPieces, _.board.pieces, writeBytes compose BinaryFormat.piece.write)
|
||||
d(positionHashes, _.history.positionHashes, w.bytes)
|
||||
d(unmovedRooks, _.history.unmovedRooks, writeBytes compose BinaryFormat.unmovedRooks.write)
|
||||
d(castleLastMove, makeCastleLastMove, CastleLastMove.castleLastMoveBSONHandler.write)
|
||||
// since variants are always OldBin
|
||||
if (a.variant.threeCheck)
|
||||
dOpt(checkCount, _.history.checkCount, (o: CheckCount) => o.nonEmpty option { BSONHandlers.checkCountWriter write o })
|
||||
if (a.variant.crazyhouse)
|
||||
dOpt(crazyData, _.board.crazyData, (o: Option[chess.variant.Crazyhouse.Data]) => o map BSONHandlers.crazyhouseDataBSONHandler.write)
|
||||
case f @ PgnStorage.Huffman =>
|
||||
d(huffmanPgn, _.pgnMoves, writeBytes compose f.encode)
|
||||
if (a.variant.standard) d(huffmanPgn, _.pgnMoves, writeBytes compose PgnStorage.Huffman.encode)
|
||||
else {
|
||||
val f = PgnStorage.OldBin
|
||||
d(oldPgn, _.pgnMoves, writeBytes compose f.encode)
|
||||
d(binaryPieces, _.board.pieces, writeBytes compose BinaryFormat.piece.write)
|
||||
d(positionHashes, _.history.positionHashes, w.bytes)
|
||||
d(unmovedRooks, _.history.unmovedRooks, writeBytes compose BinaryFormat.unmovedRooks.write)
|
||||
d(castleLastMove, makeCastleLastMove, CastleLastMove.castleLastMoveBSONHandler.write)
|
||||
// since variants are always OldBin
|
||||
if (a.variant.threeCheck)
|
||||
dOpt(checkCount, _.history.checkCount, (o: CheckCount) => o.nonEmpty option { BSONHandlers.checkCountWriter write o })
|
||||
if (a.variant.crazyhouse)
|
||||
dOpt(crazyData, _.board.crazyData, (o: Option[chess.variant.Crazyhouse.Data]) => o map BSONHandlers.crazyhouseDataBSONHandler.write)
|
||||
}
|
||||
d(turns, _.turns, w.int)
|
||||
dOpt(moveTimes, _.binaryMoveTimes, (o: Option[ByteArray]) => o map ByteArrayBSONHandler.write)
|
||||
|
|
Loading…
Reference in a new issue