Compare commits
No commits in common. "94a8f69cfdfbcf71863ef60f0d456fa73b957f7d" and "296ab79bd6ee7dcf77f33e85d62408ab10e158a0" have entirely different histories.
94a8f69cfd
...
296ab79bd6
2 changed files with 33 additions and 179 deletions
|
|
@ -24,19 +24,24 @@
|
||||||
</v-list>
|
</v-list>
|
||||||
</v-card>
|
</v-card>
|
||||||
</v-flex>
|
</v-flex>
|
||||||
|
|
||||||
<v-btn fab absolute bottom right @click.native="editing = true">
|
<v-btn fab absolute bottom right @click.native="editing = true">
|
||||||
<v-icon>edit</v-icon>
|
<v-icon>edit</v-icon>
|
||||||
</v-btn>
|
</v-btn>
|
||||||
</v-layout>
|
</v-layout>
|
||||||
<DeckEditor v-if="editing" :deck_list="deck_list" />
|
<v-form v-if="editing" lazy-validation>
|
||||||
|
<v-textarea
|
||||||
|
label="Edit Deck"
|
||||||
|
value="The Woodman set to work at once, and so sharp was his axe that the tree was soon chopped nearly through."
|
||||||
|
hint="Paste a deck list"
|
||||||
|
></v-textarea>
|
||||||
|
</v-form>
|
||||||
</v-container>
|
</v-container>
|
||||||
</v-expansion-panel-content>
|
</v-expansion-panel-content>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Card from './Card.vue'
|
import Card from './Card.vue'
|
||||||
import DeckEditor from './forms/DeckEditor.vue'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Deck',
|
name: 'Deck',
|
||||||
|
|
@ -46,8 +51,7 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
components: {
|
components: {
|
||||||
Card,
|
Card
|
||||||
DeckEditor
|
|
||||||
},
|
},
|
||||||
|
|
||||||
data: () => ({
|
data: () => ({
|
||||||
|
|
@ -56,59 +60,36 @@ export default {
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
deck_parts() {
|
deck_parts() {
|
||||||
let retval = ['Forwards', 'Backups', 'Summons, Monsters & more'].map(
|
let retval = {
|
||||||
item => ({
|
forwards: {
|
||||||
heading: item,
|
heading: 'Forwards',
|
||||||
cards: [],
|
cards: this.deck.cards.filter(card => card.dbentry.type === 'Forward')
|
||||||
count: 0
|
},
|
||||||
})
|
backups: {
|
||||||
)
|
heading: 'Backups',
|
||||||
|
cards: this.deck.cards.filter(card => card.dbentry.type === 'Backup')
|
||||||
this.deck.cards.forEach(card => {
|
},
|
||||||
let target
|
rest: {
|
||||||
switch (card.dbentry.type) {
|
heading: 'Summons, Monsters & more',
|
||||||
case 'Forward':
|
cards: this.deck.cards.filter(
|
||||||
target = 0
|
card =>
|
||||||
break
|
card.dbentry.type != 'Forward' && card.dbentry.type != 'Backup'
|
||||||
case 'Backup':
|
)
|
||||||
target = 1
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
target = 2
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
retval[target].cards.push(card)
|
}
|
||||||
retval[target].count += card.count
|
|
||||||
})
|
|
||||||
|
|
||||||
retval.forEach(part =>
|
for (let i = 0; i < Object.keys(retval).length; i++) {
|
||||||
part.cards.sort(
|
let key = Object.keys(retval)[i]
|
||||||
|
retval[key].count = retval[key].cards.reduce(
|
||||||
|
(result, card) => result + card.count,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
retval[key].cards.sort(
|
||||||
(card_l, card_r) => card_l.dbentry.cost - card_r.dbentry.cost
|
(card_l, card_r) => card_l.dbentry.cost - card_r.dbentry.cost
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
|
|
||||||
return retval
|
return retval
|
||||||
},
|
|
||||||
|
|
||||||
deck_list() {
|
|
||||||
let lines = []
|
|
||||||
|
|
||||||
// begin with deck name and note
|
|
||||||
lines.push('Deck Name: ' + this.deck.name)
|
|
||||||
lines.push(this.deck.note)
|
|
||||||
lines.push('')
|
|
||||||
|
|
||||||
// list forwards
|
|
||||||
this.deck_parts.forEach(part => {
|
|
||||||
lines.push(`${part.heading} (${part.count}):`)
|
|
||||||
|
|
||||||
part.cards.forEach(card =>
|
|
||||||
lines.push(`${card.count}x ${card.serial} "${card.dbentry.name}"`)
|
|
||||||
)
|
|
||||||
lines.push('')
|
|
||||||
})
|
|
||||||
|
|
||||||
return lines.join('\n')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,127 +0,0 @@
|
||||||
<template>
|
|
||||||
<v-form lazy-validation>
|
|
||||||
<v-alert v-model="deck.count !== 50" type="warning">
|
|
||||||
{{ deck.count }} cards detected! (Decks should have 50)
|
|
||||||
</v-alert>
|
|
||||||
|
|
||||||
<v-textarea
|
|
||||||
ref="textarea"
|
|
||||||
label="Edit Deck"
|
|
||||||
:value="deck_list"
|
|
||||||
rows="40"
|
|
||||||
hint="Change card counts and/or serial numbers. Names will be updated automatically."
|
|
||||||
style="font-family: monospace"
|
|
||||||
>
|
|
||||||
</v-textarea>
|
|
||||||
|
|
||||||
<v-spacer></v-spacer>
|
|
||||||
<v-btn color="success" @click.native="check">
|
|
||||||
Check Deck
|
|
||||||
</v-btn>
|
|
||||||
</v-form>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
name: 'DeckEditor',
|
|
||||||
|
|
||||||
props: {
|
|
||||||
deck_list: String
|
|
||||||
},
|
|
||||||
|
|
||||||
data: () => ({
|
|
||||||
deck: {
|
|
||||||
count: 50
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
|
|
||||||
methods: {
|
|
||||||
parse_deck(deck_string) {
|
|
||||||
let retval = {
|
|
||||||
name: '',
|
|
||||||
note: '',
|
|
||||||
cards: [],
|
|
||||||
count: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// select all lines containing card serial numbers
|
|
||||||
let cardLinesRE = /^.*\b\d-\d{3}[A-Z]?\b.*$/gm
|
|
||||||
let cardLines = deck_string.match(cardLinesRE)
|
|
||||||
|
|
||||||
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]
|
|
||||||
|
|
||||||
// strip out serial number
|
|
||||||
cardLine = cardLine.replace(serialRE, '')
|
|
||||||
|
|
||||||
let countREs = [
|
|
||||||
// prioritize a count with "times" symbol *, x, ×
|
|
||||||
/\b([0-9]+)(?:[*×]|[x]\b)/,
|
|
||||||
/(?:[*×]|\b[x])([0-9]+)\b/,
|
|
||||||
// next priority: count with whitespace
|
|
||||||
/\s+([0-9]+)\s+/,
|
|
||||||
/\s+([0-9]+)\b/,
|
|
||||||
/\b([0-9]+)\s+/,
|
|
||||||
// least priority: any simple number
|
|
||||||
/\b([0-9]+)\b/
|
|
||||||
]
|
|
||||||
|
|
||||||
// fallback value
|
|
||||||
let count = 1
|
|
||||||
for (let i = 0; i < countREs.length; i++) {
|
|
||||||
let data = countREs[i].exec(cardLine)
|
|
||||||
|
|
||||||
if (data) {
|
|
||||||
count = Number(data[1])
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// push card data into deck
|
|
||||||
retval.cards.push({
|
|
||||||
serial: serial,
|
|
||||||
count: count
|
|
||||||
})
|
|
||||||
retval.count += count
|
|
||||||
})
|
|
||||||
|
|
||||||
// strip out lines with serial numbers
|
|
||||||
deck_string = deck_string.replace(cardLinesRE, '')
|
|
||||||
|
|
||||||
// select the line containing 'deck name:'
|
|
||||||
// and its successor (ffdecks format)
|
|
||||||
let metaRE = /^Deck Name: (.+)$[\s]*?^(.+)$/m
|
|
||||||
let metaData = metaRE.exec(deck_string)
|
|
||||||
|
|
||||||
// fallback
|
|
||||||
retval.name = 'Unnamed Deck'
|
|
||||||
retval.note = ''
|
|
||||||
|
|
||||||
if (!metaData) {
|
|
||||||
// no ffdecks format found: strip out anything after the first empty line
|
|
||||||
deck_string = deck_string.replace(/^[\s]*$[^]*/m, '')
|
|
||||||
|
|
||||||
// use lax format: <anything>:[deck name][newline][note]
|
|
||||||
metaRE = /[^]*?:(.+)$[\s]*?^([^]*)/m
|
|
||||||
metaData = metaRE.exec(deck_string)
|
|
||||||
}
|
|
||||||
|
|
||||||
// look again, I am not an else!
|
|
||||||
if (metaData) {
|
|
||||||
// extract matches
|
|
||||||
retval.name = metaData[1].trim()
|
|
||||||
retval.note = metaData[2].trim()
|
|
||||||
}
|
|
||||||
|
|
||||||
return retval
|
|
||||||
},
|
|
||||||
|
|
||||||
check() {
|
|
||||||
let new_deck = this.parse_deck(this.$refs.textarea.lazyValue)
|
|
||||||
this.deck.count = new_deck.count
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
Reference in a new issue