simplify and normalize piece animation duration
parent
2a1bd9ecb0
commit
2131036e74
|
@ -35,8 +35,7 @@ final class Editor(env: Env) extends LilaController(env) {
|
|||
html.board.editor(
|
||||
sit = situation,
|
||||
fen = Forsyth >> situation,
|
||||
positionsJson,
|
||||
animationDuration = env.api.config.editorAnimationDuration
|
||||
positionsJson
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -49,8 +48,7 @@ final class Editor(env: Env) extends LilaController(env) {
|
|||
Ok(
|
||||
html.board.bits.jsData(
|
||||
sit = situation,
|
||||
fen = Forsyth >> situation,
|
||||
animationDuration = env.api.config.editorAnimationDuration
|
||||
fen = Forsyth >> situation
|
||||
)
|
||||
) as JSON
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package views.html.board
|
|||
import chess.format.{ FEN, Forsyth }
|
||||
import controllers.routes
|
||||
import play.api.libs.json.Json
|
||||
import scala.concurrent.duration.Duration
|
||||
|
||||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
|
@ -28,8 +27,7 @@ object bits {
|
|||
|
||||
def jsData(
|
||||
sit: chess.Situation,
|
||||
fen: FEN,
|
||||
animationDuration: Duration
|
||||
fen: FEN
|
||||
)(implicit ctx: Context) =
|
||||
Json.obj(
|
||||
"fen" -> fen.value.split(" ").take(4).mkString(" "),
|
||||
|
@ -41,11 +39,9 @@ object bits {
|
|||
"k" -> (sit canCastle chess.Black on chess.KingSide),
|
||||
"q" -> (sit canCastle chess.Black on chess.QueenSide)
|
||||
),
|
||||
"animation" -> Json.obj(
|
||||
"duration" -> ctx.pref.animationFactor * animationDuration.toMillis
|
||||
),
|
||||
"is3d" -> ctx.pref.is3d,
|
||||
"i18n" -> i18nJsObject(i18nKeyes)
|
||||
"animation" -> Json.obj("duration" -> ctx.pref.animationMillis),
|
||||
"is3d" -> ctx.pref.is3d,
|
||||
"i18n" -> i18nJsObject(i18nKeyes)
|
||||
)
|
||||
|
||||
private val i18nKeyes = List(
|
||||
|
|
|
@ -13,15 +13,14 @@ object editor {
|
|||
def apply(
|
||||
sit: chess.Situation,
|
||||
fen: FEN,
|
||||
positionsJson: String,
|
||||
animationDuration: scala.concurrent.duration.Duration
|
||||
positionsJson: String
|
||||
)(implicit ctx: Context) =
|
||||
views.html.base.layout(
|
||||
title = trans.boardEditor.txt(),
|
||||
moreJs = frag(
|
||||
jsModule("editor"),
|
||||
embedJsUnsafeLoadThen(
|
||||
s"""const data=${safeJsonValue(bits.jsData(sit, fen, animationDuration))};data.positions=$positionsJson;
|
||||
s"""const data=${safeJsonValue(bits.jsData(sit, fen))};data.positions=$positionsJson;
|
||||
LichessEditor(document.getElementById('board-editor'), data);"""
|
||||
)
|
||||
),
|
||||
|
|
|
@ -82,14 +82,6 @@ api {
|
|||
env = "dev"
|
||||
}
|
||||
}
|
||||
chessground {
|
||||
animation {
|
||||
duration = 250 ms
|
||||
}
|
||||
}
|
||||
editor {
|
||||
animation.duration = ${chessground.animation.duration}
|
||||
}
|
||||
accessibility {
|
||||
blind {
|
||||
cookie {
|
||||
|
@ -128,7 +120,6 @@ puzzle {
|
|||
round = puzzle2_round
|
||||
path = puzzle2_path
|
||||
}
|
||||
animation.duration = ${chessground.animation.duration}
|
||||
}
|
||||
coordinate {
|
||||
collection {
|
||||
|
@ -348,7 +339,6 @@ gameSearch {
|
|||
actor.name = game-search
|
||||
}
|
||||
round {
|
||||
animation.duration = ${chessground.animation.duration}
|
||||
moretime = 15 seconds
|
||||
collection {
|
||||
note = game_note
|
||||
|
|
|
@ -10,7 +10,6 @@ final class ApiConfig(
|
|||
val influxEventEnv: String,
|
||||
val isStage: Boolean,
|
||||
val prismicApiUrl: String,
|
||||
val editorAnimationDuration: FiniteDuration,
|
||||
val explorerEndpoint: String,
|
||||
val tablebaseEndpoint: String,
|
||||
val accessibility: ApiConfig.Accessibility
|
||||
|
@ -36,7 +35,6 @@ object ApiConfig {
|
|||
c.get[String]("api.influx_event.env"),
|
||||
c.get[Boolean]("app.stage"),
|
||||
c.get[String]("prismic.api_url"),
|
||||
c.get[FiniteDuration]("editor.animation.duration"),
|
||||
c.get[String]("explorer.endpoint"),
|
||||
c.get[String]("explorer.tablebase.endpoint"),
|
||||
new Accessibility(
|
||||
|
|
|
@ -10,5 +10,5 @@ final class Env(
|
|||
db: lila.db.Db
|
||||
)(implicit ec: scala.concurrent.ExecutionContext) {
|
||||
|
||||
lazy val api = new PrefApi(db(CollName("pref")), cacheApi)
|
||||
val api = new PrefApi(db(CollName("pref")), cacheApi)
|
||||
}
|
||||
|
|
|
@ -90,13 +90,13 @@ case class Pref(
|
|||
case _ => none
|
||||
}
|
||||
|
||||
def animationFactor =
|
||||
def animationMillis: Int =
|
||||
animation match {
|
||||
case Animation.NONE => 0
|
||||
case Animation.FAST => 0.5f
|
||||
case Animation.NORMAL => 1
|
||||
case Animation.SLOW => 2
|
||||
case _ => 1
|
||||
case Animation.FAST => 120
|
||||
case Animation.NORMAL => 250
|
||||
case Animation.SLOW => 500
|
||||
case _ => 250
|
||||
}
|
||||
|
||||
def isBlindfold = blindfold == Pref.Blindfold.YES
|
||||
|
|
|
@ -13,8 +13,7 @@ private class PuzzleConfig(
|
|||
@ConfigName("mongodb.uri") val mongoUri: String,
|
||||
@ConfigName("collection.puzzle") val puzzleColl: CollName,
|
||||
@ConfigName("collection.round") val roundColl: CollName,
|
||||
@ConfigName("collection.path") val pathColl: CollName,
|
||||
@ConfigName("animation.duration") val animationDuration: FiniteDuration
|
||||
@ConfigName("collection.path") val pathColl: CollName
|
||||
)
|
||||
|
||||
case class PuzzleColls(
|
||||
|
|
|
@ -12,8 +12,7 @@ import lila.user.User
|
|||
|
||||
final class JsonView(
|
||||
gameJson: GameJson,
|
||||
gameRepo: GameRepo,
|
||||
animationDuration: scala.concurrent.duration.Duration
|
||||
gameRepo: GameRepo
|
||||
)(implicit ec: scala.concurrent.ExecutionContext) {
|
||||
|
||||
import JsonView._
|
||||
|
@ -66,12 +65,10 @@ final class JsonView(
|
|||
|
||||
def pref(p: lila.pref.Pref) =
|
||||
Json.obj(
|
||||
"blindfold" -> p.blindfold,
|
||||
"coords" -> p.coords,
|
||||
"rookCastle" -> p.rookCastle,
|
||||
"animation" -> Json.obj(
|
||||
"duration" -> p.animationFactor * animationDuration.toMillis
|
||||
),
|
||||
"blindfold" -> p.blindfold,
|
||||
"coords" -> p.coords,
|
||||
"rookCastle" -> p.rookCastle,
|
||||
"animation" -> Json.obj("duration" -> p.animationMillis),
|
||||
"destination" -> p.destination,
|
||||
"resizeHandle" -> p.resizeHandle,
|
||||
"moveEvent" -> p.moveEvent,
|
||||
|
|
|
@ -20,7 +20,6 @@ private class RoundConfig(
|
|||
@ConfigName("collection.note") val noteColl: CollName,
|
||||
@ConfigName("collection.forecast") val forecastColl: CollName,
|
||||
@ConfigName("collection.alarm") val alarmColl: CollName,
|
||||
@ConfigName("animation.duration") val animationDuration: AnimationDuration,
|
||||
@ConfigName("moretime") val moretimeDuration: MoretimeDuration
|
||||
)
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ final class JsonView(
|
|||
divider: lila.game.Divider,
|
||||
evalCache: lila.evalCache.EvalCacheApi,
|
||||
isOfferingRematch: Pov => Boolean,
|
||||
animation: AnimationDuration,
|
||||
moretime: MoretimeDuration
|
||||
)(implicit ec: scala.concurrent.ExecutionContext) {
|
||||
|
||||
|
@ -83,7 +82,7 @@ final class JsonView(
|
|||
),
|
||||
"pref" -> Json
|
||||
.obj(
|
||||
"animationDuration" -> animationDuration(pov, pref),
|
||||
"animationDuration" -> animationMillis(pov, pref),
|
||||
"coords" -> pref.coords,
|
||||
"resizeHandle" -> pref.resizeHandle,
|
||||
"replay" -> pref.replay,
|
||||
|
@ -181,7 +180,7 @@ final class JsonView(
|
|||
),
|
||||
"pref" -> Json
|
||||
.obj(
|
||||
"animationDuration" -> animationDuration(pov, pref),
|
||||
"animationDuration" -> animationMillis(pov, pref),
|
||||
"coords" -> pref.coords,
|
||||
"resizeHandle" -> pref.resizeHandle,
|
||||
"replay" -> pref.replay,
|
||||
|
@ -242,7 +241,7 @@ final class JsonView(
|
|||
"orientation" -> orientation.name,
|
||||
"pref" -> Json
|
||||
.obj(
|
||||
"animationDuration" -> animationDuration(pov, pref),
|
||||
"animationDuration" -> animationMillis(pov, pref),
|
||||
"coords" -> pref.coords,
|
||||
"moveEvent" -> pref.moveEvent,
|
||||
"resizeHandle" -> pref.resizeHandle
|
||||
|
@ -277,21 +276,10 @@ final class JsonView(
|
|||
}
|
||||
}
|
||||
|
||||
private def animationFactor(pref: Pref): Float =
|
||||
pref.animation match {
|
||||
case 0 => 0
|
||||
case 1 => 0.5f
|
||||
case 2 => 1
|
||||
case 3 => 2
|
||||
case _ => 1
|
||||
}
|
||||
|
||||
private def animationDuration(pov: Pov, pref: Pref) =
|
||||
math.round {
|
||||
animationFactor(pref) * animation.value.toMillis * {
|
||||
if (pov.game.finished) 1
|
||||
else math.max(0, math.min(1.2, ((pov.game.estimateTotalTime - 60) / 60) * 0.2))
|
||||
}
|
||||
private def animationMillis(pov: Pov, pref: Pref) =
|
||||
pref.animationMillis * {
|
||||
if (pov.game.finished) 1
|
||||
else math.max(0, math.min(1.2, ((pov.game.estimateTotalTime - 60) / 60) * 0.2))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue