Browse Source

Some API updates to fix the timeout flag bug

Kirk Trombley 5 years ago
parent
commit
335f84e85d
3 changed files with 7 additions and 6 deletions
  1. 3 3
      README.md
  2. 1 1
      client/src/components/screens/PlayerScores/PlayerScoreTile.jsx
  3. 3 2
      server/db.py

+ 3 - 3
README.md

@@ -42,11 +42,12 @@ GET /game/{ID}
                     "1": {
                         "lat": number,
                         "lng": number,
-                        "score": number
+                        "score": number || null,
                     }, ...
                 }
             }, ...
-        ]
+        ],
+        "linkedGame": string || null
     }
 POST /game/{ID}/join
     Accepts {
@@ -92,5 +93,4 @@ POST /game/{ID}/guesses/{round}
 - Ivan's idea of launching a new lobby right from the end screen and updating all the other viewers
     - Add a "next game" field to game in db
     - Embed the game creation form in the summary page
-- Fix bug on UI drawing timeout flags offscreen
 - Modify scoring to linear interp in the middle

+ 1 - 1
client/src/components/screens/PlayerScores/PlayerScoreTile.jsx

@@ -42,7 +42,7 @@ export default ({ name, guesses, totalScore }) => (
         Object.entries(guesses)
           .map(([k, v]) => [parseInt(k), v])
           .sort(([k1], [k2]) => k1 < k2 ? -1 : k1 > k2 ? 1 : 0)
-          .map(([num, { score }]) => score !== undefined ? <Score key={num}>{num}: {score}</Score> : null)
+          .map(([num, { score }]) => score !== undefined ? <Score key={num}>{num}: {score ?? 0}</Score> : null)
       }
     </List>
   </Tile>

+ 3 - 2
server/db.py

@@ -65,6 +65,7 @@ class Game(db.Model):
                 } for c in self.coordinates
             },
             "players": [p.to_dict() for p in self.players],
+            "linkedGame": None,
         }
 
 
@@ -75,7 +76,7 @@ class Player(db.Model):
     guesses = db.relationship("Guess", lazy=True, order_by="Guess.round_number")
 
     def get_total_score(self):
-        return sum(g.round_score for g in self.guesses)
+        return sum(g.round_score or 0 for g in self.guesses)
 
     def get_current_round(self):
         if len(self.guesses) == 0:
@@ -97,7 +98,7 @@ class Player(db.Model):
         db.session.commit()
 
     def add_timeout(self, round_num):
-        self.add_guess(round_num, -200, -200, 0)
+        self.add_guess(round_num, -200, -200, None)
 
     def to_dict(self):
         return {