Progress on friend games
This commit is contained in:
parent
986ebd1660
commit
b29426acc0
|
@ -85,9 +85,15 @@ trait LilaController
|
|||
|
||||
def IORedirect(op: IO[Call]) = Redirect(op.unsafePerformIO)
|
||||
|
||||
def IOption[A, B](ioa: IO[Option[A]])(op: A ⇒ B)(implicit writer: Writeable[B], ctype: ContentTypeOf[B], ctx: Context) =
|
||||
def IOption[A, B](ioa: IO[Option[A]])(op: A ⇒ B)(
|
||||
implicit writer: Writeable[B],
|
||||
ctype: ContentTypeOf[B],
|
||||
ctx: Context) =
|
||||
ioa.unsafePerformIO.fold(a ⇒ Ok(op(a)), notFound(ctx))
|
||||
|
||||
def IOptionResult[A](ioa: IO[Option[A]])(op: A ⇒ Result)(implicit ctx: Context) =
|
||||
ioa.unsafePerformIO.fold(a ⇒ op(a), notFound(ctx))
|
||||
|
||||
def notFound(ctx: Context) = Lobby handleNotFound ctx
|
||||
|
||||
// I like Unit requests.
|
||||
|
|
|
@ -45,8 +45,6 @@ object Round extends LilaController {
|
|||
}
|
||||
}
|
||||
|
||||
private def version(gameId: String): Int = socket blockingVersion gameId
|
||||
|
||||
def abort(fullId: String) = performAndRedirect(fullId, hand.abort)
|
||||
def resign(fullId: String) = performAndRedirect(fullId, hand.resign)
|
||||
def resignForce(fullId: String) = performAndRedirect(fullId, hand.resignForce)
|
||||
|
@ -114,4 +112,6 @@ object Round extends LilaController {
|
|||
|
||||
private def performEvents(fullId: String)(events: List[Event]): IO[Unit] =
|
||||
env.round.socket.send(DbGame takeGameId fullId, events)
|
||||
|
||||
private def version(gameId: String): Int = socket blockingVersion gameId
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ object Setup extends LilaController {
|
|||
|
||||
def forms = env.setup.formFactory
|
||||
def processor = env.setup.processor
|
||||
def gameRepo = env.game.gameRepo
|
||||
|
||||
val aiForm = Open { implicit ctx ⇒
|
||||
IOk(forms.aiFilled map { html.setup.ai(_) })
|
||||
|
@ -33,10 +34,21 @@ object Setup extends LilaController {
|
|||
val friend = process(forms.friend) { config ⇒
|
||||
implicit ctx ⇒
|
||||
processor friend config map { pov ⇒
|
||||
routes.Round.player(pov.fullId)
|
||||
routes.Setup.await(pov.fullId)
|
||||
}
|
||||
}
|
||||
|
||||
def await(fullId: String) = Open { implicit ctx ⇒
|
||||
IOptionResult(gameRepo pov fullId) { pov ⇒
|
||||
pov.game.started.fold(
|
||||
Redirect(routes.Round.player(pov.fullId)),
|
||||
Ok(html.setup.await(pov, None))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
def cancel(fullId: String) = TODO
|
||||
|
||||
val hookForm = TODO
|
||||
|
||||
val hook = TODO
|
||||
|
|
|
@ -2,7 +2,7 @@ package lila
|
|||
package game
|
||||
|
||||
import chess.format.Forsyth
|
||||
import chess.{ Status, Variant, Color, Clock }
|
||||
import chess.{ Status, Variant, Color, Clock, Mode }
|
||||
import user.{ User, UserHelper }
|
||||
import http.Context
|
||||
import i18n.I18nHelper
|
||||
|
@ -21,11 +21,16 @@ trait GameHelper { self: I18nHelper with UserHelper ⇒
|
|||
case Variant.Chess960 ⇒ "chess960"
|
||||
}
|
||||
|
||||
def clockName(clock: Option[Clock])(implicit ctx: Context): String =
|
||||
def clockName(clock: Option[Clock])(implicit ctx: Context): String =
|
||||
clock.fold(clockName, trans.unlimited.str())
|
||||
|
||||
def clockName(clock: Clock): String = Namer clock clock
|
||||
|
||||
def modeName(mode: Mode)(implicit ctx: Context): String = mode match {
|
||||
case Mode.Casual ⇒ trans.casual.str()
|
||||
case Mode.Rated ⇒ trans.rated.str()
|
||||
}
|
||||
|
||||
def usernameWithElo(player: DbPlayer) = Namer.player(player)(userIdToUsername)
|
||||
|
||||
def playerLink(player: DbPlayer, cssClass: Option[String] = None) = Html {
|
||||
|
|
|
@ -7,7 +7,7 @@ import http.Context
|
|||
|
||||
import play.api.i18n.Lang
|
||||
import play.api.templates.Html
|
||||
import play.api.mvc.RequestHeader
|
||||
import play.api.mvc.{ RequestHeader, Call }
|
||||
|
||||
trait I18nHelper {
|
||||
|
||||
|
@ -34,6 +34,9 @@ trait I18nHelper {
|
|||
})
|
||||
}
|
||||
|
||||
def commonDomain(implicit ctx: Context): String =
|
||||
I18nDomain(ctx.req.domain).commonDomain
|
||||
|
||||
val protocol = "http://"
|
||||
|
||||
private def langUrl(lang: Lang)(req: RequestHeader) =
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package lila
|
||||
package setup
|
||||
|
||||
import chess.{ Mode }
|
||||
import chess.{ Mode, PausedClock }
|
||||
|
||||
trait HumanConfig extends Config {
|
||||
|
||||
|
@ -18,6 +18,8 @@ trait HumanConfig extends Config {
|
|||
val mode: Mode
|
||||
|
||||
def validClock = clock.fold(time + increment > 0, true)
|
||||
|
||||
def makeClock = clock option PausedClock(time, increment)
|
||||
}
|
||||
|
||||
trait BaseHumanConfig extends BaseConfig {
|
||||
|
|
34
app/views/setup/await.scala.html
Normal file
34
app/views/setup/await.scala.html
Normal file
|
@ -0,0 +1,34 @@
|
|||
@(pov: Pov, config: Option[lila.setup.FriendConfig])(implicit ctx: Context)
|
||||
|
||||
@import pov._
|
||||
|
||||
@round.layout(
|
||||
title = trans.playWithAFriend.str(),
|
||||
goodies = Html("")) {
|
||||
<div class="lichess_game lichess_game_not_started waiting_opponent clearfix lichess_player_@color"
|
||||
data-socket-url="@routes.Round.websocketPlayer(fullId)" >
|
||||
<div class="lichess_board_wrap">
|
||||
@color.fold(board.white(), board.black())
|
||||
<div class="lichess_overboard auto_center">
|
||||
@trans.toInviteSomeoneToPlayGiveThisUrl():
|
||||
<input
|
||||
class="lichess_id_input"
|
||||
readonly="readonly"
|
||||
value="@protocol@commonDomain@routes.Round.watcher(gameId, "white")"
|
||||
/>
|
||||
<p class="explanations">
|
||||
@trans.theFirstPersonToComeOnThisUrlWillPlayWithYou()
|
||||
<a href="@routes.Setup.cancel(fullId)">@trans.cancel()</a>
|
||||
</p>
|
||||
@config.map { c =>
|
||||
<p class="explanations">
|
||||
@trans.variant(): @variantName(c.variant)<br />
|
||||
@trans.timeControl(): @clockName(c.makeClock)<br />
|
||||
@trans.mode(): @modeName(c.mode)
|
||||
</p>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">var lichess_data = @Html(roundPlayerJsData(pov, 0))</script>
|
||||
}
|
|
@ -43,6 +43,8 @@ GET /setup/ai controllers.Setup.aiForm
|
|||
POST /setup/ai controllers.Setup.ai
|
||||
GET /setup/friend controllers.Setup.friendForm
|
||||
POST /setup/friend controllers.Setup.friend
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue