userAnalysisJson no longer needs to be a future
parent
a48d8bada0
commit
aa1a8aea78
|
@ -70,19 +70,18 @@ object Practice extends LilaController {
|
|||
|
||||
private def analysisJson(us: UserStudy)(implicit ctx: Context): Fu[(JsObject, JsObject)] = us match {
|
||||
case UserStudy(_, _, chapters, WithChapter(study, chapter), _) =>
|
||||
val initialFen = chapter.root.fen.value.some
|
||||
val pov = UserAnalysis.makePov(initialFen, chapter.setup.variant)
|
||||
Env.round.jsonView.userAnalysisJson(pov, ctx.pref, initialFen, chapter.setup.orientation, owner = false, me = ctx.me) zip
|
||||
studyEnv.jsonView(study, chapters, chapter, ctx.me) map {
|
||||
case (baseData, studyJson) =>
|
||||
val analysis = baseData ++ Json.obj(
|
||||
"treeParts" -> partitionTreeJsonWriter.writes {
|
||||
lila.study.TreeBuilder(chapter.root, chapter.setup.variant)
|
||||
},
|
||||
"practiceGoal" -> lila.practice.PracticeGoal(chapter)
|
||||
)
|
||||
(analysis, studyJson)
|
||||
}
|
||||
studyEnv.jsonView(study, chapters, chapter, ctx.me) map { studyJson =>
|
||||
val initialFen = chapter.root.fen.value.some
|
||||
val pov = UserAnalysis.makePov(initialFen, chapter.setup.variant)
|
||||
val baseData = Env.round.jsonView.userAnalysisJson(pov, ctx.pref, initialFen, chapter.setup.orientation, owner = false, me = ctx.me)
|
||||
val analysis = baseData ++ Json.obj(
|
||||
"treeParts" -> partitionTreeJsonWriter.writes {
|
||||
lila.study.TreeBuilder(chapter.root, chapter.setup.variant)
|
||||
},
|
||||
"practiceGoal" -> lila.practice.PracticeGoal(chapter)
|
||||
)
|
||||
(analysis, studyJson)
|
||||
}
|
||||
}
|
||||
|
||||
def complete(chapterId: String, nbMoves: Int) = Auth { implicit ctx => me =>
|
||||
|
|
|
@ -94,7 +94,7 @@ object Study extends LilaController {
|
|||
_ = if (HTTPRequest isSynchronousHttp ctx.req) env.studyRepo.incViews(study)
|
||||
initialFen = chapter.root.fen.value.some
|
||||
pov = UserAnalysis.makePov(initialFen, chapter.setup.variant)
|
||||
baseData <- Env.round.jsonView.userAnalysisJson(pov, ctx.pref, initialFen, chapter.setup.orientation, owner = false, me = ctx.me)
|
||||
baseData = Env.round.jsonView.userAnalysisJson(pov, ctx.pref, initialFen, chapter.setup.orientation, owner = false, me = ctx.me)
|
||||
studyJson <- env.jsonView(study, chapters, chapter, ctx.me)
|
||||
data = lila.study.JsonView.JsData(
|
||||
study = studyJson,
|
||||
|
@ -196,32 +196,28 @@ object Study extends LilaController {
|
|||
env.api.byIdWithChapter(id, chapterId) flatMap {
|
||||
_.fold(embedNotFound) {
|
||||
case WithChapter(study, chapter) => CanViewResult(study) {
|
||||
val setup = chapter.setup
|
||||
val initialFen = chapter.root.fen.value.some
|
||||
val pov = UserAnalysis.makePov(initialFen, setup.variant)
|
||||
Env.round.jsonView.userAnalysisJson(pov, ctx.pref, initialFen, setup.orientation, owner = false, me = ctx.me) zip
|
||||
env.jsonView(study.copy(
|
||||
members = lila.study.StudyMembers(Map.empty) // don't need no members
|
||||
), List(chapter.metadata), chapter, ctx.me) flatMap {
|
||||
case (baseData, studyJson) =>
|
||||
import lila.tree.Node.partitionTreeJsonWriter
|
||||
val analysis = baseData ++ Json.obj(
|
||||
"treeParts" -> partitionTreeJsonWriter.writes {
|
||||
lila.study.TreeBuilder.makeRoot(chapter.root)
|
||||
}
|
||||
)
|
||||
val data = lila.study.JsonView.JsData(
|
||||
study = studyJson,
|
||||
analysis = analysis
|
||||
)
|
||||
negotiate(
|
||||
html = Ok(html.study.embed(study, chapter, data)).fuccess,
|
||||
api = _ => Ok(Json.obj(
|
||||
"study" -> data.study,
|
||||
"analysis" -> data.analysis
|
||||
)).fuccess
|
||||
)
|
||||
}
|
||||
env.jsonView(study.copy(
|
||||
members = lila.study.StudyMembers(Map.empty) // don't need no members
|
||||
), List(chapter.metadata), chapter, ctx.me) flatMap { studyJson =>
|
||||
val setup = chapter.setup
|
||||
val initialFen = chapter.root.fen.value.some
|
||||
val pov = UserAnalysis.makePov(initialFen, setup.variant)
|
||||
val baseData = Env.round.jsonView.userAnalysisJson(pov, ctx.pref, initialFen, setup.orientation, owner = false, me = ctx.me)
|
||||
import lila.tree.Node.partitionTreeJsonWriter
|
||||
val analysis = baseData ++ Json.obj(
|
||||
"treeParts" -> partitionTreeJsonWriter.writes {
|
||||
lila.study.TreeBuilder.makeRoot(chapter.root)
|
||||
}
|
||||
)
|
||||
val data = lila.study.JsonView.JsData(
|
||||
study = studyJson,
|
||||
analysis = analysis
|
||||
)
|
||||
negotiate(
|
||||
html = Ok(html.study.embed(study, chapter, data)).fuccess,
|
||||
api = _ => Ok(Json.obj("study" -> data.study, "analysis" -> data.analysis)).fuccess
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
} map NoCache
|
||||
|
|
|
@ -93,15 +93,18 @@ private[api] final class RoundApi(
|
|||
}
|
||||
|
||||
def userAnalysisJson(pov: Pov, pref: Pref, initialFen: Option[String], orientation: chess.Color, owner: Boolean, me: Option[User]) =
|
||||
owner.??(forecastApi loadForDisplay pov).flatMap { fco =>
|
||||
jsonView.userAnalysisJson(pov, pref, initialFen, orientation, owner = owner, me = me) map
|
||||
withTree(pov, analysis = none, initialFen, WithFlags(opening = true))_ map
|
||||
withForecast(pov, owner, fco)_
|
||||
owner.??(forecastApi loadForDisplay pov).map { fco =>
|
||||
withForecast(pov, owner, fco)(
|
||||
withTree(pov, analysis = none, initialFen, WithFlags(opening = true))(
|
||||
jsonView.userAnalysisJson(pov, pref, initialFen, orientation, owner = owner, me = me)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def freeStudyJson(pov: Pov, pref: Pref, initialFen: Option[String], orientation: chess.Color, me: Option[User]) =
|
||||
jsonView.userAnalysisJson(pov, pref, initialFen, orientation, owner = false, me = me) map
|
||||
withTree(pov, analysis = none, initialFen, WithFlags(opening = true))_
|
||||
withTree(pov, analysis = none, initialFen, WithFlags(opening = true))(
|
||||
jsonView.userAnalysisJson(pov, pref, initialFen, orientation, owner = false, me = me)
|
||||
)
|
||||
|
||||
private def withTree(pov: Pov, analysis: Option[Analysis], initialFen: Option[String], withFlags: WithFlags)(obj: JsObject) =
|
||||
obj + ("treeParts" -> partitionTreeJsonWriter.writes(lila.round.TreeBuilder(
|
||||
|
|
|
@ -56,7 +56,7 @@ private[api] final class RoundApiBalancer(
|
|||
case UserAnalysis(pov, pref, initialFen, orientation, owner, me) =>
|
||||
api.userAnalysisJson(pov, pref, initialFen, orientation, owner, me)
|
||||
case FreeStudy(pov, pref, initialFen, orientation, me) =>
|
||||
api.freeStudyJson(pov, pref, initialFen, orientation, me)
|
||||
fuccess(api.freeStudyJson(pov, pref, initialFen, orientation, me))
|
||||
}
|
||||
})), "api.round.router"
|
||||
)
|
||||
|
|
|
@ -221,44 +221,43 @@ final class JsonView(
|
|||
orientation: chess.Color,
|
||||
owner: Boolean,
|
||||
me: Option[User]
|
||||
) =
|
||||
fuccess {
|
||||
import pov._
|
||||
val fen = Forsyth >> game.toChess
|
||||
Json.obj(
|
||||
"game" -> Json.obj(
|
||||
"id" -> gameId,
|
||||
"variant" -> game.variant,
|
||||
"opening" -> game.opening,
|
||||
"initialFen" -> (initialFen | game.variant.initialFen),
|
||||
"fen" -> fen,
|
||||
"turns" -> game.turns,
|
||||
"player" -> game.turnColor.name,
|
||||
"status" -> game.status
|
||||
),
|
||||
"player" -> Json.obj(
|
||||
"id" -> owner.option(pov.playerId),
|
||||
"color" -> color.name
|
||||
),
|
||||
"opponent" -> Json.obj(
|
||||
"color" -> opponent.color.name,
|
||||
"ai" -> opponent.aiLevel
|
||||
),
|
||||
"orientation" -> orientation.name,
|
||||
"pref" -> Json.obj(
|
||||
"blindfold" -> pref.isBlindfold,
|
||||
"animationDuration" -> animationDuration(pov, pref),
|
||||
"highlight" -> pref.highlight,
|
||||
"destination" -> pref.destination,
|
||||
"coords" -> pref.coords,
|
||||
"rookCastle" -> (pref.rookCastle == Pref.RookCastle.YES),
|
||||
"is3d" -> pref.is3d
|
||||
),
|
||||
"path" -> pov.game.turns,
|
||||
"userAnalysis" -> true,
|
||||
"evalPut" -> JsBoolean(me.??(evalCache.shouldPut))
|
||||
)
|
||||
}
|
||||
) = {
|
||||
import pov._
|
||||
val fen = Forsyth >> game.toChess
|
||||
Json.obj(
|
||||
"game" -> Json.obj(
|
||||
"id" -> gameId,
|
||||
"variant" -> game.variant,
|
||||
"opening" -> game.opening,
|
||||
"initialFen" -> (initialFen | game.variant.initialFen),
|
||||
"fen" -> fen,
|
||||
"turns" -> game.turns,
|
||||
"player" -> game.turnColor.name,
|
||||
"status" -> game.status
|
||||
),
|
||||
"player" -> Json.obj(
|
||||
"id" -> owner.option(pov.playerId),
|
||||
"color" -> color.name
|
||||
),
|
||||
"opponent" -> Json.obj(
|
||||
"color" -> opponent.color.name,
|
||||
"ai" -> opponent.aiLevel
|
||||
),
|
||||
"orientation" -> orientation.name,
|
||||
"pref" -> Json.obj(
|
||||
"blindfold" -> pref.isBlindfold,
|
||||
"animationDuration" -> animationDuration(pov, pref),
|
||||
"highlight" -> pref.highlight,
|
||||
"destination" -> pref.destination,
|
||||
"coords" -> pref.coords,
|
||||
"rookCastle" -> (pref.rookCastle == Pref.RookCastle.YES),
|
||||
"is3d" -> pref.is3d
|
||||
),
|
||||
"path" -> pov.game.turns,
|
||||
"userAnalysis" -> true,
|
||||
"evalPut" -> JsBoolean(me.??(evalCache.shouldPut))
|
||||
)
|
||||
}
|
||||
|
||||
private def gameJson(game: Game, initialFen: Option[String]) = Json.obj(
|
||||
"id" -> game.id,
|
||||
|
|
Loading…
Reference in New Issue