fix card set filters. fixes #114

This commit is contained in:
Andy Janata 2015-02-21 19:50:33 -08:00
parent bdf18c0423
commit c49787d1df
1 changed files with 36 additions and 32 deletions

View File

@ -24,14 +24,14 @@
/** /**
* Display the list of games on the server, and enable the player to join a game. This is a * Display the list of games on the server, and enable the player to join a game. This is a
* singleton. * singleton.
* *
* @author Andy Janata (ajanata@socialgamer.net) * @author Andy Janata (ajanata@socialgamer.net)
* @constructor * @constructor
*/ */
cah.GameList = function() { cah.GameList = function() {
/** /**
* The game list DOM element. * The game list DOM element.
* *
* @type {HTMLDivElement} * @type {HTMLDivElement}
* @private * @private
*/ */
@ -39,7 +39,7 @@ cah.GameList = function() {
/** /**
* Map all game lobby objects, id -> game lobby. * Map all game lobby objects, id -> game lobby.
* *
* @type {Object} * @type {Object}
* @private * @private
*/ */
@ -47,7 +47,7 @@ cah.GameList = function() {
/** /**
* Regular Expression for simple filtering of game list. * Regular Expression for simple filtering of game list.
* *
* @type {RegExp} * @type {RegExp}
* @private * @private
*/ */
@ -61,7 +61,7 @@ cah.GameList = function() {
$(document).ready(function() { $(document).ready(function() {
/** /**
* The singleton instance of GameList. * The singleton instance of GameList.
* *
* @type {cah.GameList} * @type {cah.GameList}
*/ */
cah.GameList.instance = new cah.GameList(); cah.GameList.instance = new cah.GameList();
@ -102,7 +102,7 @@ cah.GameList.prototype.update = function() {
/** /**
* Update the list of games with fresh data from the server. * Update the list of games with fresh data from the server.
* *
* @param {Object} * @param {Object}
* gameData The game data returned by the server. * gameData The game data returned by the server.
*/ */
@ -129,12 +129,13 @@ cah.GameList.prototype.processUpdate = function(gameData) {
var bannedSets = cah.Preferences.getBannedCardSetIds(); var bannedSets = cah.Preferences.getBannedCardSetIds();
var requiredSets = cah.Preferences.getRequiredCardSetIds(); var requiredSets = cah.Preferences.getRequiredCardSetIds();
for ( var i = 0; i < games.length; i++) { for (var i = 0; i < games.length; i++) {
var game = games[i]; var game = games[i];
var gameOptions = game[cah.$.GameInfo.GAME_OPTIONS];
var hasBanned = false; var hasBanned = false;
$(bannedSets).each(function(index, value) { $(bannedSets).each(function(index, value) {
if (-1 !== $.inArray(value, game[cah.$.GameInfo.CARD_SETS])) { if (-1 !== $.inArray(value, gameOptions[cah.$.GameOptionData.CARD_SETS])) {
hasBanned = true; hasBanned = true;
return false; return false;
} }
@ -142,7 +143,7 @@ cah.GameList.prototype.processUpdate = function(gameData) {
var missingRequired = false; var missingRequired = false;
$(requiredSets).each(function(index, value) { $(requiredSets).each(function(index, value) {
if (-1 === $.inArray(value, game[cah.$.GameInfo.CARD_SETS])) { if (-1 === $.inArray(value, gameOptions[cah.$.GameOptionData.CARD_SETS])) {
missingRequired = true; missingRequired = true;
return false; return false;
} }
@ -167,7 +168,7 @@ cah.GameList.prototype.processUpdate = function(gameData) {
/** /**
* Join the given game. * Join the given game.
* *
* @param {Number} * @param {Number}
* id The id of the game to join. * id The id of the game to join.
*/ */
@ -183,25 +184,26 @@ cah.GameList.prototype.joinGame = function(id) {
/** /**
* Sets the current game filter regular expression * Sets the current game filter regular expression
*/ */
cah.GameList.prototype.setFilter = function (filterRegExp) { cah.GameList.prototype.setFilter = function(filterRegExp) {
try { try {
this.filter_ = new RegExp(filterRegExp || '.', 'i'); this.filter_ = new RegExp(filterRegExp || '.', 'i');
} catch (err) { } catch (err) {
//console.log('Invalid filter: ' + String(filterRegExp)) // console.log('Invalid filter: ' + String(filterRegExp))
} }
}; };
/** /**
* Filters the visibility of the current game list by regular expression * Filters the visibility of the current game list by regular expression
*/ */
cah.GameList.prototype.applyFilter = function (filterRegExp) { cah.GameList.prototype.applyFilter = function(filterRegExp) {
if (filterRegExp || filterRegExp === '') this.setFilter(filterRegExp); if (filterRegExp || filterRegExp === '') {
this.setFilter(filterRegExp);
}
var filter = this.filter_ var filter = this.filter_, gamelist = $('.gamelist_lobby').show();
, gamelist = $('.gamelist_lobby').show();
if (filter && filter.test) { if (filter && filter.test) {
gamelist.filter(function (i) { gamelist.filter(function(i) {
return !filter.test($(this).text()); return !filter.test($(this).text());
}).hide(); }).hide();
} }
@ -209,7 +211,7 @@ cah.GameList.prototype.applyFilter = function (filterRegExp) {
/** /**
* Event handler for the clicking the Create Game button. * Event handler for the clicking the Create Game button.
* *
* @private * @private
*/ */
cah.GameList.prototype.createGameClick_ = function() { cah.GameList.prototype.createGameClick_ = function() {
@ -218,7 +220,7 @@ cah.GameList.prototype.createGameClick_ = function() {
/** /**
* Event handler for clicking the Refresh Games button. * Event handler for clicking the Refresh Games button.
* *
* @private * @private
*/ */
cah.GameList.prototype.refreshGamesClick_ = function() { cah.GameList.prototype.refreshGamesClick_ = function() {
@ -227,7 +229,7 @@ cah.GameList.prototype.refreshGamesClick_ = function() {
/** /**
* Event handler for typing in the filter games input. * Event handler for typing in the filter games input.
* *
* @private * @private
*/ */
cah.GameList.prototype.filterGamesChange_ = function() { cah.GameList.prototype.filterGamesChange_ = function() {
@ -238,7 +240,7 @@ cah.GameList.prototype.filterGamesChange_ = function() {
/** /**
* A single entry in the game list. * A single entry in the game list.
* *
* @param {HTMLElement} * @param {HTMLElement}
* parentElem Element under which to display this. * parentElem Element under which to display this.
* @param {Object} * @param {Object}
@ -248,7 +250,7 @@ cah.GameList.prototype.filterGamesChange_ = function() {
cah.GameListLobby = function(parentElem, data) { cah.GameListLobby = function(parentElem, data) {
/** /**
* The game id represented by this lobby. * The game id represented by this lobby.
* *
* @type {number} * @type {number}
* @private * @private
*/ */
@ -256,7 +258,7 @@ cah.GameListLobby = function(parentElem, data) {
/** /**
* The element we live under. * The element we live under.
* *
* @type {HTMLElement} * @type {HTMLElement}
* @private * @private
*/ */
@ -264,7 +266,7 @@ cah.GameListLobby = function(parentElem, data) {
/** /**
* This game lobby's dom element. * This game lobby's dom element.
* *
* @type {HTMLDivElement} * @type {HTMLDivElement}
* @private * @private
*/ */
@ -272,12 +274,12 @@ cah.GameListLobby = function(parentElem, data) {
/** /**
* This game's data. * This game's data.
* *
* @type {object} * @type {object}
* @private * @private
*/ */
this.data_ = data; this.data_ = data;
var options = data[cah.$.GameInfo.GAME_OPTIONS]; var options = data[cah.$.GameInfo.GAME_OPTIONS];
this.element_.id = "gamelist_lobby_" + this.id_; this.element_.id = "gamelist_lobby_" + this.id_;
@ -294,12 +296,13 @@ cah.GameListLobby = function(parentElem, data) {
$(".gamelist_lobby_player_count", this.element_).text(data[cah.$.GameInfo.PLAYERS].length); $(".gamelist_lobby_player_count", this.element_).text(data[cah.$.GameInfo.PLAYERS].length);
$(".gamelist_lobby_max_players", this.element_).text(options[cah.$.GameOptionData.PLAYER_LIMIT]); $(".gamelist_lobby_max_players", this.element_).text(options[cah.$.GameOptionData.PLAYER_LIMIT]);
$(".gamelist_lobby_spectator_count", this.element_).text(data[cah.$.GameInfo.SPECTATORS].length); $(".gamelist_lobby_spectator_count", this.element_).text(data[cah.$.GameInfo.SPECTATORS].length);
$(".gamelist_lobby_max_spectators", this.element_).text(options[cah.$.GameOptionData.SPECTATOR_LIMIT]); $(".gamelist_lobby_max_spectators", this.element_).text(
options[cah.$.GameOptionData.SPECTATOR_LIMIT]);
$(".gamelist_lobby_goal", this.element_).text(options[cah.$.GameOptionData.SCORE_LIMIT]); $(".gamelist_lobby_goal", this.element_).text(options[cah.$.GameOptionData.SCORE_LIMIT]);
var cardSets = options[cah.$.GameOptionData.CARD_SETS]; var cardSets = options[cah.$.GameOptionData.CARD_SETS];
var cardSetNames = []; var cardSetNames = [];
cardSets.sort(); cardSets.sort();
for (var key in cardSets) { for ( var key in cardSets) {
var cardSetId = cardSets[key]; var cardSetId = cardSets[key];
cardSetNames.push(cah.CardSet.list[cardSetId].getName()); cardSetNames.push(cah.CardSet.list[cardSetId].getName());
} }
@ -312,10 +315,11 @@ cah.GameListLobby = function(parentElem, data) {
$(this.element_).attr( $(this.element_).attr(
"aria-label", "aria-label",
data[cah.$.GameInfo.HOST] + "'s game, with " + data[cah.$.GameInfo.PLAYERS].length + " of " data[cah.$.GameInfo.HOST] + "'s game, with " + data[cah.$.GameInfo.PLAYERS].length + " of "
+ options[cah.$.GameOptionData.PLAYER_LIMIT] + " players, and " + data[cah.$.GameInfo.SPECTATORS].length + options[cah.$.GameOptionData.PLAYER_LIMIT] + " players, and "
+ " of " + options[cah.$.GameOptionData.SPECTATOR_LIMIT] + "spectators. " + statusMessage + ". Goal is " + data[cah.$.GameInfo.SPECTATORS].length + " of "
+ options[cah.$.GameOptionData.SCORE_LIMIT] + " Awesome Points. Using " + cardSetNames.length + options[cah.$.GameOptionData.SPECTATOR_LIMIT] + "spectators. " + statusMessage
+ " card set" + (cardSetNames.length == 1 ? "" : "s") + ". " + ". Goal is " + options[cah.$.GameOptionData.SCORE_LIMIT] + " Awesome Points. Using "
+ cardSetNames.length + " card set" + (cardSetNames.length == 1 ? "" : "s") + ". "
+ (data[cah.$.GameInfo.HAS_PASSWORD] ? "Has" : "Does not have") + " a password."); + (data[cah.$.GameInfo.HAS_PASSWORD] ? "Has" : "Does not have") + " a password.");
}; };