preload study chapter dests

This commit is contained in:
Thibault Duplessis 2017-01-23 11:04:37 +01:00
parent df12aafc74
commit 9308e4d7b3
3 changed files with 23 additions and 5 deletions

View file

@ -29,7 +29,9 @@ object Practice extends LilaController {
case (baseData, studyJson) =>
import lila.tree.Node.partitionTreeJsonWriter
val analysis = baseData ++ Json.obj(
"treeParts" -> partitionTreeJsonWriter.writes(lila.study.TreeBuilder(chapter.root)))
"treeParts" -> partitionTreeJsonWriter.writes {
lila.study.TreeBuilder(chapter.root, chapter.setup.variant)
})
val data = lila.practice.JsonView.JsData(
study = studyJson,
analysis = analysis,

View file

@ -97,7 +97,9 @@ object Study extends LilaController {
case (((baseData, chat), studyJson), sVersion) =>
import lila.tree.Node.partitionTreeJsonWriter
val analysis = baseData ++ Json.obj(
"treeParts" -> partitionTreeJsonWriter.writes(lila.study.TreeBuilder(chapter.root)))
"treeParts" -> partitionTreeJsonWriter.writes {
lila.study.TreeBuilder(chapter.root, chapter.setup.variant)
})
val data = lila.study.JsonView.JsData(
study = studyJson,
analysis = analysis)
@ -174,7 +176,9 @@ object Study extends LilaController {
case (baseData, studyJson) =>
import lila.tree.Node.partitionTreeJsonWriter
val analysis = baseData ++ Json.obj(
"treeParts" -> partitionTreeJsonWriter.writes(lila.study.TreeBuilder(chapter.root)))
"treeParts" -> partitionTreeJsonWriter.writes {
lila.study.TreeBuilder.makeRoot(chapter.root)
})
val data = lila.study.JsonView.JsData(
study = studyJson,
analysis = analysis)

View file

@ -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,
@ -29,6 +41,6 @@ object TreeBuilder {
children = toBranches(node.children),
opening = FullOpeningDB findByFen node.fen.value)
private def toBranches(children: Node.Children) =
private def toBranches(children: Node.Children): List[tree.Branch] =
children.nodes.toList.map(toBranch)
}