From 323d6d2f3540fb7c3be2feb43507ad899ea91eed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Thu, 16 May 2019 15:54:33 +0200 Subject: [PATCH] better deck parts splitter --- frontend/src/components/Deck.vue | 54 +++++++++++++++++--------------- 1 file changed, 28 insertions(+), 26 deletions(-) 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 }