Skip to content

Commit

Permalink
add game division to game json export
Browse files Browse the repository at this point in the history
  • Loading branch information
allanjoseph98 committed Jan 25, 2024
1 parent a58f158 commit 9e5bc57
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/controllers/Game.scala
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ final class Game(env: Env, apiC: => Api) extends LilaController(env):
pgnInJson = getBool("pgnInJson"),
delayMoves = delayMovesFromReq,
lastFen = getBool("lastFen"),
accuracy = getBool("accuracy")
accuracy = getBool("accuracy"),
division = getBoolOpt("division") | extended
)

private[controllers] def delayMovesFromReq(using RequestHeader) =
Expand Down
6 changes: 4 additions & 2 deletions modules/api/src/main/GameApiV2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import lila.common.{ HTTPRequest, LightUser }
import lila.db.dsl.{ *, given }
import lila.game.JsonView.given
import lila.game.PgnDump.WithFlags
import lila.game.{ Game, Query, Pov }
import lila.game.{ Game, Query, Pov, Divider }
import lila.team.GameTeams
import lila.tournament.Tournament
import lila.user.{ Me, User }
Expand All @@ -30,7 +30,8 @@ final class GameApiV2(
annotator: lila.analyse.Annotator,
getLightUser: LightUser.Getter,
realPlayerApi: RealPlayerApi,
gameProxy: GameProxyRepo
gameProxy: GameProxyRepo,
division: Divider
)(using Executor, akka.actor.ActorSystem):

import GameApiV2.*
Expand Down Expand Up @@ -303,6 +304,7 @@ final class GameApiV2(
))
.add("lastFen" -> flags.lastFen.option(Fen.write(g.chess.situation)))
.add("lastMove" -> flags.lastFen.option(g.lastMoveKeys))
.add("division" -> flags.division.option(division(g, initialFen)))

private def gameLightUsers(game: Game): Future[ByColor[(lila.game.Player, Option[LightUser])]] =
game.players.traverse(_.userId so getLightUser).dmap(game.players.zip(_))
Expand Down
3 changes: 2 additions & 1 deletion modules/game/src/main/PgnDump.scala
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ object PgnDump:
pgnInJson: Boolean = false,
delayMoves: Boolean = false,
lastFen: Boolean = false,
accuracy: Boolean = false
accuracy: Boolean = false,
division: Boolean = false
):
def applyDelay[M](moves: Seq[M]): Seq[M] =
if !delayMoves then moves
Expand Down

0 comments on commit 9e5bc57

Please sign in to comment.