1
0
mirror of https://github.com/exane/not-gwent-online synced 2025-10-09 07:39:08 +00:00

merge multiple cards

This commit is contained in:
devfake
2015-06-25 21:19:07 +02:00
parent c1137344a9
commit 299008f514
2 changed files with 36 additions and 10 deletions

View File

@@ -29,13 +29,34 @@ module.exports = {
},
filters: {
// Iterate for correct card type and merge multiple cards.
getType: function(c, type) {
var a = [];
var itemCount = {};
var tmp = $.map(c, (item) => {
//if(item.type == type) return item;
if($.inArray(item.type, type) > -1) return item;
if($.inArray(item.card.type, type) > -1) {
if($.inArray(item.card.name, a) > -1) {
itemCount[item.card.name] = (itemCount[item.card.name] || 1) + 1;
} else {
a.push(item.card.name);
return item;
}
}
});
return tmp;
// todo: extract to method
var tmp2 = $.map(tmp, (item) => {
if(itemCount[item.card.name]) {
item.count = itemCount[item.card.name];
}
return item;
});
return tmp2;
}
},
@@ -66,7 +87,10 @@ module.exports = {
var _deck = deck[this.factionFilter];
for(var item in _deck) {
this.deck.push(cards[_deck[item]]);
this.deck.push({
card: cards[_deck[item]],
count: 1
});
}
},