Skip to content

Commit

Permalink
Rework lobby logic to not add people with no names. Button to start i…
Browse files Browse the repository at this point in the history
…s disabled until you enter a name.
  • Loading branch information
n1mmy committed Apr 10, 2012
1 parent 95cd398 commit e23b309
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
10 changes: 7 additions & 3 deletions examples/wordplay/client/wordplay.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ <h1>{{count}} other players are in the lobby:</h1>
<div class="player">{{name}}</div>
{{/each}}
{{/if}}
<button class="startgame">It's on!</button>
<div>
<button id="startgame" class="startgame" {{{disabled}}}>
{{#if count}} It's on! {{else}} Play solo {{/if}}
</button>
</div>
</div>
{{/if}}
</div>
Expand All @@ -70,7 +74,7 @@ <h1>{{count}} other players are in the lobby:</h1>
{{#if show}}
<div id="scratchpad">
<input id="scratchpad_input" type="text" />
<button class="submit">Submit</button>
<button name="submit" class="submit">Submit</button>
</div>
{{/if}}
</template>
Expand All @@ -79,7 +83,7 @@ <h1>{{count}} other players are in the lobby:</h1>
<div>
{{#if show}}
<div id="postgame">
<button class="lobby">Back to lobby</button>
<button name="backtolobby" class="lobby">Back to lobby</button>
</div>
{{/if}}
</div>
Expand Down
8 changes: 8 additions & 0 deletions examples/wordplay/client/wordplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ Template.lobby.count = function () {
return players.count();
};

Template.lobby.disabled = function () {
var me = player();
if (me && me.name)
return '';
return 'disabled="disabled"';
};


Template.lobby.events = {
'keyup input#myname': function (evt) {
var name = $('#lobby input#myname').val().trim();
Expand Down
4 changes: 2 additions & 2 deletions examples/wordplay/server/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Meteor.methods({
var game_id = Games.insert({board: new_board(),
clock: 120});

// move everyone in the lobby to the game
Players.update({game_id: null, idle: false},
// move everyone who is ready in the lobby to the game
Players.update({game_id: null, idle: false, name: {$ne: ''}},
{$set: {game_id: game_id}},
{multi: true});
// Save a record of who is in the game, so when they leave we can
Expand Down

0 comments on commit e23b309

Please sign in to comment.