1
0
mirror of https://github.com/exane/not-gwent-online synced 2024-12-27 05:13:13 +00:00
not-gwent-online/site/client/app/modules/deck-builder/components/deck-builder.js

105 lines
2.2 KiB
JavaScript
Raw Normal View History

2015-06-24 05:09:16 +00:00
var cards = require("../../../../../../assets/data/cards");
var deck = require("../../../../../../assets/data/deck");
2015-06-23 08:36:29 +00:00
module.exports = {
2015-06-24 05:09:16 +00:00
template: require('../views/deck-builder.html'),
data: function() {
return {
cards: [],
2015-06-25 13:18:44 +00:00
deck: [],
2015-06-24 10:44:10 +00:00
2015-06-25 17:07:52 +00:00
allLeaders: [],
myLeaders: [],
2015-06-24 10:44:10 +00:00
2015-06-25 17:07:52 +00:00
factionFilter: 'northern_realm',
modalLeader: false
2015-06-24 05:09:16 +00:00
}
},
2015-06-25 17:07:52 +00:00
components: {
showleaders: require('./show-leaders')
},
2015-06-24 05:09:16 +00:00
ready: function() {
2015-06-24 18:34:35 +00:00
this.initCards();
this.initDeck();
2015-06-24 10:44:10 +00:00
},
2015-06-25 13:18:44 +00:00
filters: {
2015-06-25 19:19:07 +00:00
// Iterate for correct card type and merge multiple cards.
2015-06-25 13:18:44 +00:00
getType: function(c, type) {
2015-06-25 19:19:07 +00:00
var a = [];
var itemCount = {};
2015-06-25 13:18:44 +00:00
var tmp = $.map(c, (item) => {
2015-06-25 19:19:07 +00:00
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;
}
}
});
// todo: extract to method
var tmp2 = $.map(tmp, (item) => {
if(itemCount[item.card.name]) {
item.count = itemCount[item.card.name];
}
return item;
2015-06-25 13:18:44 +00:00
});
2015-06-25 19:19:07 +00:00
return tmp2;
2015-06-25 13:18:44 +00:00
}
},
2015-06-24 10:44:10 +00:00
methods: {
changeDeck: function(deck) {
2015-06-24 13:21:17 +00:00
// todo: load animation
2015-06-25 13:46:31 +00:00
$('.all-cards, .all-deck').addClass('remove');
2015-06-24 10:44:10 +00:00
this.factionFilter = deck;
2015-06-24 18:34:35 +00:00
this.initDeck();
2015-06-25 13:46:31 +00:00
$('.all-cards, .all-deck').scrollTop(0);
2015-06-24 10:44:10 +00:00
setTimeout(function() {
2015-06-25 13:46:31 +00:00
$('.all-cards, .all-deck').removeClass('remove');
2015-06-24 15:51:21 +00:00
}, 500);
2015-06-24 18:34:35 +00:00
},
// Filter for leaders and store them separately.
initCards: function() {
this.cards = $.map(cards, (n) => {
if(n.type != 3) return n;
2015-06-25 17:07:52 +00:00
this.allLeaders.push(n);
2015-06-24 18:34:35 +00:00
});
},
initDeck: function() {
2015-06-25 13:18:44 +00:00
this.deck = [];
var _deck = deck[this.factionFilter];
for(var item in _deck) {
2015-06-25 19:19:07 +00:00
this.deck.push({
card: cards[_deck[item]],
count: 1
});
2015-06-25 13:18:44 +00:00
}
2015-06-24 18:34:35 +00:00
},
2015-06-25 17:07:52 +00:00
showLeaders: function(currentLeader) {
this.myLeaders = $.map(this.allLeaders, (item) => {
if(item.faction == this.factionFilter) return item;
});
2015-06-24 18:34:35 +00:00
2015-06-25 17:07:52 +00:00
this.modalLeader = true;
2015-06-24 10:44:10 +00:00
}
2015-06-24 05:09:16 +00:00
}
2015-06-23 08:36:29 +00:00
};