Permalink
Browse files

Save a record of who was in the game so we can keep showing them when…

… they are gone.
  • Loading branch information...
1 parent b40c23e commit 3c638d8f75b286001ebe09a543526d63650da4c0 @n1mmy n1mmy committed with dgreensp Apr 10, 2012
@@ -141,6 +141,11 @@ button:active {
font-size: 1.25em;
}
+#scores .unnamed {
+ color: #444;
+ font-style: italic;
+}
+
#scores .word {
float: left;
font-size: 1.25em;
@@ -163,4 +168,4 @@ button:active {
#scores .word.bad span.score {
background-image: 'circle-ball-dark-antialiased.gif';
-}
+}
@@ -90,19 +90,29 @@
{{#if show}}
<div id="scores">
{{#each players}}
- <div class="player">
- <div class="header">{{name}}</div>
- {{> words}}
- </div>
+ {{> player }}
{{/each}}
</div>
{{/if}}
</div>
</template>
+<template name="player">
+ <div class="player">
+ <div class="header">
+ {{#if name}}
+ {{name}}
+ {{else}}
+ <span class="unnamed">no name</span>
+ {{/if}}
+ <span class="score">{{total_score}}</span>
+ </div>
+ {{> words}}
+ </div>
+</template>
+
<template name="words">
<div class="words">
- <div class="score">{{total_score}}</div>
{{#each words}}
<div id="word_{{_id}}" class="word {{state}}">
<span class="score">
@@ -175,15 +175,10 @@ Template.scores.show = function () {
};
Template.scores.players = function () {
- return Players.find({game_id: game() && game()._id});
+ return game() && game().players;
};
-Template.words.words = function () {
- return Words.find({game_id: game() && game()._id,
- player_id: this._id});
-};
-
-Template.words.total_score = function () {
+Template.player.total_score = function () {
var words = Words.find({game_id: game() && game()._id,
player_id: this._id});
@@ -195,6 +190,12 @@ Template.words.total_score = function () {
return score;
};
+Template.words.words = function () {
+ return Words.find({game_id: game() && game()._id,
+ player_id: this._id});
+};
+
+
Meteor.startup(function () {
// Allocate a new player id.
@@ -8,6 +8,12 @@ Meteor.methods({
Players.update({game_id: null, idle: false},
{$set: {game_id: game_id}},
{multi: true});
+ // Save a record of who is in the game, so when they leave we can
+ // still show them.
+ var p = Players.find({game_id: game_id},
+ {fields: {_id: true, name: true}}).fetch();
+ Games.update({_id: game_id}, {$set: {players: p}});
+
// wind down the game clock
var clock = 120;

0 comments on commit 3c638d8

Please sign in to comment.