better deck parts splitter

This commit is contained in:
Jörn-Michael Miehe 2019-05-16 15:54:33 +02:00
parent 296ab79bd6
commit 323d6d2f35

View file

@ -60,34 +60,36 @@ export default {
computed: {
deck_parts() {
let retval = {
forwards: {
heading: 'Forwards',
cards: this.deck.cards.filter(card => card.dbentry.type === 'Forward')
},
backups: {
heading: 'Backups',
cards: this.deck.cards.filter(card => card.dbentry.type === 'Backup')
},
rest: {
heading: 'Summons, Monsters & more',
cards: this.deck.cards.filter(
card =>
card.dbentry.type != 'Forward' && card.dbentry.type != 'Backup'
let retval = ['Forwards', 'Backups', 'Summons, Monsters & more'].map(
item => ({
heading: item,
cards: [],
count: 0
})
)
}
}
for (let i = 0; i < Object.keys(retval).length; i++) {
let key = Object.keys(retval)[i]
retval[key].count = retval[key].cards.reduce(
(result, card) => result + card.count,
0
)
retval[key].cards.sort(
this.deck.cards.forEach(card => {
let target
switch (card.dbentry.type) {
case 'Forward':
target = 0
break
case 'Backup':
target = 1
break
default:
target = 2
break
}
retval[target].cards.push(card)
retval[target].count += card.count
})
retval.forEach(part =>
part.cards.sort(
(card_l, card_r) => card_l.dbentry.cost - card_r.dbentry.cost
)
}
)
return retval
}