diff --git a/frontend/src/classes/Deck.js b/frontend/src/classes/Deck.js
index 8deed29..535ed1b 100644
--- a/frontend/src/classes/Deck.js
+++ b/frontend/src/classes/Deck.js
@@ -3,30 +3,55 @@
import CardsDB from '@/plugins/ffdecks'
export default class {
- constructor() {
- this.id = null
+ constructor(id) {
+ this.id = id
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
+ populate() {
+ for (let card of this.cards) {
+ card.dbentry = CardsDB[card.serial]
+ }
+ }
+
+ from_object(obj) {
+ if (obj) {
+ this.name = obj.name
+ this.note = obj.note
+ this.cards = obj.cards
+ }
+ }
+
+ plainObject() {
+ let plainCards = []
+ for (let card of this.cards) {
+ plainCards.push({
+ serial: card.serial,
+ count: card.count
+ })
+ }
+
+ return {
+ name: this.name,
+ note: this.note,
+ cards: plainCards
+ }
}
from_deckList(str) {
// select all lines containing card serial numbers
- let cardLinesRE = /^.*\b\d-\d{3}[A-Z]?\b.*$/gm
+ let cardLinesRE = /^.*\b\d+-0*\d{1,3}[A-Z]?\b.*$/gm
let cardLines = str.match(cardLinesRE)
let cardCounts = {}
cardLines.forEach(cardLine => {
// extract serial (guaranteed to be in here!)
- let serialRE = /\b(\d-\d{3})[A-Z]?\b/i
- let serial = serialRE.exec(cardLine)[1]
+ let serialRE = /\b(\d+)-0*(\d{1,3})[A-Z]?\b/i
+ let serial = serialRE.exec(cardLine)
+ // force format 'x-xxx'
+ serial = `${serial[1]}-${serial[2].padStart(3, '0')}`
// strip out serial number
cardLine = cardLine.replace(serialRE, '')
@@ -63,7 +88,7 @@ export default class {
// push card data into deck
this.cards = []
- for(let serial in cardCounts) {
+ for (let serial in cardCounts) {
this.cards.push({
serial: serial,
count: cardCounts[serial]
@@ -98,14 +123,6 @@ export default class {
}
}
- plainObject() {
- return {
- name: this.name,
- note: this.note,
- cards: this.cards
- }
- }
-
parts() {
let retval = ['Forwards', 'Backups', 'Summons, Monsters & more'].map(
item => ({
@@ -150,10 +167,10 @@ export default class {
lines.push('')
// list each deck part
- for(let part of this.parts()) {
+ for (let part of this.parts()) {
lines.push(`${part.heading} (${part.count}):`)
- for(let card of part.cards)
+ for (let card of part.cards)
lines.push(`${card.count}x ${card.serial} "${card.dbentry.name}"`)
lines.push('')
@@ -165,10 +182,4 @@ export default class {
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 6add96c..1208c14 100644
--- a/frontend/src/components/Deck.vue
+++ b/frontend/src/components/Deck.vue
@@ -31,12 +31,12 @@
-
+
+
+ cancel
+ cancel
+
+
@@ -68,18 +68,17 @@ export default {
},
methods: {
- change_deck(new_deck) {
+ save_deck(new_deck) {
axios
.post('/decks/modify', {
session: this.session,
deckID: this.deck.id,
- deckCards: new_deck
+ deckCards: new_deck.plainObject()
})
.then(response => {
if (response.data.success) {
+ this.editing = false
this.$emit('change')
- } else {
- this.editing = true
}
})
}
diff --git a/frontend/src/components/DeckList.vue b/frontend/src/components/DeckList.vue
index 7101434..32b56e1 100644
--- a/frontend/src/components/DeckList.vue
+++ b/frontend/src/components/DeckList.vue
@@ -50,8 +50,9 @@ export default {
let result = []
for (let plainDeck of this.decks) {
- let deck = new DeckJS()
- deck.from_plainObject(plainDeck)
+ let deck = new DeckJS(plainDeck.id)
+
+ deck.from_object(plainDeck.content)
deck.populate()
result.push(deck)
diff --git a/frontend/src/components/NewDeck.vue b/frontend/src/components/NewDeck.vue
index 1ef784b..6a53a1a 100644
--- a/frontend/src/components/NewDeck.vue
+++ b/frontend/src/components/NewDeck.vue
@@ -6,7 +6,7 @@
-
+
diff --git a/frontend/src/components/forms/DeckEditor.vue b/frontend/src/components/forms/DeckEditor.vue
index 6279fd1..6fba9bb 100644
--- a/frontend/src/components/forms/DeckEditor.vue
+++ b/frontend/src/components/forms/DeckEditor.vue
@@ -1,5 +1,5 @@
-
+
{{ check.count }} cards detected! (Decks should have exactly 50 cards)
@@ -10,33 +10,26 @@
-
- cancel
- cancel
-
-
+
-
+
check
validate
-
+
save
save
@@ -52,8 +45,7 @@ export default {
name: 'DeckEditor',
props: {
- deck: Object,
- visible: Boolean
+ deck: Object
},
data: () => ({
@@ -62,31 +54,22 @@ export default {
maximum: 0,
checked: false
},
- new_decklist: null
+ new_deck: {}
}),
created() {
- this.new_decklist = this.deck.deckList()
- },
+ this.new_deck = new Deck(0)
- computed: {
- new_deck() {
- let deck = new Deck()
- deck.from_deckList(this.new_decklist)
- deck.populate()
-
- this.new_decklist = deck.deckList()
- return deck
- }
+ if (this.deck)
+ // this.deck should already be populated!
+ this.new_deck.from_object(this.deck)
},
methods: {
- close() {
- this.check.checked = false
- this.$emit('close')
- },
+ validate() {
+ this.new_deck.from_deckList(this.$refs.deckList.lazyValue)
+ this.new_deck.populate()
- check_deck() {
// count number of cards
this.check.count = this.new_deck.count()
@@ -100,9 +83,8 @@ export default {
this.check.checked = true
},
- save_deck() {
- this.$emit('change', this.new_deck.plainObject())
- this.close()
+ save() {
+ this.$emit('save', this.new_deck)
}
}
}