open explorer games not at ply, but at FEN

This commit is contained in:
Thibault Duplessis 2016-02-15 18:04:17 +07:00
parent 094902c651
commit 2a9b959326
4 changed files with 49 additions and 34 deletions

View file

@ -64,30 +64,46 @@ object Analyse extends LilaController {
def replay(pov: Pov, userTv: Option[lila.user.User])(implicit ctx: Context) =
if (HTTPRequest isBot ctx.req) replayBot(pov)
else GameRepo initialFen pov.game.id flatMap { initialFen =>
(env.analyser get pov.game.id) zip
(pov.game.simulId ?? Env.simul.repo.find) zip
Env.game.crosstableApi(pov.game) flatMap {
case ((analysis, simul), crosstable) =>
val pgn = Env.api.pgnDump(pov.game, initialFen)
Env.api.roundApi.watcher(pov, lila.api.Mobile.Api.currentVersion,
tv = none,
analysis.map(pgn -> _),
initialFenO = initialFen.some,
withMoveTimes = true) map { data =>
Ok(html.analyse.replay(
pov,
data,
initialFen,
Env.analyse.annotator(pgn, analysis, pov.game.opening, pov.game.winnerColor, pov.game.status, pov.game.clock).toString,
analysis,
analysis filter (_.done) map { a => AdvantageChart(a.infoAdvices, pov.game.pgnMoves, pov.game.startedAtTurn) },
simul,
new TimeChart(pov.game, pov.game.pgnMoves),
crosstable,
userTv,
divider(pov.game, initialFen)))
}
}
RedirectAtFen(pov, initialFen) {
(env.analyser get pov.game.id) zip
(pov.game.simulId ?? Env.simul.repo.find) zip
Env.game.crosstableApi(pov.game) flatMap {
case ((analysis, simul), crosstable) =>
val pgn = Env.api.pgnDump(pov.game, initialFen)
Env.api.roundApi.watcher(pov, lila.api.Mobile.Api.currentVersion,
tv = none,
analysis.map(pgn -> _),
initialFenO = initialFen.some,
withMoveTimes = true) map { data =>
Ok(html.analyse.replay(
pov,
data,
initialFen,
Env.analyse.annotator(pgn, analysis, pov.game.opening, pov.game.winnerColor, pov.game.status, pov.game.clock).toString,
analysis,
analysis filter (_.done) map { a => AdvantageChart(a.infoAdvices, pov.game.pgnMoves, pov.game.startedAtTurn) },
simul,
new TimeChart(pov.game, pov.game.pgnMoves),
crosstable,
userTv,
divider(pov.game, initialFen)))
}
}
}
}
private def RedirectAtFen(pov: Pov, initialFen: Option[String])(or: => Fu[Result])(implicit ctx: Context) =
get("fen").fold(or) { atFen =>
val url = routes.Round.watcher(pov.gameId, pov.color.name)
fuccess {
chess.Replay.plyAtFen(pov.game.pgnMoves, initialFen, pov.game.variant, atFen).fold(
err => {
// loginfo(s"RedirectAtFen: $err")
println(s"RedirectAtFen: $err")
Redirect(url)
},
ply => Redirect(s"$url#$ply"))
}
}
private def replayBot(pov: Pov)(implicit ctx: Context) =

View file

@ -40,19 +40,18 @@ object Importer extends LilaController {
}
def masterGame(id: String, orientation: String) = Open { implicit ctx =>
def redirectAtFen(game: lila.game.Game) = Redirect {
val url = routes.Round.watcher(game.id, orientation).url
s"$url?fen=${~get("fen")}"
}
lila.game.GameRepo game id flatMap {
case Some(game) => fuccess(Redirect(routes.Round.watcher(game.id, game.firstPlayer.color.name)))
case Some(game) => fuccess(redirectAtFen(game))
case _ => Env.explorer.fetchPgn(id) flatMap {
case None => fuccess(NotFound)
case Some(pgn) => env.importer(
lila.importer.ImportData(pgn, none),
user = "lichess".some,
forceId = id.some) map { game =>
Redirect {
val url = routes.Round.watcher(game.id, orientation).url
s"$url#${~getInt("ply")}"
}
}
forceId = id.some) map redirectAtFen
}
}
}

@ -1 +1 @@
Subproject commit aa3ca3018378579ed4ca58093633e77af6766dce
Subproject commit 18edd6eb2de3b408506ff7df194d73fcb8fce3a7

View file

@ -87,9 +87,9 @@ function showGameTable(ctrl, type, games) {
if (!$tr.length) return;
var orientation = ctrl.chessground.data.orientation;
if (ctrl.explorer.config.data.db.selected() === 'lichess')
window.open('/' + $tr.data('id') + '/' + orientation + '#' + ctrl.vm.step.ply, '_blank');
window.open('/' + $tr.data('id') + '/' + orientation + '?fen=' + ctrl.vm.step.fen, '_blank');
else
window.open('/import/master/' + $tr.data('id') + '/' + orientation + '?ply=' + ctrl.vm.step.ply, '_blank');
window.open('/import/master/' + $tr.data('id') + '/' + orientation + '?fen=' + ctrl.vm.step.fen, '_blank');
}
}, games.map(function(game) {
return m('tr', {