fix import from position without initial FEN -> standard

pull/4131/head
Thibault Duplessis 2018-03-09 20:29:07 -05:00
parent d8b2818ef1
commit f17910a113
2 changed files with 5 additions and 5 deletions

View File

@ -46,7 +46,7 @@ case class ImportData(pgn: String, analyse: Option[String]) {
sans => sans.copy(value = sans.value take maxPlies),
Tags.empty
) map evenIncomplete map {
case replay @ Replay(setup, _, game) =>
case replay @ Replay(setup, _, state) =>
val initBoard = parsed.tags.fen.map(_.value) flatMap Forsyth.<< map (_.board)
val fromPosition = initBoard.nonEmpty && !parsed.tags.fen.contains(FEN(Forsyth.initial))
val variant = {
@ -59,6 +59,7 @@ case class ImportData(pgn: String, analyse: Option[String]) {
case chess.variant.FromPosition if parsed.tags.fen.isEmpty => chess.variant.Standard
case v => v
}
val game = state.copy(situation = state.situation withVariant variant)
val initialFen = parsed.tags.fen.map(_.value) flatMap {
Forsyth.<<<@(variant, _)
} map Forsyth.>> map FEN.apply
@ -87,7 +88,7 @@ case class ImportData(pgn: String, analyse: Option[String]) {
}
val dbGame = Game.make(
chess = replay.state,
chess = game,
whitePlayer = Player.make(chess.White, None) withName name(_.White, _.WhiteElo),
blackPlayer = Player.make(chess.Black, None) withName name(_.Black, _.BlackElo),
mode = Mode.Casual,
@ -95,7 +96,7 @@ case class ImportData(pgn: String, analyse: Option[String]) {
pgnImport = PgnImport.make(user = user, date = date, pgn = pgn).some
).start
Preprocessed(dbGame, replay, result, initialFen, parsed)
Preprocessed(dbGame, replay.copy(state = game), result, initialFen, parsed)
}
}
}

View File

@ -30,8 +30,7 @@ final class Importer(
gameExists {
(data preprocess user).future flatMap {
case Preprocessed(g, replay, result, initialFen, _) =>
val started = forceId.fold(g)(g.withId).start
val game = applyResult(started, result, replay.state.situation)
val game = applyResult(forceId.fold(g)(g.withId), result, replay.state.situation)
(GameRepo.insertDenormalized(game, initialFen = initialFen)) >> {
game.pgnImport.flatMap(_.user).isDefined ?? GameRepo.setImportCreatedAt(game)
} >> {