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

@ -129,12 +129,13 @@ cah.GameList.prototype.processUpdate = function(gameData) {
var bannedSets = cah.Preferences.getBannedCardSetIds();
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 gameOptions = game[cah.$.GameInfo.GAME_OPTIONS];
var hasBanned = false;
$(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;
return false;
}
@ -142,7 +143,7 @@ cah.GameList.prototype.processUpdate = function(gameData) {
var missingRequired = false;
$(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;
return false;
}
@ -183,25 +184,26 @@ cah.GameList.prototype.joinGame = function(id) {
/**
* Sets the current game filter regular expression
*/
cah.GameList.prototype.setFilter = function (filterRegExp) {
cah.GameList.prototype.setFilter = function(filterRegExp) {
try {
this.filter_ = new RegExp(filterRegExp || '.', 'i');
} 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
*/
cah.GameList.prototype.applyFilter = function (filterRegExp) {
if (filterRegExp || filterRegExp === '') this.setFilter(filterRegExp);
cah.GameList.prototype.applyFilter = function(filterRegExp) {
if (filterRegExp || filterRegExp === '') {
this.setFilter(filterRegExp);
}
var filter = this.filter_
, gamelist = $('.gamelist_lobby').show();
var filter = this.filter_, gamelist = $('.gamelist_lobby').show();
if (filter && filter.test) {
gamelist.filter(function (i) {
gamelist.filter(function(i) {
return !filter.test($(this).text());
}).hide();
}
@ -294,12 +296,13 @@ cah.GameListLobby = function(parentElem, data) {
$(".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_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]);
var cardSets = options[cah.$.GameOptionData.CARD_SETS];
var cardSetNames = [];
cardSets.sort();
for (var key in cardSets) {
for ( var key in cardSets) {
var cardSetId = cardSets[key];
cardSetNames.push(cah.CardSet.list[cardSetId].getName());
}
@ -312,10 +315,11 @@ cah.GameListLobby = function(parentElem, data) {
$(this.element_).attr(
"aria-label",
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
+ " of " + options[cah.$.GameOptionData.SPECTATOR_LIMIT] + "spectators. " + statusMessage + ". Goal is "
+ options[cah.$.GameOptionData.SCORE_LIMIT] + " Awesome Points. Using " + cardSetNames.length
+ " card set" + (cardSetNames.length == 1 ? "" : "s") + ". "
+ options[cah.$.GameOptionData.PLAYER_LIMIT] + " players, and "
+ data[cah.$.GameInfo.SPECTATORS].length + " of "
+ options[cah.$.GameOptionData.SPECTATOR_LIMIT] + "spectators. " + statusMessage
+ ". 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.");
};