From 077806411c55417bbe7e44e571af6f1a11922c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Thu, 23 May 2019 18:11:39 +0200 Subject: [PATCH] reactivity DeckEditor --- frontend/src/classes/Deck.js | 96 ++++++++++++++++++-- frontend/src/components/Deck.vue | 81 +++++------------ frontend/src/components/DeckList.vue | 37 +++----- frontend/src/components/NewDeck.vue | 25 +++++ frontend/src/components/forms/DeckEditor.vue | 41 +++------ 5 files changed, 163 insertions(+), 117 deletions(-) create mode 100644 frontend/src/components/NewDeck.vue diff --git a/frontend/src/classes/Deck.js b/frontend/src/classes/Deck.js index 51143b9..8deed29 100644 --- a/frontend/src/classes/Deck.js +++ b/frontend/src/classes/Deck.js @@ -1,7 +1,23 @@ 'use strict' +import CardsDB from '@/plugins/ffdecks' + export default class { - constructor(str) { + constructor() { + this.id = null + this.name = '' + this.note = '' + this.cards = [] + } + + from_plainObject(obj) { + this.id = obj.id + this.name = obj.content.name + this.note = obj.content.note + this.cards = obj.content.cards + } + + from_deckList(str) { // select all lines containing card serial numbers let cardLinesRE = /^.*\b\d-\d{3}[A-Z]?\b.*$/gm let cardLines = str.match(cardLinesRE) @@ -29,8 +45,8 @@ export default class { // fallback value let count = 1 - for (let i = 0; i < countREs.length; i++) { - let data = countREs[i].exec(cardLine) + for (let countRE of countREs) { + let data = countRE.exec(cardLine) if (data) { count = Number(data[1]) @@ -47,12 +63,12 @@ export default class { // push card data into deck this.cards = [] - Object.keys(cardCounts).forEach(serial => { + for(let serial in cardCounts) { this.cards.push({ serial: serial, count: cardCounts[serial] }) - }) + } // strip out lines with serial numbers str = str.replace(cardLinesRE, '') @@ -82,10 +98,6 @@ export default class { } } - count() { - return this.cards.reduce((total, card) => total + card.count, 0) - } - plainObject() { return { name: this.name, @@ -93,4 +105,70 @@ export default class { cards: this.cards } } + + parts() { + let retval = ['Forwards', 'Backups', 'Summons, Monsters & more'].map( + item => ({ + heading: item, + cards: [], + count: 0 + }) + ) + + for (let card of this.cards) { + 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 + } + + for (let part of retval) { + part.cards.sort( + (card_l, card_r) => card_l.dbentry.cost - card_r.dbentry.cost + ) + } + + return retval + } + + deckList() { + let lines = [] + + // begin with deck name and note + lines.push('Deck Name: ' + this.name) + lines.push(this.note) + lines.push('') + + // list each deck part + for(let part of this.parts()) { + lines.push(`${part.heading} (${part.count}):`) + + for(let card of part.cards) + lines.push(`${card.count}x ${card.serial} "${card.dbentry.name}"`) + + lines.push('') + } + + return lines.join('\n') + } + + count() { + return this.cards.reduce((total, card) => total + card.count, 0) + } + + populate() { + for (let card of this.cards) { + card.dbentry = CardsDB[card.serial] + } + } } diff --git a/frontend/src/components/Deck.vue b/frontend/src/components/Deck.vue index e73e5e3..6add96c 100644 --- a/frontend/src/components/Deck.vue +++ b/frontend/src/components/Deck.vue @@ -10,7 +10,7 @@ - + {{ part.count }} {{ part.heading }} @@ -30,17 +30,20 @@ + diff --git a/frontend/src/components/forms/DeckEditor.vue b/frontend/src/components/forms/DeckEditor.vue index cf8e040..6279fd1 100644 --- a/frontend/src/components/forms/DeckEditor.vue +++ b/frontend/src/components/forms/DeckEditor.vue @@ -11,12 +11,11 @@ @@ -47,16 +46,13 @@