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
* singleton.
*
*
* @author Andy Janata (ajanata@socialgamer.net)
* @constructor
*/
cah.GameList = function() {
/**
* The game list DOM element.
*
*
* @type {HTMLDivElement}
* @private
*/
@ -39,7 +39,7 @@ cah.GameList = function() {
/**
* Map all game lobby objects, id -> game lobby.
*
*
* @type {Object}
* @private
*/
@ -47,7 +47,7 @@ cah.GameList = function() {
/**
* Regular Expression for simple filtering of game list.
*
*
* @type {RegExp}
* @private
*/
@ -61,7 +61,7 @@ cah.GameList = function() {
$(document).ready(function() {
/**
* The singleton instance of GameList.
*
*
* @type {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.
*
*
* @param {Object}
* gameData The game data returned by the server.
*/
@ -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;
}
@ -167,7 +168,7 @@ cah.GameList.prototype.processUpdate = function(gameData) {
/**
* Join the given game.
*
*
* @param {Number}
* 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
*/
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();
}
@ -209,7 +211,7 @@ cah.GameList.prototype.applyFilter = function (filterRegExp) {
/**
* Event handler for the clicking the Create Game button.
*
*
* @private
*/
cah.GameList.prototype.createGameClick_ = function() {
@ -218,7 +220,7 @@ cah.GameList.prototype.createGameClick_ = function() {
/**
* Event handler for clicking the Refresh Games button.
*
*
* @private
*/
cah.GameList.prototype.refreshGamesClick_ = function() {
@ -227,7 +229,7 @@ cah.GameList.prototype.refreshGamesClick_ = function() {
/**
* Event handler for typing in the filter games input.
*
*
* @private
*/
cah.GameList.prototype.filterGamesChange_ = function() {
@ -238,7 +240,7 @@ cah.GameList.prototype.filterGamesChange_ = function() {
/**
* A single entry in the game list.
*
*
* @param {HTMLElement}
* parentElem Element under which to display this.
* @param {Object}
@ -248,7 +250,7 @@ cah.GameList.prototype.filterGamesChange_ = function() {
cah.GameListLobby = function(parentElem, data) {
/**
* The game id represented by this lobby.
*
*
* @type {number}
* @private
*/
@ -256,7 +258,7 @@ cah.GameListLobby = function(parentElem, data) {
/**
* The element we live under.
*
*
* @type {HTMLElement}
* @private
*/
@ -264,7 +266,7 @@ cah.GameListLobby = function(parentElem, data) {
/**
* This game lobby's dom element.
*
*
* @type {HTMLDivElement}
* @private
*/
@ -272,12 +274,12 @@ cah.GameListLobby = function(parentElem, data) {
/**
* This game's data.
*
*
* @type {object}
* @private
*/
this.data_ = data;
var options = data[cah.$.GameInfo.GAME_OPTIONS];
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_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.");
};