From 299008f5143d8564eaac044cb76b9fb134dce911 Mon Sep 17 00:00:00 2001 From: devfake Date: Thu, 25 Jun 2015 21:19:07 +0200 Subject: [PATCH 1/3] merge multiple cards --- .../deck-builder/components/deck-builder.js | 32 ++++++++++++++++--- .../deck-builder/views/deck-builder.html | 14 ++++---- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/site/client/app/modules/deck-builder/components/deck-builder.js b/site/client/app/modules/deck-builder/components/deck-builder.js index 2f52725..95b3d85 100644 --- a/site/client/app/modules/deck-builder/components/deck-builder.js +++ b/site/client/app/modules/deck-builder/components/deck-builder.js @@ -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 + }); } }, diff --git a/site/client/app/modules/deck-builder/views/deck-builder.html b/site/client/app/modules/deck-builder/views/deck-builder.html index 6faeb00..cbf2379 100644 --- a/site/client/app/modules/deck-builder/views/deck-builder.html +++ b/site/client/app/modules/deck-builder/views/deck-builder.html @@ -38,9 +38,9 @@ LEADER
- +
{{ item.count }}x
-
+
@@ -51,9 +51,9 @@ CLOSE COMBAT
-
{{ c > 1 ? c + 'x' : '' }}
+
{{ item.count }}x
-
+
@@ -63,8 +63,9 @@ RANGE
+
{{ item.count }}x
-
+
@@ -74,8 +75,9 @@ SPECIAL
+
{{ item.count }}x
-
+
From 8c3f7417c07e0aaceb4bcde3bb42cbdf2f499d90 Mon Sep 17 00:00:00 2001 From: devfake Date: Thu, 25 Jun 2015 21:20:36 +0200 Subject: [PATCH 2/3] remove count for single cards --- .../app/modules/deck-builder/views/deck-builder.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/site/client/app/modules/deck-builder/views/deck-builder.html b/site/client/app/modules/deck-builder/views/deck-builder.html index cbf2379..998ec55 100644 --- a/site/client/app/modules/deck-builder/views/deck-builder.html +++ b/site/client/app/modules/deck-builder/views/deck-builder.html @@ -38,7 +38,7 @@ LEADER
-
{{ item.count }}x
+
{{ item.count > 1 ? item.count + 'x' : '' }}
@@ -51,7 +51,7 @@ CLOSE COMBAT
-
{{ item.count }}x
+
{{ item.count > 1 ? item.count + 'x' : '' }}
@@ -63,7 +63,7 @@ RANGE
-
{{ item.count }}x
+
{{ item.count > 1 ? item.count + 'x' : '' }}
@@ -75,7 +75,7 @@ SPECIAL
-
{{ item.count }}x
+
{{ item.count > 1 ? item.count + 'x' : '' }}
From 05a76559806bb23ecfec61d1708e3777185b858e Mon Sep 17 00:00:00 2001 From: devfake Date: Thu, 25 Jun 2015 21:25:39 +0200 Subject: [PATCH 3/3] fix leader choose --- .../app/modules/deck-builder/components/show-leaders.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site/client/app/modules/deck-builder/components/show-leaders.js b/site/client/app/modules/deck-builder/components/show-leaders.js index 001c14b..3f35a7b 100644 --- a/site/client/app/modules/deck-builder/components/show-leaders.js +++ b/site/client/app/modules/deck-builder/components/show-leaders.js @@ -14,8 +14,8 @@ module.exports = { chooseLeader(card) { // todo: make own leader variable for(var item in this.deck) { - if(this.deck[item].type == 3) { - this.deck.$set(item, card); + if(this.deck[item].card.type == 3) { + this.deck.$set(item, {card}); } }