From f5425829dda1114d778924edf9138b7268ace3ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Mon, 27 May 2019 13:43:18 +0200 Subject: [PATCH] Crystal component --- frontend/src/classes/Deck.js | 22 +++++++++++ frontend/src/components/Card.vue | 51 ++++--------------------- frontend/src/components/Crystal.vue | 59 +++++++++++++++++++++++++++++ frontend/src/components/Deck.vue | 15 +++++++- 4 files changed, 102 insertions(+), 45 deletions(-) create mode 100644 frontend/src/components/Crystal.vue diff --git a/frontend/src/classes/Deck.js b/frontend/src/classes/Deck.js index 4d84216..2f0a2f7 100644 --- a/frontend/src/classes/Deck.js +++ b/frontend/src/classes/Deck.js @@ -187,4 +187,26 @@ export default class { count() { return this.cards.reduce((total, card) => total + card.count, 0) } + + elements() { + let elements = {} + + for (let card of this.cards) { + if (!elements[card.dbentry.element]) elements[card.dbentry.element] = 0 + + elements[card.dbentry.element] += card.count + } + + let retval = [] + + for (let element in elements) + retval.push({ + name: element, + count: elements[element] + }) + + retval.sort((element_l, element_r) => element_r.count - element_l.count) + + return retval + } } diff --git a/frontend/src/components/Card.vue b/frontend/src/components/Card.vue index 1432099..193a238 100644 --- a/frontend/src/components/Card.vue +++ b/frontend/src/components/Card.vue @@ -3,28 +3,7 @@ diff --git a/frontend/src/components/Deck.vue b/frontend/src/components/Deck.vue index 7b6516b..702b741 100644 --- a/frontend/src/components/Deck.vue +++ b/frontend/src/components/Deck.vue @@ -1,7 +1,18 @@