From 4acfbfdd1f95fe7e7e34ed12e197085e1259647e Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Fri, 12 Jun 2015 00:54:51 +0200 Subject: [PATCH] more tournament rewrite WIP --- app/controllers/Round.scala | 18 +++++------ app/controllers/Tournament.scala | 10 +++--- app/views/analyse/replay.scala.html | 2 +- app/views/analyse/replayBot.scala.html | 2 +- app/views/game/side.scala.html | 12 +++---- app/views/game/sides.scala.html | 4 +-- app/views/round/player.scala.html | 4 +-- app/views/round/watcher.scala.html | 4 +-- app/views/round/watcherBot.scala.html | 2 +- app/views/tournament/gameStanding.scala.html | 18 +++-------- app/views/tournament/reminder.scala.html | 2 +- app/views/tournament/setup.scala.html | 2 +- app/views/tournament/show.scala.html | 4 +-- app/views/tournament/side.scala.html | 2 +- .../tournament/src/main/BSONHandlers.scala | 14 ++++---- modules/tournament/src/main/Pairing.scala | 19 +++-------- modules/tournament/src/main/Player.scala | 8 ++--- modules/tournament/src/main/PlayerRepo.scala | 13 +++++++- modules/tournament/src/main/System.scala | 1 + .../tournament/src/main/TournamentApi.scala | 32 ++++++++++++++++++- .../src/main/arena/ScoringSystem.scala | 2 +- modules/tournament/src/main/model.scala | 5 +++ modules/user/src/main/UserRepo.scala | 3 ++ 23 files changed, 103 insertions(+), 80 deletions(-) create mode 100644 modules/tournament/src/main/model.scala diff --git a/app/controllers/Round.scala b/app/controllers/Round.scala index 9f8b9d3810..afc449828c 100644 --- a/app/controllers/Round.scala +++ b/app/controllers/Round.scala @@ -12,7 +12,7 @@ import lila.common.HTTPRequest import lila.game.{ Pov, PlayerRef, GameRepo, Game => GameModel } import lila.hub.actorApi.map.Tell import lila.round.actorApi.round._ -import lila.tournament.{ TournamentRepo, Tournament => Tourney } +import lila.tournament.{ TournamentRepo, Tournament => Tourney, MiniStanding } import lila.user.{ User => UserModel, UserRepo } import makeTimeout.large import views._ @@ -59,7 +59,7 @@ object Round extends LilaController with TheftPrevention { if (pov.game.playableByAi) env.roundMap ! Tell(pov.game.id, AiPlay) pov.game.started.fold( PreventTheft(pov) { - myTour(pov.game.tournamentId) zip + myTour(pov.game.tournamentId, true) zip (pov.game.simulId ?? Env.simul.repo.find) zip Env.game.crosstableApi(pov.game) zip (!pov.game.isTournament ?? otherPovs(pov.gameId)) flatMap { @@ -145,7 +145,7 @@ object Round extends LilaController with TheftPrevention { else ctx.userId.flatMap(pov.game.playerByUserId) ifTrue pov.game.playable match { case Some(player) => renderPlayer(pov withColor player.color) case None if HTTPRequest.isHuman(ctx.req) => - myTour(pov.game.tournamentId) zip + myTour(pov.game.tournamentId, false) zip (pov.game.simulId ?? Env.simul.repo.find) zip Env.game.crosstableApi(pov.game) zip Env.api.roundApi.watcher(pov, lila.api.Mobile.Api.currentVersion, tv = none) map { @@ -163,11 +163,9 @@ object Round extends LilaController with TheftPrevention { api = apiVersion => Env.api.roundApi.watcher(pov, apiVersion, tv = none) map { Ok(_) } ) - private def myTour(tourId: Option[String])(implicit ctx: Context): Fu[Option[Tourney]] = + private def myTour(tourId: Option[String], withStanding: Boolean)(implicit ctx: Context): Fu[Option[MiniStanding]] = tourId ?? { tid => - ctx.userId ?? { uid => - Env.tournament.cached tour tid map (_ filter (_ contains uid)) - } + Env.tournament.api.miniStanding(tid, ctx.userId, withStanding) } private def join(pov: Pov)(implicit ctx: Context): Fu[Result] = @@ -211,12 +209,12 @@ object Round extends LilaController with TheftPrevention { } private def sides(pov: Pov, isPlayer: Boolean)(implicit ctx: Context) = - myTour(pov.game.simulId) zip + myTour(pov.game.simulId, isPlayer) zip (pov.game.simulId ?? Env.simul.repo.find) zip GameRepo.initialFen(pov.game) zip Env.game.crosstableApi(pov.game) map { - case (((myTour, simul), initialFen), crosstable) => - Ok(html.game.sides(pov, initialFen, myTour, crosstable, withTourStanding = isPlayer, simul)) + case (((tour, simul), initialFen), crosstable) => + Ok(html.game.sides(pov, initialFen, tour, crosstable, simul)) } def continue(id: String, mode: String) = Open { implicit ctx => diff --git a/app/controllers/Tournament.scala b/app/controllers/Tournament.scala index bb623c9185..b827f9094f 100644 --- a/app/controllers/Tournament.scala +++ b/app/controllers/Tournament.scala @@ -57,9 +57,9 @@ object Tournament extends LilaController { } def gameStanding(id: String) = Open { implicit ctx => - env.cached tour id map { - case Some(t) if !t.isCreated => Ok(html.tournament.gameStanding(t, true)) - case _ => NotFound + env.api.miniStanding(id, true) map { + case Some(m) if !m.tour.isCreated => Ok(html.tournament.gameStanding(m)) + case _ => NotFound } } @@ -70,11 +70,11 @@ object Tournament extends LilaController { html = repo enterableById id map { case None => tournamentNotFound case Some(tour) => - env.api.join(tour, me) + env.api.join(tour.id, me) Redirect(routes.Tournament.show(tour.id)) }, api = _ => OptionFuOk(repo enterableById id) { tour => - env.api.join(tour, me) + env.api.join(tour.id, me) fuccess(Json.obj("ok" -> true)) } ) diff --git a/app/views/analyse/replay.scala.html b/app/views/analyse/replay.scala.html index 3cf079d75d..a0f0fedcf2 100644 --- a/app/views/analyse/replay.scala.html +++ b/app/views/analyse/replay.scala.html @@ -45,7 +45,7 @@ userId: @Html(ctx.userId.fold("null")(id => s""""$id"""")) @analyse.layout( title = title, -side = views.html.game.side(pov, initialFen, none, withTourStanding = false, simul = simul, userTv = userTv).some, +side = views.html.game.side(pov, initialFen, none, simul = simul, userTv = userTv).some, chat = base.chatDom(trans.spectatorRoom.str(), ctx.isAuth).some, underchat = underchat.some, moreCss = moreCss, diff --git a/app/views/analyse/replayBot.scala.html b/app/views/analyse/replayBot.scala.html index 11c0568e14..0127e5d766 100644 --- a/app/views/analyse/replayBot.scala.html +++ b/app/views/analyse/replayBot.scala.html @@ -37,7 +37,7 @@ orientation: "@pov.color.name" @analyse.layout( title = title, -side = views.html.game.side(pov, initialFen, none, withTourStanding = false, simul = simul).some, +side = views.html.game.side(pov, initialFen, none, simul = simul).some, chat = base.chatDom(trans.spectatorRoom.str(), ctx.isAuth).some, underchat = underchat.some, moreJs = moreJs, diff --git a/app/views/game/side.scala.html b/app/views/game/side.scala.html index 6cae8009b6..f19d94ab59 100644 --- a/app/views/game/side.scala.html +++ b/app/views/game/side.scala.html @@ -1,4 +1,4 @@ -@(pov: Pov, initialFen: Option[String], myTour: Option[lila.tournament.Tournament], withTourStanding: Boolean, simul: Option[lila.simul.Simul], userTv: Option[User] = None)(implicit ctx: Context) +@(pov: Pov, initialFen: Option[String], tour: Option[lila.tournament.MiniStanding], simul: Option[lila.simul.Simul], userTv: Option[User] = None)(implicit ctx: Context) @import pov._ @import lila.tournament.arena @@ -86,16 +86,14 @@ } - @myTour match { - case Some(t) if !t.isCreated => { @tournament.gameStanding(t, withTourStanding) } - case _ => { - @pov.game.tournamentId.map { tourId => + @tour match { + case Some(m) if !m.tour.isCreated => { @tournament.gameStanding(m) } + case Some(m) => { } } - } @simul.map { sim =>