2016-05-13 16:01:44 -06:00
|
|
|
package views.html.board
|
|
|
|
|
2020-08-16 10:20:56 -06:00
|
|
|
import chess.format.{ FEN, Forsyth }
|
|
|
|
import controllers.routes
|
2017-01-15 05:26:08 -07:00
|
|
|
import play.api.libs.json.Json
|
2016-05-13 16:01:44 -06:00
|
|
|
|
|
|
|
import lila.api.Context
|
|
|
|
import lila.app.templating.Environment._
|
2018-12-04 09:20:16 -07:00
|
|
|
import lila.app.ui.ScalatagsTemplate._
|
2020-08-16 10:20:56 -06:00
|
|
|
import lila.game.Pov
|
2018-12-03 04:48:24 -07:00
|
|
|
|
|
|
|
object bits {
|
2016-05-13 16:01:44 -06:00
|
|
|
|
2020-08-16 10:20:56 -06:00
|
|
|
private val dataState = attr("data-state")
|
|
|
|
|
2020-11-29 04:05:18 -07:00
|
|
|
private def miniOrientation(pov: Pov): chess.Color =
|
|
|
|
if (pov.game.variant == chess.variant.RacingKings) chess.White else pov.player.color
|
2020-11-29 03:23:43 -07:00
|
|
|
|
2020-08-16 10:20:56 -06:00
|
|
|
def mini(pov: Pov): Tag => Tag =
|
2020-11-29 04:05:18 -07:00
|
|
|
mini(
|
|
|
|
FEN(Forsyth.boardAndColor(pov.game.situation)),
|
|
|
|
miniOrientation(pov),
|
|
|
|
~pov.game.lastMoveKeys
|
|
|
|
) _
|
2020-08-16 10:20:56 -06:00
|
|
|
|
|
|
|
def mini(fen: chess.format.FEN, color: chess.Color = chess.White, lastMove: String = "")(tag: Tag): Tag =
|
|
|
|
tag(
|
|
|
|
cls := "mini-board mini-board--init cg-wrap is2d",
|
|
|
|
dataState := s"${fen.value},${color.name},$lastMove"
|
|
|
|
)(cgWrapContent)
|
|
|
|
|
|
|
|
def miniSpan(fen: chess.format.FEN, color: chess.Color = chess.White, lastMove: String = "") =
|
|
|
|
mini(fen, color, lastMove)(span)
|
|
|
|
|
2021-08-09 00:50:40 -06:00
|
|
|
def jsData(fen: Option[String] = None)(implicit ctx: Context) =
|
2021-08-19 01:38:42 -06:00
|
|
|
Json
|
|
|
|
.obj(
|
|
|
|
"baseUrl" -> s"$netBaseUrl${routes.Editor.load("")}",
|
|
|
|
"animation" -> Json.obj("duration" -> ctx.pref.animationMillis),
|
|
|
|
"is3d" -> ctx.pref.is3d,
|
|
|
|
"i18n" -> i18nJsObject(i18nKeyes)
|
|
|
|
)
|
|
|
|
.add("fen" -> fen)
|
2018-12-03 02:39:00 -07:00
|
|
|
|
2021-10-21 12:32:09 -06:00
|
|
|
def explorerConfig(implicit ctx: Context) = Json.obj(
|
2021-10-18 11:20:52 -06:00
|
|
|
"endpoint" -> explorerEndpoint,
|
2021-10-21 12:32:09 -06:00
|
|
|
"tablebaseEndpoint" -> tablebaseEndpoint,
|
|
|
|
"showRatings" -> ctx.pref.showRatings
|
2021-10-18 11:20:52 -06:00
|
|
|
)
|
|
|
|
|
2020-02-12 09:46:59 -07:00
|
|
|
private val i18nKeyes = List(
|
2018-12-03 02:39:00 -07:00
|
|
|
trans.setTheBoard,
|
|
|
|
trans.boardEditor,
|
|
|
|
trans.startPosition,
|
|
|
|
trans.clearBoard,
|
|
|
|
trans.flipBoard,
|
|
|
|
trans.loadPosition,
|
|
|
|
trans.popularOpenings,
|
2021-06-28 10:11:36 -06:00
|
|
|
trans.endgamePositions,
|
2018-12-03 02:39:00 -07:00
|
|
|
trans.castling,
|
|
|
|
trans.whiteCastlingKingside,
|
|
|
|
trans.blackCastlingKingside,
|
|
|
|
trans.whitePlays,
|
|
|
|
trans.blackPlays,
|
|
|
|
trans.variant,
|
|
|
|
trans.continueFromHere,
|
|
|
|
trans.playWithTheMachine,
|
|
|
|
trans.playWithAFriend,
|
2019-12-03 13:23:18 -07:00
|
|
|
trans.analysis,
|
|
|
|
trans.toStudy
|
2020-02-12 09:46:59 -07:00
|
|
|
).map(_.key)
|
2016-05-13 16:01:44 -06:00
|
|
|
}
|