Skip to content

Commit

Permalink
remove pool dep to game
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Apr 14, 2024
1 parent c7f4d9a commit e9d1e6d
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 47 deletions.
2 changes: 1 addition & 1 deletion app/controllers/Importer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ final class Importer(env: Env) extends LilaController(env):
case Right(game) =>
negotiate(
html = ctx.me
.filter(_ => data.analyse.isDefined && game.analysable)
.filter(_ => data.analyse.isDefined && lila.game.GameExt.analysable(game))
.soUse { me ?=>
env.fishnet
.analyser(
Expand Down
44 changes: 24 additions & 20 deletions app/views/analyse/replay.scala
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,13 @@ object replay:
frag(
div(cls := "analyse__underboard")(
div(role := "tablist", cls := "analyse__underboard__menu")(
game.analysable.option(
span(role := "tab", cls := "computer-analysis", dataPanel := "computer-analysis")(
trans.site.computerAnalysis()
)
),
lila.game.GameExt
.analysable(game)
.option(
span(role := "tab", cls := "computer-analysis", dataPanel := "computer-analysis")(
trans.site.computerAnalysis()
)
),
(!game.isPgnImport).option(
frag(
(game.ply > 1)
Expand All @@ -174,21 +176,23 @@ object replay:
span(role := "tab", dataPanel := "fen-pgn")(trans.study.shareAndExport())
),
div(cls := "analyse__underboard__panels")(
game.analysable.option(
div(cls := "computer-analysis")(
if analysis.isDefined || analysisStarted then
div(id := "acpl-chart-container")(canvas(id := "acpl-chart"))
else
postForm(
cls := s"future-game-analysis${ctx.isAnon.so(" must-login")}",
action := routes.Analyse.requestAnalysis(gameId)
):
submitButton(cls := "button text"):
span(cls := "is3 text", dataIcon := Icon.BarChart)(
trans.site.requestAComputerAnalysis()
)
)
),
lila.game.GameExt
.analysable(game)
.option(
div(cls := "computer-analysis")(
if analysis.isDefined || analysisStarted then
div(id := "acpl-chart-container")(canvas(id := "acpl-chart"))
else
postForm(
cls := s"future-game-analysis${ctx.isAnon.so(" must-login")}",
action := routes.Analyse.requestAnalysis(gameId)
):
submitButton(cls := "button text"):
span(cls := "is3 text", dataIcon := Icon.BarChart)(
trans.site.requestAComputerAnalysis()
)
)
),
div(cls := "move-times")(
(game.ply > 1)
.option(div(id := "movetimes-chart-container")(canvas(id := "movetimes-chart")))
Expand Down
5 changes: 3 additions & 2 deletions app/views/mod/games.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ object games:
tbody(
games.fold(_.map(_ -> None), _.map { case (pov, ass) => pov -> Some(ass) }).map {
case (pov, assessment) =>
val analysable = lila.game.GameExt.analysable(pov.game)
tr(
td(cls := pov.game.analysable.option("input"))(
pov.game.analysable.option(
td(cls := analysable.option("input"))(
analysable.option(
input(
tpe := "checkbox",
name := s"game[]",
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ lazy val round = module("round",
)

lazy val pool = module("pool",
Seq(game),
Seq(coreI18n, db, rating),
reactivemongo.bundle
)

Expand Down
2 changes: 2 additions & 0 deletions modules/core/src/main/game/Player.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import lila.core.userId.{ UserId, UserIdOf }
import lila.core.rating.data.{ IntRating, IntRatingDiff, RatingProvisional }
import cats.kernel.Eq
import lila.core.user.WithPerf
import lila.core.perf.Perf

case class Player(
id: GamePlayerId,
Expand Down Expand Up @@ -79,3 +80,4 @@ object Player:
trait NewPlayer:
def apply(color: Color, user: Option[WithPerf]): Player
def apply(color: Color, userId: UserId, rating: IntRating, provisional: RatingProvisional): Player
def apply(color: Color, userPerf: (UserId, Perf)): Player
2 changes: 2 additions & 0 deletions modules/core/src/main/game/misc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ object GameRule:
opaque type OnStart = GameId => Unit
object OnStart extends FunctionWrapper[OnStart, GameId => Unit]

case class GameStart(id: GameId)

case class TvSelect(gameId: GameId, speed: Speed, channel: String, data: JsObject)
case class ChangeFeatured(mgs: JsObject)

Expand Down
3 changes: 2 additions & 1 deletion modules/fishnet/src/main/Analyser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ final class Analyser(
repo: FishnetRepo,
analysisRepo: AnalysisRepo,
gameRepo: lila.core.game.GameRepo,
gameApi: lila.core.game.GameApi,
uciMemo: UciMemo,
evalCache: FishnetEvalCache,
limiter: FishnetLimiter
Expand All @@ -35,7 +36,7 @@ final class Analyser(
def apply(game: Game, sender: Work.Sender, ignoreConcurrentCheck: Boolean = false): Fu[Analyser.Result] =
(game.metadata.analysed.so(analysisRepo.exists(game.id.value))).flatMap {
if _ then fuccess(Analyser.Result.AlreadyAnalysed)
else if !game.analysable then fuccess(Analyser.Result.NotAnalysable)
else if !gameApi.analysable(game) then fuccess(Analyser.Result.NotAnalysable)
else
limiter(
sender,
Expand Down
1 change: 1 addition & 0 deletions modules/fishnet/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ final class Env(
requesterApi: lila.analyse.RequesterApi,
getSinglePvEval: lila.tree.CloudEval.GetSinglePvEval,
gameRepo: lila.game.GameRepo,
gameApi: lila.core.game.GameApi,
analysisRepo: lila.analyse.AnalysisRepo,
userApi: lila.core.user.UserApi,
db: lila.db.Db,
Expand Down
2 changes: 0 additions & 2 deletions modules/game/src/main/Game.scala
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@ end GameExt

object Game:

case class OnStart(id: GameId)

val syntheticId = GameId("synthetic")

val maxPlaying = 200 // including correspondence
Expand Down
6 changes: 4 additions & 2 deletions modules/game/src/main/GameRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,10 @@ final class GameRepo(c: Coll)(using Executor) extends lila.core.game.GameRepo(c)
def setAnalysed(id: GameId): Funit = coll.updateField($id(id), F.analysed, true).void
def setUnanalysed(id: GameId): Unit = coll.updateFieldUnchecked($id(id), F.analysed, false)

def isAnalysed(game: Game): Fu[Boolean] = game.analysable.so:
coll.exists($id(game.id) ++ Query.analysed(true))
def isAnalysed(game: Game): Fu[Boolean] = GameExt
.analysable(game)
.so:
coll.exists($id(game.id) ++ Query.analysed(true))

def analysed(id: GameId): Fu[Option[Game]] = coll.one[Game]($id(id) ++ Query.analysed(true))

Expand Down
1 change: 1 addition & 0 deletions modules/insight/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import lila.core.config.*
final class Env(
appConfig: Configuration,
gameRepo: lila.game.GameRepo,
gameApi: lila.core.game.GameApi,
analysisRepo: lila.analyse.AnalysisRepo,
prefApi: lila.core.pref.PrefApi,
relationApi: lila.core.relation.RelationApi,
Expand Down
3 changes: 2 additions & 1 deletion modules/insight/src/main/PovToEntry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ case class RichPov(

final private class PovToEntry(
gameRepo: lila.game.GameRepo,
gameApi: lila.core.game.GameApi,
analysisRepo: lila.analyse.AnalysisRepo
)(using Executor):

def apply(game: Game, userId: UserId, provisional: Boolean): Fu[Either[Game, InsightEntry]] =
enrich(game, userId, provisional).map(_.flatMap(convert).toRight(game))

private def removeWrongAnalysis(game: Game): Boolean =
if game.metadata.analysed && !game.analysable then
if game.metadata.analysed && !gameApi.analysable(game) then
gameRepo.setUnanalysed(game.id)
analysisRepo.remove(game.id.value)
true
Expand Down
10 changes: 4 additions & 6 deletions modules/pool/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@ package lila.pool

import com.softwaremill.macwire.*

import lila.common.Bus
import lila.game.Game

@Module
final class Env(
userApi: lila.core.user.UserApi,
gameRepo: lila.game.GameRepo,
idGenerator: lila.game.IdGenerator,
gameRepo: lila.core.game.GameRepo,
newPlayer: lila.core.game.NewPlayer,
idGenerator: lila.core.game.IdGenerator,
HasCurrentPlayban: lila.core.playban.HasCurrentPlayban,
rageSitOf: lila.core.playban.RageSitOf
)(using Executor, akka.actor.ActorSystem, Scheduler):

private val hookThieve = wire[HookThieve]

val onStart = (gameId: GameId) => Bus.publish(Game.OnStart(gameId), "gameStartId")
val onStart = (gameId: GameId) => lila.common.Bus.publish(lila.core.game.GameStart(gameId), "gameStartId")

private val gameStarter = wire[GameStarter]

Expand Down
7 changes: 4 additions & 3 deletions modules/pool/src/main/GameStarter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package lila.pool

import chess.ByColor

import lila.core.game.{ IdGenerator, GameRepo, Source }
import lila.core.game.{ IdGenerator, GameRepo, NewPlayer, Source }
import lila.core.pool.{ Pairing, Pairings }

final private class GameStarter(
userApi: lila.core.user.UserApi,
gameRepo: GameRepo,
newPlayer: NewPlayer,
idGenerator: IdGenerator,
onStart: GameId => Unit
)(using Executor, Scheduler):
Expand All @@ -24,7 +25,7 @@ final private class GameStarter(
workQueue:
val userIds = couples.flatMap(_.userIds)
for
(perfs, ids) <- userApi.perfOf(userIds, pool.perfType).zip(idGenerator.games(couples.size))
(perfs, ids) <- userApi.perfOf(userIds, pool.perfKey).zip(idGenerator.games(couples.size))
pairings <- couples.zip(ids).map((one(pool, perfs)).tupled).parallel
yield lila.common.Bus.publish(Pairings(pairings.flatten.toList), "poolPairings")

Expand Down Expand Up @@ -62,7 +63,7 @@ final private class GameStarter(
situation = chess.Situation(chess.variant.Standard),
clock = pool.clock.toClock.some
),
players = ByColor(whiteUser, blackUser).mapWithColor(lila.game.Player.make),
players = ByColor(whiteUser, blackUser).mapWithColor((u, p) => newPlayer(u, p)),
mode = chess.Mode.Rated,
status = chess.Status.Created,
daysPerTurn = none,
Expand Down
4 changes: 1 addition & 3 deletions modules/pool/src/main/PoolApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package lila.pool

import akka.actor.*

import lila.game.Game

import lila.core.rating.RatingRange
import lila.core.socket.{ Sri, Sris }
import lila.core.pool.{ PoolMember, PoolConfigId, Joiner }
Expand All @@ -30,7 +28,7 @@ final class PoolApi(

val poolPerfKeys: Map[PoolConfigId, PerfKey] = configs
.map: config =>
config.id -> config.perfType.key
config.id -> config.perfKey
.toMap

def join(poolId: PoolConfigId, joiner: Joiner): Unit =
Expand Down
7 changes: 3 additions & 4 deletions modules/pool/src/main/PoolConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ case class PoolConfig(
clock: chess.Clock.Config,
wave: PoolConfig.Wave
):
val perfType = PerfKey(chess.Speed(clock).key.value).fold(PerfType.Classical)(PerfType.apply)

val id = PoolConfig.clockToId(clock)
val perfKey = PerfKey(chess.Speed(clock).key.value) | PerfKey.classical
val id = PoolConfig.clockToId(clock)

object PoolConfig:

Expand All @@ -31,5 +30,5 @@ object PoolConfig:
"id" -> p.id,
"lim" -> p.clock.limitInMinutes,
"inc" -> p.clock.incrementSeconds,
"perf" -> p.perfType.trans
"perf" -> PerfType(p.perfKey).trans
)
2 changes: 1 addition & 1 deletion modules/round/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ final class Env(
"accountClose" -> { case lila.core.security.CloseAccount(userId) =>
resignAllGamesOf(userId)
},
"gameStartId" -> { case Game.OnStart(gameId) =>
"gameStartId" -> { case lila.core.game.GameStart(gameId) =>
onStart(gameId)
},
"selfReport" -> { case RoundSocket.Protocol.In.SelfReport(fullId, ip, userId, name) =>
Expand Down

0 comments on commit e9d1e6d

Please sign in to comment.