implement game creation API
parent
f4f8aa0c83
commit
b0958334e0
|
@ -71,6 +71,10 @@ object Setup extends LilaController {
|
|||
}
|
||||
}
|
||||
|
||||
val api = Open { implicit ctx ⇒
|
||||
JsonIOk(processor.api)
|
||||
}
|
||||
|
||||
private def process[A](form: Context ⇒ Form[A])(op: A ⇒ BodyContext ⇒ IO[Call]) =
|
||||
OpenBody { ctx ⇒
|
||||
implicit val req = ctx.body
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package lila
|
||||
package setup
|
||||
|
||||
import chess.{ Game, Board, Variant, Mode, Clock, Color ⇒ ChessColor }
|
||||
import elo.EloRange
|
||||
import game.{ DbGame, DbPlayer }
|
||||
|
||||
case object ApiConfig extends Config with GameGenerator {
|
||||
|
||||
val color = Color.White
|
||||
val variant = Variant.Standard
|
||||
val mode = Mode.Casual
|
||||
|
||||
def game = DbGame(
|
||||
game = Game(
|
||||
board = Board(pieces = variant.pieces),
|
||||
clock = none),
|
||||
ai = None,
|
||||
whitePlayer = DbPlayer.white,
|
||||
blackPlayer = DbPlayer.black,
|
||||
creatorColor = creatorColor,
|
||||
mode = mode,
|
||||
variant = variant)
|
||||
}
|
|
@ -4,9 +4,10 @@ package setup
|
|||
import http.Context
|
||||
import game.{ DbGame, GameRepo, Pov }
|
||||
import user.User
|
||||
import chess.{ Game, Board }
|
||||
import chess.{ Game, Board, Color => ChessColor }
|
||||
import ai.Ai
|
||||
import lobby.{ Hook, Fisherman }
|
||||
import controllers.routes
|
||||
|
||||
import scalaz.effects._
|
||||
|
||||
|
@ -63,4 +64,20 @@ final class Processor(
|
|||
hook = config hook ctx.me
|
||||
_ ← fisherman add hook
|
||||
} yield hook
|
||||
|
||||
def api(implicit ctx: Context): IO[Map[String, Any]] = {
|
||||
val domainRegex = """^.+([^\.]+\.[^\.]+)$""".r
|
||||
val domain = "http://" + domainRegex.replaceAllIn(ctx.req.domain, _ group 1)
|
||||
val config = ApiConfig
|
||||
val pov = config.pov
|
||||
val game = ctx.me.fold(
|
||||
user ⇒ pov.game.updatePlayer(pov.color, _ withUser user),
|
||||
pov.game).start
|
||||
for {
|
||||
_ ← gameRepo insert game
|
||||
_ ← timelinePush(game)
|
||||
} yield ChessColor.all map { color ⇒
|
||||
color.name -> (domain + routes.Round.player(game fullIdOf color).url)
|
||||
} toMap
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import play.api.templates.Html
|
|||
|
||||
trait AssetHelper {
|
||||
|
||||
val assetVersion = 24
|
||||
val assetVersion = 25
|
||||
|
||||
def cssTag(name: String) = css("stylesheets/" + name)
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ GET /$fullId<[\w\-]{12}>/await controllers.Setup.await(fullId: String)
|
|||
GET /$fullId<[\w\-]{12}>/cancel controllers.Setup.cancel(fullId: String)
|
||||
GET /setup/hook controllers.Setup.hookForm
|
||||
POST /setup/hook controllers.Setup.hook
|
||||
POST /api/game/new controllers.Setup.api
|
||||
|
||||
# I18n
|
||||
GET /translation/contribute controllers.I18n.contribute
|
||||
|
|
|
@ -71,7 +71,7 @@
|
|||
|
||||
app.memory = new SpeedOMeter({
|
||||
name : "MEMORY",
|
||||
maxVal : 2000,
|
||||
maxVal : 3000,
|
||||
unit : "MB",
|
||||
container : container
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue