Add basic deck builder #12
4 changed files with 60 additions and 12 deletions
|
@ -1,7 +1,12 @@
|
||||||
<template>
|
<template>
|
||||||
<section class="cardpicker" :style="grid">
|
<section class="cardpicker" :style="grid">
|
||||||
<article class="ccgcard" v-for="(card, i) in cards" :key="i + card.ID">
|
<article
|
||||||
<img :src="imageURL(card.ID)" />
|
@click="_picked(card.data)"
|
||||||
|
class="ccgcard"
|
||||||
|
v-for="(card, i) in cards"
|
||||||
|
:key="i + card.data.ID"
|
||||||
|
>
|
||||||
|
<img :src="imageURL(card.data.ID)" />
|
||||||
</article>
|
</article>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
@ -23,14 +28,14 @@ $padding: 10px;
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Component, Vue, Prop } from "vue-property-decorator";
|
import { Component, Vue, Prop } from "vue-property-decorator";
|
||||||
import { Card, cardImageURL } from "@/mlpccg";
|
import { Card, CardSlot, cardImageURL } from "@/mlpccg";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
components: {}
|
components: {}
|
||||||
})
|
})
|
||||||
export default class CardPicker extends Vue {
|
export default class CardPicker extends Vue {
|
||||||
@Prop()
|
@Prop()
|
||||||
public cards!: Card[];
|
public cards!: CardSlot[];
|
||||||
|
|
||||||
@Prop({ default: 2 })
|
@Prop({ default: 2 })
|
||||||
public rows!: number;
|
public rows!: number;
|
||||||
|
@ -48,5 +53,9 @@ export default class CardPicker extends Vue {
|
||||||
private imageURL(id: string) {
|
private imageURL(id: string) {
|
||||||
return cardImageURL(id);
|
return cardImageURL(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private picked(card: Card) {
|
||||||
|
this.$emit("picked", card);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
<template>
|
<template>
|
||||||
<section class="decklist">
|
<section class="decklist">
|
||||||
<article v-for="(card, i) in cards" :key="i">
|
<article v-for="(card, i) in cards" :key="i">
|
||||||
<div class="name">{{ fullName(card) }}</div>
|
<div class="amt">{{ card.howmany }}</div>
|
||||||
|
<div class="name">{{ fullName(card.data) }}</div>
|
||||||
</article>
|
</article>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
@ -14,14 +15,14 @@
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Component, Vue, Prop } from "vue-property-decorator";
|
import { Component, Vue, Prop } from "vue-property-decorator";
|
||||||
import { Card, cardFullName } from "@/mlpccg";
|
import { cardFullName, CardSlot, Card } from "@/mlpccg";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
components: {}
|
components: {}
|
||||||
})
|
})
|
||||||
export default class DeckList extends Vue {
|
export default class DeckList extends Vue {
|
||||||
@Prop()
|
@Prop()
|
||||||
public cards!: Card[];
|
public cards!: CardSlot[];
|
||||||
|
|
||||||
private fullName(card: Card): string {
|
private fullName(card: Card): string {
|
||||||
return cardFullName(card);
|
return cardFullName(card);
|
||||||
|
|
|
@ -43,3 +43,9 @@ export interface CardFilter {
|
||||||
Powers?: number[];
|
Powers?: number[];
|
||||||
Rarities?: string[];
|
Rarities?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CardSlot {
|
||||||
|
data: Card;
|
||||||
|
limit: number;
|
||||||
|
howmany: number;
|
||||||
|
}
|
||||||
|
|
|
@ -30,7 +30,12 @@
|
||||||
<div @click="prevPage" :class="canGoPrev ? 'prev' : 'prev unavailable'">
|
<div @click="prevPage" :class="canGoPrev ? 'prev' : 'prev unavailable'">
|
||||||
<img src="/images/deckbuilder/navarrow.svg" />
|
<img src="/images/deckbuilder/navarrow.svg" />
|
||||||
</div>
|
</div>
|
||||||
<CardPicker :columns="columns" :rows="rows" :cards="currentPage" />
|
<CardPicker
|
||||||
|
@picked="cardPicked"
|
||||||
|
:columns="columns"
|
||||||
|
:rows="rows"
|
||||||
|
:cards="currentPage"
|
||||||
|
/>
|
||||||
<div @click="nextPage" :class="canGoNext ? 'next' : 'next unavailable'">
|
<div @click="nextPage" :class="canGoNext ? 'next' : 'next unavailable'">
|
||||||
<img src="/images/deckbuilder/navarrow.svg" />
|
<img src="/images/deckbuilder/navarrow.svg" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -127,7 +132,14 @@
|
||||||
import { Component, Vue } from "vue-property-decorator";
|
import { Component, Vue } from "vue-property-decorator";
|
||||||
import DeckList from "@/components/DeckBuilder/DeckList.vue";
|
import DeckList from "@/components/DeckBuilder/DeckList.vue";
|
||||||
import CardPicker from "@/components/DeckBuilder/CardPicker.vue";
|
import CardPicker from "@/components/DeckBuilder/CardPicker.vue";
|
||||||
import { Card, CardFilter, getCards, allSets, cardFullName } from "@/mlpccg";
|
import {
|
||||||
|
Card,
|
||||||
|
CardFilter,
|
||||||
|
CardSlot,
|
||||||
|
getCards,
|
||||||
|
allSets,
|
||||||
|
cardFullName
|
||||||
|
} from "@/mlpccg";
|
||||||
|
|
||||||
const colorNames = [
|
const colorNames = [
|
||||||
"Loyalty",
|
"Loyalty",
|
||||||
|
@ -257,7 +269,7 @@ function sortByColor(a: Card, b: Card) {
|
||||||
})
|
})
|
||||||
export default class DeckBuilder extends Vue {
|
export default class DeckBuilder extends Vue {
|
||||||
// Picked/filtered cards
|
// Picked/filtered cards
|
||||||
private decklist!: Card[];
|
private decklist!: CardSlot[];
|
||||||
private filtered!: Card[];
|
private filtered!: Card[];
|
||||||
|
|
||||||
// Names
|
// Names
|
||||||
|
@ -315,8 +327,14 @@ export default class DeckBuilder extends Vue {
|
||||||
return this.columns * this.rows;
|
return this.columns * this.rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
private get currentPage() {
|
private get currentPage(): CardSlot[] {
|
||||||
return this.filtered.slice(this.offset, this.offset + this.itemsPerPage);
|
return this.filtered
|
||||||
|
.slice(this.offset, this.offset + this.itemsPerPage)
|
||||||
|
.map(card => ({
|
||||||
|
data: card,
|
||||||
|
limit: card.Type == "Problem" ? 2 : 3,
|
||||||
|
howmany: this.decklist.filter(c => c.data.ID == card.ID).length
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private elementIconURL(element: string): string {
|
private elementIconURL(element: string): string {
|
||||||
|
@ -387,5 +405,19 @@ export default class DeckBuilder extends Vue {
|
||||||
this.offset + this.itemsPerPage
|
this.offset + this.itemsPerPage
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private cardPicked(card: Card) {
|
||||||
|
// Check if card is already in
|
||||||
|
const idx = this.decklist.findIndex(c => c.data.ID == card.ID);
|
||||||
|
if (idx >= 0) {
|
||||||
|
this.decklist[idx].howmany += 1;
|
||||||
|
} else {
|
||||||
|
this.decklist.push({
|
||||||
|
data: card,
|
||||||
|
limit: card.Type == "Problem" ? 2 : 3,
|
||||||
|
howmany: 1
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue