Permalink
Browse files

pause the graph scrolling when the game is paused

  • Loading branch information...
1 parent 2733e0b commit aac021a8b3a7dcbab13a07b4b44c91711b287dc6 @rchatley committed Jan 8, 2012
Showing with 15 additions and 6 deletions.
  1. +5 −4 lib/extreme_startup/web_server.rb
  2. +10 −2 public/js/leaderboard.js
@@ -26,28 +26,29 @@ class WebServer < Sinatra::Base
get '/' do
haml :leaderboard, :locals => {
- :leaderboard => LeaderBoard.new(scoreboard, players),
+ :leaderboard => LeaderBoard.new(scoreboard, players, game_state),
:players => players }
end
get '/scores' do
- LeaderBoard.new(scoreboard, players).to_json
+ LeaderBoard.new(scoreboard, players, game_state).to_json
end
class LeaderBoard
- def initialize(scoreboard, players)
+ def initialize(scoreboard, players, game_state)
@entries = []
scoreboard.leaderboard.each do |entry|
@entries << LeaderBoardEntry.new(entry[0], players[entry[0]], entry[1])
end
+ @inplay = game_state.is_running?;
end
def each(&block)
@entries.each &block
end
def to_json(*a)
- @entries.to_json(*a)
+ {'entries' => @entries, 'inplay' => @inplay }.to_json(*a)
end
end
View
@@ -21,8 +21,12 @@ $(document).ready(function() {
smoothie.addTimeSeries(series, { strokeStyle:colourTable[entry.playerid], lineWidth:3 });
}
series.append(new Date().getTime(), entry.score);
+ smoothie.start();
}
};
+ this.pause = function() {
+ smoothie.stop();
+ }
};
var ScoreBoard = function(div) {
@@ -49,8 +53,12 @@ $(document).ready(function() {
url: '/scores',
success: function( data ) {
var leaderboard = JSON.parse(data);
- graph.updateWith(leaderboard);
- scoreboard.updateWith(leaderboard);
+ if (leaderboard.inplay) {
+ graph.updateWith(leaderboard.entries);
+ scoreboard.updateWith(leaderboard.entries);
+ } else {
+ graph.pause();
+ }
}
});
}, 1000);

0 comments on commit aac021a

Please sign in to comment.