Commits

Stu Kabakoff committed 28fe4c9

better analytics, hyphens for breaks in blind list and game list

Comments (0)

Files changed (3)

 	var state = info.state;
 	var blinds = info.blinds;
 	var games = info.games;
-	var blindTime = info.blindTime || 600;
+	var blindTime = util.stringToSeconds(info.blindTime) || 600;
 	var infoEl;
 	
 	game.syncToken = info.syncToken;
 	game.name = info.name;
 	
-	if ($.isArray(info.state)) {
-		state = info.state;
-	} else {
-		blinds = blinds.split(/\n+/g);
-		games = games.split(/\n+/g);
-		blindTime = util.stringToSeconds(blindTime);
-		
-		state = [];
-		for (var i=0,c=blinds.length; i<c; i++ ) {
-			state.push({ time:blindTime, blinds:blinds[i], game: games[i%games.length] });
-		}
-	}
-	if (!lastUpdate) {
-		lastUpdate = (new Date).getTime();
-	}
 	if (!game.syncToken) {
 		game.syncToken = 0;
 	}
 	if( !breakLength ) {
 		breakLength = blindTime; 
 	}
+	if ($.isArray(info.state)) {
+		state = info.state;
+	} else {
+		blinds = blinds.split(/\n+/g);
+		games = games.split(/\n+/g);
+		
+		state = [];
+		var levelsThatWerentBlinds = 0;
+		for (var i=0,c=blinds.length; i<c; i++ ) {
+			if (blinds[i] === '-') {
+				state.push(getBreakObject());
+			} else if (games[levelsThatWerentBlinds%games.length] === '-') {
+				state.push(getBreakObject());
+				levelsThatWerentBlinds += 1;
+			} else {
+				state.push({ time:breakLength, blinds:blinds[i], game: games[levelsThatWerentBlinds%games.length] });
+				levelsThatWerentBlinds += 1;
+			}
+		}
+	}
+	if (!lastUpdate) {
+		lastUpdate = (new Date).getTime();
+	}
 	
 	var countInterval;
 	var element = createElement('div', 'poker-game');
 	var toolbar;
 	var hud;
 	
+	function getBreakObject() {
+		return {blinds:local['break'], game:'', time:breakLength};
+	}
+	
 	game.element = element;
 	
 	function count() {
 				blind = state[currentBlindIndex];
 			}
 			if (previousBlindIndex !== currentBlindIndex) {
-				_gaq.push(['_trackEvent', 'level', currentBlindIndex]);
+				_gaq.push(['_trackEvent', 'level', ''+currentBlindIndex]);
 				if( currentLevelEl ) {
 					var previousLevel$ = $(currentLevelEl).removeClass('current').addClass('previous played');
 					previousDimmerTimer = setTimeout( function() {
 				PokerRoom.save();
 				sync.save();
 				syncTimer = setTimeout( function(){ run(); }, 30000 );
-				_gaq.push(['_trackEvent', 'share', currentBlindIndex]);
+				_gaq.push(['_trackEvent', 'share', ''+currentBlindIndex]);
 			},
 			stop: function() {
 				clearTimeout(syncTimer);
 		resize();
 	}
 	function addBreak(index) {
-		state.splice(index, 0, {blinds:local['break'], game:'', time:breakLength});
+		state.splice(index, 0, getBreakLevel());
 		draw();
 		save();
 	}
 		});
 	}
 	function addTime(seconds) {
-		_gaq.push(['_trackEvent', 'timechange', seconds]);
+		_gaq.push(['_trackEvent', 'timechange', ''+seconds]);
 		state[currentBlindIndex].time += seconds * 1000;
 		update();
 		save();
 		},
 		get: function ( gameName ) {
 			$('#public_feedback').html('Loading...');
-			_gaq.push(['_trackEvent', 'sync', 'join-attempt', currentBlindIndex]);
+			_gaq.push(['_trackEvent', 'sync', 'join-attempt']);
 			$.post('php/games.php', {method:'get', name: gameName}, function(data) {
 				data = JSON.parse(data);
 				data = room.add(data);
 				if (data) {
-					_gaq.push(['_trackEvent', 'join', 'success', currentBlindIndex]);
+					_gaq.push(['_trackEvent', 'join', 'success']);
 					room.showGame(data);
 				} else {
-					_gaq.push(['_trackEvent', 'join', 'failure', currentBlindIndex]);
+					_gaq.push(['_trackEvent', 'join', 'failure']);
 					$('#public_feedback').html('No game with that name.');
 				}
 			});
 		return Math.floor(sec/60)+':'+util.pad(sec%60,2);
 	},
 	stringToSeconds: function( time ) {
-		var time_a = time.split(':');
+		var time_a = time.toString().split(':');
 		if (time_a.length > 1) {
 			var minutes = (parseInt(time_a[0],10) || 0) * 60;
 			var seconds = parseInt(time_a[1],10) || 0;