Skip to content

Commit 6968fc3

Browse files
committed
add player scores in miniboard upon game finish update
1 parent 1c585a1 commit 6968fc3

File tree

4 files changed

+38
-17
lines changed

4 files changed

+38
-17
lines changed

src/main/scala/Fens.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ object Fens {
4444
}
4545

4646
// a game finishes
47-
def finish(gameId: Game.Id, winner: Option[PlayerIndex]) =
47+
def finish(gameId: Game.Id, winner: Option[PlayerIndex], playerScores: List[String]) =
4848
games.computeIfPresent(
4949
gameId,
5050
(_, watched) => {
51-
watched.clients foreach { _ ! ClientIn.Finish(gameId, winner) }
51+
watched.clients foreach { _ ! ClientIn.Finish(gameId, winner, playerScores) }
5252
null
5353
}
5454
)

src/main/scala/LilaHandler.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ final class LilaHandler(
147147
friendList.startPlaying(u)
148148
publish(_ userTv u, ClientIn.Resync)
149149
}
150-
case GameFinish(gameId, winner, users) =>
150+
case GameFinish(gameId, winner, playerScores, users) =>
151151
users foreach friendList.stopPlaying
152-
Fens.finish(gameId, winner)
152+
Fens.finish(gameId, winner, playerScores)
153153
case Pong(pingAt) => Monitor.ping.record("round", pingAt)
154154
case LilaBoot =>
155155
logger.info("#################### LILA BOOT ####################")

src/main/scala/ipc/ClientIn.scala

+11-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,17 @@ object ClientIn {
7474
)
7575
}
7676

77-
case class Finish(gameId: Game.Id, winner: Option[PlayerIndex]) extends ClientIn {
78-
def write = cliMsg("finish", Json.obj("id" -> gameId.value, "win" -> winner.map(_.letter.toString)))
77+
case class Finish(gameId: Game.Id, winner: Option[PlayerIndex], playerScores: List[String])
78+
extends ClientIn {
79+
def write = cliMsg(
80+
"finish",
81+
Json.obj(
82+
"id" -> gameId.value,
83+
"win" -> winner.map(_.letter.toString),
84+
"p1Score" -> playerScores.headOption,
85+
"p2Score" -> playerScores.lift(1)
86+
)
87+
)
7988
}
8089

8190
case class Mlat(millis: Double) extends ClientIn {

src/main/scala/ipc/LilaOut.scala

+23-11
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,20 @@ object LilaOut {
8585
flags: RoundEventFlags,
8686
tpe: String,
8787
data: JsonString
88-
) extends RoundOut
89-
case class RoundTourStanding(tourId: Tour.ID, data: JsonString) extends RoundOut
90-
case class RoundResyncPlayer(fullId: Game.FullId) extends RoundOut
91-
case class RoundGone(fullId: Game.FullId, v: Boolean) extends RoundOut
92-
case class RoundGoneIn(fullId: Game.FullId, seconds: Int) extends RoundOut
93-
case class RoundBotOnline(gameId: Game.Id, playerIndex: PlayerIndex, v: Boolean) extends RoundOut
94-
case class GameStart(users: List[User.ID]) extends RoundOut
95-
case class GameFinish(gameId: Game.Id, winner: Option[PlayerIndex], users: List[User.ID]) extends RoundOut
96-
case class TvSelect(gameId: Game.Id, speed: Speed, json: JsonString) extends RoundOut
88+
) extends RoundOut
89+
case class RoundTourStanding(tourId: Tour.ID, data: JsonString) extends RoundOut
90+
case class RoundResyncPlayer(fullId: Game.FullId) extends RoundOut
91+
case class RoundGone(fullId: Game.FullId, v: Boolean) extends RoundOut
92+
case class RoundGoneIn(fullId: Game.FullId, seconds: Int) extends RoundOut
93+
case class RoundBotOnline(gameId: Game.Id, playerIndex: PlayerIndex, v: Boolean) extends RoundOut
94+
case class GameStart(users: List[User.ID]) extends RoundOut
95+
case class GameFinish(
96+
gameId: Game.Id,
97+
winner: Option[PlayerIndex],
98+
playerScores: List[String],
99+
users: List[User.ID]
100+
) extends RoundOut
101+
case class TvSelect(gameId: Game.Id, speed: Speed, json: JsonString) extends RoundOut
97102

98103
// racer
99104

@@ -289,8 +294,15 @@ object LilaOut {
289294

290295
case "r/start" => Some(GameStart(commas(args).toList))
291296
case "r/finish" =>
292-
get(args, 3) { case Array(gameId, winner, users) =>
293-
Some(GameFinish(Game.Id(gameId), readOptionalPlayerIndex(winner), commas(users).toList))
297+
get(args, 4) { case Array(gameId, winner, playerScores, users) =>
298+
Some(
299+
GameFinish(
300+
Game.Id(gameId),
301+
readOptionalPlayerIndex(winner),
302+
commas(playerScores).toList,
303+
commas(users).toList
304+
)
305+
)
294306
}
295307

296308
// tv

0 commit comments

Comments
 (0)