From e5a0e2b1de53af84f52579d5e22871f3db8af54e Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Thu, 2 Feb 2017 13:16:32 +0100 Subject: [PATCH] Revert "no longer preload study destinations, as to leverage eval cache" This reverts commit 28103c670bc2efbfcaf09683dc407631e6dddbff. --- app/controllers/Practice.scala | 2 +- app/controllers/Study.scala | 4 ++-- modules/study/src/main/TreeBuilder.scala | 14 +++++++++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/controllers/Practice.scala b/app/controllers/Practice.scala index 61d9568384..2426a5679d 100644 --- a/app/controllers/Practice.scala +++ b/app/controllers/Practice.scala @@ -58,7 +58,7 @@ object Practice extends LilaController { case (baseData, studyJson) => val analysis = baseData ++ Json.obj( "treeParts" -> partitionTreeJsonWriter.writes { - lila.study.TreeBuilder(chapter.root) + lila.study.TreeBuilder(chapter.root, chapter.setup.variant) }, "practiceGoal" -> lila.practice.PracticeGoal(chapter)) (analysis, studyJson) diff --git a/app/controllers/Study.scala b/app/controllers/Study.scala index bf9b422358..ec78596803 100644 --- a/app/controllers/Study.scala +++ b/app/controllers/Study.scala @@ -99,7 +99,7 @@ object Study extends LilaController { study = studyJson, analysis = baseData ++ Json.obj( "treeParts" -> partitionTreeJsonWriter.writes { - lila.study.TreeBuilder(chapter.root) + lila.study.TreeBuilder(chapter.root, chapter.setup.variant) })) res <- negotiate( html = for { @@ -176,7 +176,7 @@ object Study extends LilaController { import lila.tree.Node.partitionTreeJsonWriter val analysis = baseData ++ Json.obj( "treeParts" -> partitionTreeJsonWriter.writes { - lila.study.TreeBuilder(chapter.root) + lila.study.TreeBuilder.makeRoot(chapter.root) }) val data = lila.study.JsonView.JsData( study = studyJson, diff --git a/modules/study/src/main/TreeBuilder.scala b/modules/study/src/main/TreeBuilder.scala index d04fe22a43..0eb5838d36 100644 --- a/modules/study/src/main/TreeBuilder.scala +++ b/modules/study/src/main/TreeBuilder.scala @@ -5,7 +5,19 @@ import lila.tree object TreeBuilder { - def apply(root: Node.Root) = tree.Root( + private val initialStandardDests = chess.Game(chess.variant.Standard).situation.destinations + + def apply(root: Node.Root, variant: chess.variant.Variant) = { + val dests = + if (variant.standard && root.fen.value == chess.format.Forsyth.initial) initialStandardDests + else { + val sit = chess.Game(variant.some, root.fen.value.some).situation + sit.playable(false) ?? sit.destinations + } + makeRoot(root).copy(dests = dests.some) + } + + def makeRoot(root: Node.Root) = tree.Root( ply = root.ply, fen = root.fen.value, check = root.check,