Skip to content

Commit

Permalink
fix: miniViews and padded numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentfrochot committed Feb 25, 2025
1 parent b545d5e commit 7f4afdb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/views/game/mini.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ object mini {
def renderState(pov: Pov) =
pov.game.variant match {
case Variant.Backgammon(_) =>
dataState := s"${Forsyth.>>(pov.game.variant.gameLogic, pov.game.stratGame)}|${orientation(pov)}|${~pov.game.lastActionKeys}|${pov.game.multiPointResult}"
dataState := s"${Forsyth.>>(pov.game.variant.gameLogic, pov.game.stratGame)}|${orientation(pov)}|${~pov.game.lastActionKeys}|${pov.game.multiPointResult.fold(MultiPointState.noDataChar)(_.toString)}"
case Variant.Chess(_) | Variant.FairySF(_) | Variant.Samurai(_) | Variant.Togyzkumalak(_) |
Variant.Go(_) | Variant.Abalone(_) =>
dataState := s"${Forsyth.>>(pov.game.variant.gameLogic, pov.game.stratGame)}|${orientation(pov)}|${~pov.game.lastActionKeys}"
Expand Down Expand Up @@ -116,7 +116,7 @@ object mini {
pov.game.metadata.multiPointState match {
case Some(_) => {
pov.game.multiPointResult.fold(MultiPointState.noDataChar) { mps =>
s" (${if (pov.playerIndex.p1) mps.p1Points else mps.p2Points})"
s" (${mps.toString(pov.playerIndex.p1).toInt})"
}
}
case None => {
Expand Down
1 change: 1 addition & 0 deletions modules/game/src/main/Game.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,7 @@ case class MultiPointState(target: Int, p1Points: Int = 0, p2Points: Int = 0) {
)

override def toString: String = f"${target}%02d${p1Points}%02d${p2Points}%02d"
def toString(p1: Boolean): String = f"${(if(p1) p1Points else p2Points)}%02d"
}

object MultiPointState {
Expand Down
8 changes: 4 additions & 4 deletions modules/swiss/src/main/SwissJson.scala
Original file line number Diff line number Diff line change
Expand Up @@ -299,17 +299,17 @@ object SwissJson {
"id" -> game.id,
"p1UserId" -> game.p1Player.userId,
"startingScore" -> Json.obj(
"p1" -> game.multiPointResult.fold("0")(_.p1Points.toString),
"p2" -> game.multiPointResult.fold("0")(_.p2Points.toString),
"p1" -> game.multiPointResult.fold(0)(_.p1Points),
"p2" -> game.multiPointResult.fold(0)(_.p2Points),
)
)
} :+
Json.obj(
"id" -> pairingGame.game.id,
"p1UserId" -> pairingGame.game.p1Player.userId,
"startingScore" -> Json.obj(
"p1" -> pairingGame.game.multiPointResult.fold("0")(_.p1Points.toString),
"p2" -> pairingGame.game.multiPointResult.fold("0")(_.p2Points.toString),
"p1" -> pairingGame.game.multiPointResult.fold(0)(_.p1Points),
"p2" -> pairingGame.game.multiPointResult.fold(0)(_.p2Points),
)
)
)
Expand Down

0 comments on commit 7f4afdb

Please sign in to comment.