lila/app/views/game/bits.scala

111 lines
3.3 KiB
Scala
Raw Normal View History

2018-12-02 07:01:49 -07:00
package views.html.game
import lila.api.Context
import lila.app.templating.Environment._
2018-12-04 06:16:52 -07:00
import lila.app.ui.ScalatagsTemplate._
2019-12-13 07:30:20 -07:00
import lila.game.{ Game, Player, Pov }
2018-12-02 20:17:18 -07:00
import lila.user.Title
import controllers.routes
2018-12-02 07:01:49 -07:00
object bits {
2019-04-08 18:36:57 -06:00
def featuredJs(pov: Pov): Frag = frag(
gameFenNoCtx(pov, tv = true),
vstext(pov)(none)
)
2018-12-02 07:01:49 -07:00
2019-04-24 09:06:12 -06:00
def mini(pov: Pov)(implicit ctx: Context): Frag =
a(href := gameLink(pov))(
gameFen(pov, withLink = false),
vstext(pov)(ctx.some)
)
2018-12-02 07:01:49 -07:00
2019-12-13 07:30:20 -07:00
def miniBoard(fen: chess.format.FEN, color: chess.Color = chess.White): Frag =
div(
cls := "mini-board parse-fen cg-wrap is2d",
dataColor := color.name,
dataFen := fen.value
)(cgWrapContent)
2018-12-02 07:01:49 -07:00
2018-12-02 20:17:18 -07:00
def gameIcon(game: Game): Char = game.perfType match {
2019-12-13 07:30:20 -07:00
case _ if game.fromPosition => '*'
case _ if game.imported => '/'
2018-12-02 18:07:16 -07:00
case Some(p) if game.variant.exotic => p.iconChar
2019-12-13 07:30:20 -07:00
case _ if game.hasAi => 'n'
case Some(p) => p.iconChar
case _ => '8'
2018-12-02 18:07:16 -07:00
}
2018-12-02 20:17:18 -07:00
def sides(
2019-12-13 07:30:20 -07:00
pov: Pov,
initialFen: Option[chess.format.FEN],
tour: Option[lila.tournament.TourAndTeamVs],
2019-12-13 07:30:20 -07:00
cross: Option[lila.game.Crosstable.WithMatchup],
simul: Option[lila.simul.Simul],
userTv: Option[lila.user.User] = None,
bookmarked: Boolean
2019-05-21 23:47:30 -06:00
)(implicit ctx: Context) = div(
side.meta(pov, initialFen, tour, simul, userTv, bookmarked = bookmarked),
2018-12-02 20:17:18 -07:00
cross.map { c =>
div(cls := "crosstable")(crosstable(ctx.userId.fold(c)(c.fromPov), pov.gameId.some))
}
)
def variantLink(
2019-12-13 07:30:20 -07:00
variant: chess.variant.Variant,
name: String,
initialFen: Option[chess.format.FEN] = None
) =
a(
cls := "variant-link",
href := (variant match {
case chess.variant.Standard => "https://en.wikipedia.org/wiki/Chess"
case chess.variant.FromPosition =>
s"""${routes.Editor.index}?fen=${initialFen.??(_.value.replace(' ', '_'))}"""
case v => routes.Page.variant(v.key).url
}),
rel := "nofollow",
target := "_blank",
title := variant.title
)(name)
2018-12-02 20:17:18 -07:00
private def playerTitle(player: Player) =
2019-12-04 23:52:53 -07:00
player.userId.flatMap(lightUser).flatMap(_.title) map Title.apply map { t =>
span(cls := "title", dataBot(t), title := Title titleName t)(t.value)
2018-12-02 20:17:18 -07:00
}
2019-04-05 20:20:44 -06:00
def vstext(pov: Pov)(ctxOption: Option[Context]): Frag =
2019-03-09 17:33:57 -07:00
span(cls := "vstext")(
2019-04-08 03:19:22 -06:00
span(cls := "vstext__pl user-link")(
2018-12-02 20:17:18 -07:00
playerUsername(pov.player, withRating = false, withTitle = false),
br,
2019-12-13 07:30:20 -07:00
playerTitle(pov.player) map { t =>
frag(t, " ")
},
2018-12-02 20:17:18 -07:00
pov.player.rating,
pov.player.provisional option "?"
),
pov.game.clock map { c =>
2019-03-09 17:33:57 -07:00
span(cls := "vstext__clock")(shortClockName(c.config))
2018-12-02 20:17:18 -07:00
} orElse {
ctxOption flatMap { implicit ctx =>
pov.game.daysPerTurn map { days =>
2019-03-09 17:33:57 -07:00
span(cls := "vstext__clock")(
2019-04-22 03:42:25 -06:00
if (days == 1) trans.oneDay() else trans.nbDays.pluralSame(days)
2018-12-02 20:17:18 -07:00
)
}
}
2019-02-27 01:57:53 -07:00
},
2019-04-08 03:19:22 -06:00
span(cls := "vstext__op user-link")(
2019-02-27 01:57:53 -07:00
playerUsername(pov.opponent, withRating = false, withTitle = false),
br,
pov.opponent.rating,
pov.opponent.provisional option "?",
2019-12-13 07:30:20 -07:00
playerTitle(pov.opponent) map { t =>
frag(" ", t)
}
2019-02-27 01:57:53 -07:00
)
2018-12-02 20:17:18 -07:00
)
2018-12-02 07:01:49 -07:00
}