preload study chapter dests
This commit is contained in:
parent
df12aafc74
commit
9308e4d7b3
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue