2020-04-23 20:03:47 -06:00
|
|
|
package lila.setup
|
|
|
|
|
|
|
|
import chess.Clock
|
2020-10-18 12:21:34 -06:00
|
|
|
import chess.format.FEN
|
2020-04-23 20:03:47 -06:00
|
|
|
import chess.variant.FromPosition
|
2020-08-28 01:08:45 -06:00
|
|
|
|
2020-04-23 20:03:47 -06:00
|
|
|
import lila.game.PerfPicker
|
2020-08-28 01:08:45 -06:00
|
|
|
import lila.rating.PerfType
|
2020-04-23 20:03:47 -06:00
|
|
|
|
|
|
|
final case class OpenConfig(
|
2021-03-19 09:56:28 -06:00
|
|
|
name: Option[String],
|
2020-04-23 20:03:47 -06:00
|
|
|
variant: chess.variant.Variant,
|
|
|
|
clock: Option[Clock.Config],
|
2021-03-18 17:09:53 -06:00
|
|
|
rated: Boolean,
|
2020-04-23 20:03:47 -06:00
|
|
|
position: Option[FEN] = None
|
|
|
|
) {
|
|
|
|
|
|
|
|
def perfType: Option[PerfType] = PerfPicker.perfType(chess.Speed(clock), variant, none)
|
|
|
|
|
2020-08-28 01:08:45 -06:00
|
|
|
def validFen = ApiConfig.validFen(variant, position)
|
2020-05-24 19:33:59 -06:00
|
|
|
|
|
|
|
def autoVariant =
|
2020-10-18 12:21:34 -06:00
|
|
|
if (variant.standard && position.exists(!_.initial)) copy(variant = FromPosition)
|
2020-05-24 19:33:59 -06:00
|
|
|
else this
|
2020-04-23 20:03:47 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
object OpenConfig {
|
|
|
|
|
2021-03-19 09:56:28 -06:00
|
|
|
def from(
|
|
|
|
n: Option[String],
|
|
|
|
v: Option[String],
|
|
|
|
cl: Option[Clock.Config],
|
|
|
|
rated: Boolean,
|
2021-06-08 03:30:45 -06:00
|
|
|
pos: Option[FEN]
|
2021-03-19 09:56:28 -06:00
|
|
|
) =
|
2020-04-23 20:03:47 -06:00
|
|
|
new OpenConfig(
|
2021-03-19 09:56:28 -06:00
|
|
|
name = n.map(_.trim).filter(_.nonEmpty),
|
2020-05-24 19:33:59 -06:00
|
|
|
variant = chess.variant.Variant.orDefault(~v),
|
2020-04-23 20:03:47 -06:00
|
|
|
clock = cl,
|
2021-03-18 17:09:53 -06:00
|
|
|
rated = rated,
|
2021-06-08 03:30:45 -06:00
|
|
|
position = pos
|
2020-05-24 19:33:59 -06:00
|
|
|
).autoVariant
|
2020-04-23 20:03:47 -06:00
|
|
|
}
|