more swiss options
This commit is contained in:
parent
ab997224ea
commit
1c0e62e899
|
@ -71,14 +71,17 @@ object bits {
|
|||
)
|
||||
|
||||
def showInterval(s: Swiss): Frag =
|
||||
if (s.settings.manualRounds) frag("Rounds are started manually")
|
||||
else if (s.settings.oneDayInterval) frag("One round per day")
|
||||
else
|
||||
frag(
|
||||
if (s.settings.intervalSeconds < 60) pluralize("second", s.settings.intervalSeconds)
|
||||
else pluralize("minute", s.settings.intervalSeconds / 60),
|
||||
" between rounds"
|
||||
)
|
||||
s.settings.dailyInterval match {
|
||||
case Some(1) => frag("One round per day")
|
||||
case Some(d) => frag(s"One round every $d days")
|
||||
case None if s.settings.manualRounds => frag("Rounds are started manually")
|
||||
case None =>
|
||||
frag(
|
||||
if (s.settings.intervalSeconds < 60) pluralize("second", s.settings.intervalSeconds)
|
||||
else pluralize("minute", s.settings.intervalSeconds / 60),
|
||||
" between rounds"
|
||||
)
|
||||
}
|
||||
|
||||
def jsI18n(implicit ctx: Context) = i18nJsObject(i18nKeys)
|
||||
|
||||
|
|
|
@ -86,8 +86,13 @@ object Swiss {
|
|||
roundInterval: FiniteDuration
|
||||
) {
|
||||
lazy val intervalSeconds = roundInterval.toSeconds.toInt
|
||||
def manualRounds = intervalSeconds == 0
|
||||
def oneDayInterval = intervalSeconds == 24 * 3600
|
||||
def manualRounds = intervalSeconds == Swiss.RoundInterval.manual
|
||||
def dailyInterval = (!manualRounds && intervalSeconds >= 24 * 3600) option intervalSeconds / 3600 / 24
|
||||
}
|
||||
|
||||
object RoundInterval {
|
||||
val auto = -1
|
||||
val manual = 99999999
|
||||
}
|
||||
|
||||
def makeScore(points: Points, tieBreak: TieBreak, perf: Performance) =
|
||||
|
|
|
@ -99,7 +99,9 @@ final class SwissApi(
|
|||
rated = data.rated | old.settings.rated,
|
||||
description = data.description,
|
||||
hasChat = data.hasChat | old.settings.hasChat,
|
||||
roundInterval = data.roundInterval.fold(old.settings.roundInterval)(_.seconds)
|
||||
roundInterval =
|
||||
if (data.roundInterval.isDefined) data.realRoundInterval
|
||||
else old.settings.roundInterval
|
||||
)
|
||||
) pipe { s =>
|
||||
if (
|
||||
|
@ -294,8 +296,10 @@ final class SwissApi(
|
|||
.updateField(
|
||||
$id(swiss.id),
|
||||
"nextRoundAt",
|
||||
if (swiss.settings.oneDayInterval) game.createdAt plusDays 1
|
||||
else DateTime.now.plusSeconds(swiss.settings.roundInterval.toSeconds.toInt)
|
||||
swiss.settings.dailyInterval match {
|
||||
case Some(days) => game.createdAt plusDays days
|
||||
case None => DateTime.now.plusSeconds(swiss.settings.roundInterval.toSeconds.toInt)
|
||||
}
|
||||
)
|
||||
.void >>-
|
||||
systemChat(swiss.id, s"Round ${swiss.round.value + 1} will start soon.")
|
||||
|
|
|
@ -55,7 +55,7 @@ final class SwissForm(implicit mode: Mode) {
|
|||
nbRounds = 8,
|
||||
description = none,
|
||||
hasChat = true.some,
|
||||
roundInterval = 60.some
|
||||
roundInterval = Swiss.RoundInterval.auto.some
|
||||
)
|
||||
|
||||
def edit(s: Swiss) =
|
||||
|
@ -82,7 +82,7 @@ final class SwissForm(implicit mode: Mode) {
|
|||
object SwissForm {
|
||||
|
||||
val clockLimits: Seq[Int] = Seq(0, 15, 30, 45, 60, 90) ++ {
|
||||
(120 to 420 by 60) ++ (600 to 1800 by 300) ++ (2400 to 3600 by 600)
|
||||
(120 to 420 by 60) ++ (600 to 1800 by 300) ++ (2400 to 10800 by 600)
|
||||
}
|
||||
|
||||
val clockLimitChoices = options(
|
||||
|
@ -91,12 +91,35 @@ object SwissForm {
|
|||
)
|
||||
|
||||
val roundIntervals: Seq[Int] =
|
||||
Seq(5, 10, 20, 30, 45, 60, 90, 120, 180, 300, 600, 900, 1200, 1800, 2700, 3600, 24 * 3600, 0)
|
||||
Seq(
|
||||
Swiss.RoundInterval.auto,
|
||||
5,
|
||||
10,
|
||||
20,
|
||||
30,
|
||||
45,
|
||||
60,
|
||||
90,
|
||||
120,
|
||||
180,
|
||||
300,
|
||||
600,
|
||||
900,
|
||||
1200,
|
||||
1800,
|
||||
2700,
|
||||
3600,
|
||||
24 * 3600,
|
||||
2 * 24 * 3600,
|
||||
7 * 24 * 3600,
|
||||
Swiss.RoundInterval.manual
|
||||
)
|
||||
|
||||
val roundIntervalChoices = options(
|
||||
roundIntervals,
|
||||
s =>
|
||||
if (s == 0) s"Manually schedule each round"
|
||||
if (s == Swiss.RoundInterval.auto) s"Automatic (recommended)"
|
||||
else if (s == Swiss.RoundInterval.manual) s"Manually schedule each round"
|
||||
else if (s < 60) s"$s seconds"
|
||||
else if (s < 3600) s"${s / 60} minute(s)"
|
||||
else if (s < 24 * 3600) s"${s / 3600} hour(s)"
|
||||
|
@ -114,8 +137,22 @@ object SwissForm {
|
|||
hasChat: Option[Boolean],
|
||||
roundInterval: Option[Int]
|
||||
) {
|
||||
def realVariant = variant flatMap Variant.apply getOrElse Variant.default
|
||||
def realStartsAt = startsAt | DateTime.now.plusMinutes(10)
|
||||
def realRoundInterval = (roundInterval | 60).seconds
|
||||
def realVariant = variant flatMap Variant.apply getOrElse Variant.default
|
||||
def realStartsAt = startsAt | DateTime.now.plusMinutes(10)
|
||||
def realRoundInterval = {
|
||||
(roundInterval | Swiss.RoundInterval.auto) match {
|
||||
case Swiss.RoundInterval.auto =>
|
||||
import chess.Speed._
|
||||
chess.Speed(clock) match {
|
||||
case UltraBullet => 5
|
||||
case Bullet => 10
|
||||
case Blitz if clock.estimateTotalSeconds < 300 => 20
|
||||
case Blitz => 30
|
||||
case Rapid => 60
|
||||
case _ => 300
|
||||
}
|
||||
case i => i
|
||||
}
|
||||
}.seconds
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue