diff --git a/frontend/src/components/Deck.vue b/frontend/src/components/Deck.vue index b35861b..ad0fc2a 100644 --- a/frontend/src/components/Deck.vue +++ b/frontend/src/components/Deck.vue @@ -24,7 +24,7 @@ - + edit @@ -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 }