use clock configs for simuls
This commit is contained in:
parent
1dd66f9bc6
commit
68f220e754
|
@ -29,7 +29,7 @@ final class JsonView(
|
|||
},
|
||||
"name" -> simul.name,
|
||||
"fullName" -> simul.fullName,
|
||||
"variants" -> simul.variants.map(variantJson(chess.Speed(simul.clock.chessClock.some))),
|
||||
"variants" -> simul.variants.map(variantJson(chess.Speed(simul.clock.config.some))),
|
||||
"applicants" -> simul.applicants.sortBy(-_.player.rating).map(applicantJson),
|
||||
"pairings" -> simul.pairings.sortBy(-_.player.rating).map(pairingJson(games, simul.hostId)),
|
||||
"isCreated" -> simul.isCreated,
|
||||
|
|
|
@ -95,7 +95,7 @@ case class Simul(
|
|||
|
||||
def perfTypes: List[lila.rating.PerfType] = variants.flatMap { variant =>
|
||||
lila.game.PerfPicker.perfType(
|
||||
speed = chess.Speed(clock.chessClock.some),
|
||||
speed = chess.Speed(clock.config.some),
|
||||
variant = variant,
|
||||
daysPerTurn = none)
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ object Simul {
|
|||
hostRating = host.perfs.bestRatingIn {
|
||||
variants flatMap { variant =>
|
||||
lila.game.PerfPicker.perfType(
|
||||
speed = chess.Speed(clock.chessClock.some),
|
||||
speed = chess.Speed(clock.config.some),
|
||||
variant = variant,
|
||||
daysPerTurn = none)
|
||||
}
|
||||
|
|
|
@ -40,8 +40,7 @@ private[simul] final class SimulApi(
|
|||
def create(setup: SimulSetup, me: User): Fu[Simul] = {
|
||||
val simul = Simul.make(
|
||||
clock = SimulClock(
|
||||
limit = setup.clockTime * 60,
|
||||
increment = setup.clockIncrement,
|
||||
config = chess.Clock.Config(setup.clockTime * 60, setup.clockIncrement),
|
||||
hostExtraTime = setup.clockExtra * 60),
|
||||
variants = setup.variants.flatMap { chess.variant.Variant(_) },
|
||||
host = me,
|
||||
|
|
|
@ -2,18 +2,11 @@ package lila.simul
|
|||
|
||||
// All durations are expressed in seconds
|
||||
case class SimulClock(
|
||||
limit: Int,
|
||||
increment: Int,
|
||||
config: chess.Clock.Config,
|
||||
hostExtraTime: Int) {
|
||||
|
||||
def limitInMinutes = limit / 60
|
||||
|
||||
def show = s"${limitInMinutes}+${increment}"
|
||||
|
||||
def chessClock = chess.Clock(limit, increment)
|
||||
|
||||
def chessClockOf(hostColor: chess.Color) =
|
||||
chessClock.giveTime(hostColor, hostExtraTime)
|
||||
config.toClock.giveTime(hostColor, hostExtraTime)
|
||||
|
||||
def hostExtraMinutes = hostExtraTime / 60
|
||||
}
|
||||
|
|
|
@ -24,7 +24,11 @@ private[simul] final class SimulRepo(simulColl: Coll) {
|
|||
def read(bsonInt: BSONInteger): Variant = Variant(bsonInt.value) err s"No such variant: ${bsonInt.value}"
|
||||
def write(x: Variant) = BSONInteger(x.id)
|
||||
}
|
||||
private implicit val ClockBSONHandler = Macros.handler[SimulClock]
|
||||
private implicit val ClockBSONHandler = {
|
||||
import chess.Clock.Config
|
||||
implicit val clockHandler = Macros.handler[Config]
|
||||
Macros.handler[SimulClock]
|
||||
}
|
||||
private implicit val PlayerBSONHandler = Macros.handler[SimulPlayer]
|
||||
private implicit val ApplicantBSONHandler = Macros.handler[SimulApplicant]
|
||||
private implicit val SimulPairingBSONHandler = new BSON[SimulPairing] {
|
||||
|
|
Loading…
Reference in a new issue