aboutsummaryrefslogtreecommitdiff
path: root/src/scalevalapokalypsi/Server/Server.scala
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-17 17:06:56 +0200
committerJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-17 17:06:56 +0200
commitc954ca4d1ec677a34a6d787a23f9d01396f7e585 (patch)
treec6b00b5046bde3a98c18f9557198f852b4ce9d46 /src/scalevalapokalypsi/Server/Server.scala
parenta6b0330c845d4edad87c7059bac56e194a276c6f (diff)
downloadscalevalapokalypsi-c954ca4d1ec677a34a6d787a23f9d01396f7e585.tar.gz
scalevalapokalypsi-c954ca4d1ec677a34a6d787a23f9d01396f7e585.zip
Template for singing, WIP.
* The line to sing is always the same. * The client recovers weirdly from singing before the next turn and my brain is currently too fried to figure out why
Diffstat (limited to 'src/scalevalapokalypsi/Server/Server.scala')
-rw-r--r--src/scalevalapokalypsi/Server/Server.scala21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/scalevalapokalypsi/Server/Server.scala b/src/scalevalapokalypsi/Server/Server.scala
index f18d5c0..db30283 100644
--- a/src/scalevalapokalypsi/Server/Server.scala
+++ b/src/scalevalapokalypsi/Server/Server.scala
@@ -52,6 +52,7 @@ class Server(
this.readFromAll()
this.clients.foreach(_.interpretData())
this.writeClientDataToClients()
+ this.makeClientsSing()
this.writeObservations()
if this.canExecuteTurns then
this.clients.inRandomOrder(_.act())
@@ -68,7 +69,11 @@ class Server(
)
startGameForClient(c)
)
- else if this.adventure.isEmpty && !this.clients.isEmpty && this.clients.forall(_.isReadyForGameStart) then
+ else if
+ this.adventure.isEmpty &&
+ !this.clients.isEmpty &&
+ this.clients.forall(_.isReadyForGameStart)
+ then
this.adventure = Some(Adventure(this.clients.names))
this.clients.foreach(startGameForClient(_))
this.previousTurn = currentTimeMillis() / 1000
@@ -97,7 +102,9 @@ class Server(
this.clients.foreach(c =>
if c.player != playerEntity then
- c.player.foreach(_.observe(s"${name.getOrElse("Unknown player")} joins the game."))
+ c.player.foreach(_.observe(
+ s"${name.getOrElse("Unknown player")} joins the game.")
+ )
)
@@ -109,6 +116,16 @@ class Server(
)
)
+ private def makeClientsSing(): Unit =
+ this.clients.foreach(c =>
+ if c.player.exists(_.isSinging) && !c.clientHasSong then
+ this.writeToClient(
+ s"${SING_INDICATOR}Esimerkkirivi laulettavaksi, lirulirulei\r\n",
+ c
+ )
+ c.startSong()
+ )
+
/** Helper function to determine if the next turn can be taken */
private def canExecuteTurns: Boolean =
val requirement1 = this.adventure.isDefined