Browse Source

Send pending round via status

Thomas Dy 11 years ago
parent
commit
7f70b86640
3 changed files with 19 additions and 7 deletions
  1. 8 7
      app/models/Taboo.scala
  2. 10 0
      app/util.scala
  3. 1 0
      public/javascripts/tabooServices.js

+ 8 - 7
app/models/Taboo.scala

@@ -1,5 +1,6 @@
 package models
 
+import util._
 import akka.actor._
 import scala.concurrent.duration._
 import play.api.libs.concurrent._
@@ -109,14 +110,13 @@ class TabooGame(val chatActor: ActorRef) extends Actor {
     case Quit(username) =>
       teamA.leave(username)
       teamB.leave(username)
+      val lackingMembers = teamA.size < 2 || currentTeam == teamB && teamB.size < 2
+      if(ready && lackingMembers) {
+        ready = false
+      }
       announceStatus("quit", username)
-      if(teamA.size < 2 || currentTeam == teamB && teamB.size < 2) {
-        if(ready) {
-          ready = false
-        }
-        if(!round.isEmpty) {
-          roundActor ! End
-        }
+      if(!round.isEmpty && lackingMembers) {
+        roundActor ! End
       }
 
     case Talk(username, "/status") => announceStatus()
@@ -215,6 +215,7 @@ class TabooGame(val chatActor: ActorRef) extends Actor {
     chatActor ! Announce(Json.obj(
       "kind" -> kind,
       "user" -> user,
+      "pendingPlayer" -> ifOpt(ready)(currentTeam.player),
       "round" -> round,
       "teamA" -> teamA,
       "teamB" -> teamB

+ 10 - 0
app/util.scala

@@ -0,0 +1,10 @@
+package object util {
+  def ifOpt[A](cond: => Boolean)(f: => A): Option[A] = {
+    if(cond) {
+      Some(f)
+    }
+    else {
+      None
+    }
+  }
+}

+ 1 - 0
public/javascripts/tabooServices.js

@@ -124,6 +124,7 @@ angular.module('tabooServices', [])
     game.teamA = message.teamA;
     game.teamB = message.teamB;
     game.round = message.round;
+    game.pendingRound = (message.pendingPlayer == Chat.username);
     if(game.round) {
       Timer.start(game.round.remainingTime);
     }