parent
dc2cc4910c
commit
400685ea13
|
@ -6,30 +6,26 @@ import chess.{ Variant, Mode, Speed }
|
|||
case class FilterConfig(
|
||||
variant: Option[Variant],
|
||||
mode: Option[Mode],
|
||||
speed: Option[Speed],
|
||||
eloDiff: Int) {
|
||||
speed: Option[Speed]) {
|
||||
|
||||
def withModeCasual = copy(mode = Mode.Casual.some)
|
||||
|
||||
def encode = RawFilterConfig(
|
||||
v = ~variant.map(_.id),
|
||||
m = mode.map(_.id) | -1,
|
||||
s = ~speed.map(_.id),
|
||||
e = eloDiff
|
||||
s = ~speed.map(_.id)
|
||||
)
|
||||
|
||||
def >> = (
|
||||
variant map (_.id),
|
||||
mode map (_.id),
|
||||
speed map (_.id),
|
||||
eloDiff
|
||||
speed map (_.id)
|
||||
).some
|
||||
|
||||
def render = Map(
|
||||
"variant" -> variant.map(_.toString),
|
||||
"mode" -> mode.map(_.toString),
|
||||
"speed" -> speed.map(_.id),
|
||||
"eloDiff" -> eloDiff
|
||||
"speed" -> speed.map(_.id)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -38,19 +34,16 @@ object FilterConfig {
|
|||
val default = FilterConfig(
|
||||
variant = none,
|
||||
mode = none,
|
||||
speed = none,
|
||||
eloDiff = 0)
|
||||
speed = none)
|
||||
|
||||
val variants = 0 :: Config.variants
|
||||
val modes = -1 :: Mode.all.map(_.id)
|
||||
val speeds = 0 :: Config.speeds
|
||||
val eloDiffs = 0 :: 100 :: 200 :: 300 :: 500 :: Nil
|
||||
|
||||
def <<(v: Option[Int], m: Option[Int], s: Option[Int], e: Int) = new FilterConfig(
|
||||
def <<(v: Option[Int], m: Option[Int], s: Option[Int]) = new FilterConfig(
|
||||
variant = v flatMap Variant.apply,
|
||||
mode = m flatMap Mode.apply,
|
||||
speed = s flatMap Speed.apply,
|
||||
eloDiff = e
|
||||
speed = s flatMap Speed.apply
|
||||
)
|
||||
|
||||
import com.mongodb.casbah.Imports._
|
||||
|
@ -60,17 +53,15 @@ object FilterConfig {
|
|||
variant ← filter.getAs[Int]("v")
|
||||
mode ← filter.getAs[Int]("m")
|
||||
speed ← filter.getAs[Int]("s")
|
||||
eloDiff = ~filter.getAs[Int]("e")
|
||||
config ← RawFilterConfig(variant, mode, speed, eloDiff).decode
|
||||
config ← RawFilterConfig(variant, mode, speed).decode
|
||||
} yield config
|
||||
}
|
||||
|
||||
private[setup] case class RawFilterConfig(v: Int, m: Int, s: Int, e: Int) {
|
||||
private[setup] case class RawFilterConfig(v: Int, m: Int, s: Int) {
|
||||
|
||||
def decode = FilterConfig(
|
||||
variant = Variant(v),
|
||||
mode = Mode(m),
|
||||
speed = Speed(s),
|
||||
eloDiff = e
|
||||
speed = Speed(s)
|
||||
).some
|
||||
}
|
||||
|
|
|
@ -21,8 +21,7 @@ private[setup] final class FormFactory(
|
|||
mapping(
|
||||
"variant" -> optional(variant),
|
||||
"mode" -> mode(ctx.isAuth),
|
||||
"speed" -> optional(speed),
|
||||
"eloDiff" -> eloDiff
|
||||
"speed" -> optional(speed)
|
||||
)(FilterConfig.<<)(_.>>)
|
||||
)
|
||||
|
||||
|
|
|
@ -19,5 +19,4 @@ object Mappings {
|
|||
val color = nonEmptyText.verifying(Color.names contains _)
|
||||
val level = number.verifying(AiConfig.levels contains _)
|
||||
val speed = number.verifying(Config.speeds contains _)
|
||||
val eloDiff = number.verifying(FilterConfig.eloDiffs contains _)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue