Add elo diff to lobby filters WIP

This commit is contained in:
Thibault Duplessis 2013-01-01 23:18:22 +01:00
parent 0bcdc5ffaa
commit c896644a74
4 changed files with 23 additions and 11 deletions

View file

@ -6,26 +6,30 @@ import chess.{ Variant, Mode, Speed }
case class FilterConfig(
variant: Option[Variant],
mode: Option[Mode],
speed: Option[Speed]) {
speed: Option[Speed],
eloDiff: Int) {
def withModeCasual = copy(mode = Mode.Casual.some)
def encode = RawFilterConfig(
v = ~variant.map(_.id),
m = mode.map(_.id) | -1,
s = ~speed.map(_.id)
s = ~speed.map(_.id),
e = eloDiff
)
def >> = (
variant map (_.id),
mode map (_.id),
speed map (_.id)
speed map (_.id),
eloDiff
).some
def render = Map(
"variant" -> variant.map(_.toString),
"mode" -> mode.map(_.toString),
"speed" -> speed.map(_.id)
"speed" -> speed.map(_.id),
"eloDiff" -> eloDiff
)
}
@ -34,16 +38,19 @@ object FilterConfig {
val default = FilterConfig(
variant = none,
mode = none,
speed = none)
speed = none,
eloDiff = 0)
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]) = new FilterConfig(
def <<(v: Option[Int], m: Option[Int], s: Option[Int], e: Int) = new FilterConfig(
variant = v flatMap Variant.apply,
mode = m flatMap Mode.apply,
speed = s flatMap Speed.apply
speed = s flatMap Speed.apply,
eloDiff = e
)
import com.mongodb.casbah.Imports._
@ -53,15 +60,17 @@ object FilterConfig {
variant filter.getAs[Int]("v")
mode filter.getAs[Int]("m")
speed filter.getAs[Int]("s")
config RawFilterConfig(variant, mode, speed).decode
eloDiff = ~filter.getAs[Int]("e")
config RawFilterConfig(variant, mode, speed, eloDiff).decode
} yield config
}
private[setup] case class RawFilterConfig(v: Int, m: Int, s: Int) {
private[setup] case class RawFilterConfig(v: Int, m: Int, s: Int, e: Int) {
def decode = FilterConfig(
variant = Variant(v),
mode = Mode(m),
speed = Speed(s)
speed = Speed(s),
eloDiff = e
).some
}

View file

@ -21,7 +21,8 @@ private[setup] final class FormFactory(
mapping(
"variant" -> optional(variant),
"mode" -> mode(ctx.isAuth),
"speed" -> optional(speed)
"speed" -> optional(speed),
"eloDiff" -> eloDiff
)(FilterConfig.<<)(_.>>)
)

View file

@ -19,4 +19,5 @@ 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 _)
}

1
todo
View file

@ -53,3 +53,4 @@ make signup more visible
traduction intégrale
block user creation from an IP
mute IP
fast join game = creator not redirected properly?