Add basic deck builder #12
5 changed files with 81 additions and 20 deletions
|
@ -1,12 +1,52 @@
|
||||||
<template>
|
<template>
|
||||||
<section></section>
|
<section class="cardpicker" :style="grid">
|
||||||
|
<article class="ccgcard" v-for="(card, i) in cards" :key="i">
|
||||||
|
<img :src="imageURL(card.ID)" />
|
||||||
|
</article>
|
||||||
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
$padding: 10px;
|
||||||
|
|
||||||
|
.cardpicker {
|
||||||
|
height: 100%;
|
||||||
|
display: grid;
|
||||||
|
grid-gap: $padding;
|
||||||
|
padding: $padding;
|
||||||
|
.ccgcard {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Component, Vue } from "vue-property-decorator";
|
import { Component, Vue, Prop } from "vue-property-decorator";
|
||||||
|
import { Card, cardImageURL } from "@/mlpccg";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
components: {}
|
components: {}
|
||||||
})
|
})
|
||||||
export default class CardPicker extends Vue {}
|
export default class CardPicker extends Vue {
|
||||||
|
@Prop()
|
||||||
|
public cards!: Card[];
|
||||||
|
|
||||||
|
@Prop({ default: 2 })
|
||||||
|
public rows!: number;
|
||||||
|
|
||||||
|
@Prop({ default: 5 })
|
||||||
|
public columns!: number;
|
||||||
|
|
||||||
|
private get grid() {
|
||||||
|
return {
|
||||||
|
gridTemplateRows: "1fr ".repeat(this.rows).trim(),
|
||||||
|
gridTemplateColumns: "1fr ".repeat(this.columns).trim()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private imageURL(id: string) {
|
||||||
|
return cardImageURL(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<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="name">{{ cardFullName(card) }}</div>
|
||||||
</article>
|
</article>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
@ -14,22 +14,13 @@
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Component, Vue, Prop } from "vue-property-decorator";
|
import { Component, Vue, Prop } from "vue-property-decorator";
|
||||||
import { Card } from "@/mlpccg/types";
|
import { Card, cardFullName } from "@/mlpccg";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
components: {}
|
components: {}
|
||||||
})
|
})
|
||||||
export default class DeckList extends Vue {
|
export default class DeckList extends Vue {
|
||||||
@Prop({
|
@Prop()
|
||||||
default: []
|
|
||||||
})
|
|
||||||
public cards!: Card[];
|
public cards!: Card[];
|
||||||
|
|
||||||
private fullname(card: Card): string {
|
|
||||||
if (card.Subname != "") {
|
|
||||||
return `${card.Name}, ${card.Subname}`;
|
|
||||||
}
|
|
||||||
return card.Name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
|
import { Card } from "./types";
|
||||||
|
|
||||||
const imgBaseURL = "https://mcg.zyg.ovh/images/cards/";
|
const imgBaseURL = "https://mcg.zyg.ovh/images/cards/";
|
||||||
|
|
||||||
export function cardImageURL(cardid: string): string {
|
export function cardImageURL(cardid: string): string {
|
||||||
return `${imgBaseURL}${cardid}.webp`;
|
return `${imgBaseURL}${cardid}.webp`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function cardFullName(card: Card): string {
|
||||||
|
if (card.Subname != "") {
|
||||||
|
return `${card.Name}, ${card.Subname}`;
|
||||||
|
}
|
||||||
|
return card.Name;
|
||||||
|
}
|
||||||
|
|
4
src/mlpccg/index.ts
Normal file
4
src/mlpccg/index.ts
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
export * from "./card";
|
||||||
|
export * from "./database";
|
||||||
|
export * from "./set";
|
||||||
|
export * from "./types";
|
|
@ -3,7 +3,7 @@
|
||||||
<section class="cardlist">
|
<section class="cardlist">
|
||||||
<section class="filters"></section>
|
<section class="filters"></section>
|
||||||
<section class="cards">
|
<section class="cards">
|
||||||
<CardPicker :cards="filtered" />
|
<CardPicker :columns="columns" :rows="rows" :cards="currentPage" />
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
<section class="decklist">
|
<section class="decklist">
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
.cardlist {
|
.cardlist {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-column: 1;
|
grid-column: 1;
|
||||||
grid-template-rows: 50px 1fr;
|
grid-template-rows: 100px 1fr;
|
||||||
}
|
}
|
||||||
.decklist {
|
.decklist {
|
||||||
grid-column: 2;
|
grid-column: 2;
|
||||||
|
@ -37,10 +37,9 @@
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Component, Vue } from "vue-property-decorator";
|
import { Component, Vue } from "vue-property-decorator";
|
||||||
import { Card, CardFilter } from "@/mlpccg/types";
|
|
||||||
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 { getCards } from "@/mlpccg/database";
|
import { Card, CardFilter, getCards } from "@/mlpccg";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
components: {
|
components: {
|
||||||
|
@ -52,17 +51,35 @@ export default class DeckBuilder extends Vue {
|
||||||
private decklist!: Card[];
|
private decklist!: Card[];
|
||||||
private filter!: CardFilter;
|
private filter!: CardFilter;
|
||||||
private filtered!: Card[];
|
private filtered!: Card[];
|
||||||
|
private offset!: number;
|
||||||
|
private rows!: number;
|
||||||
|
private columns!: number;
|
||||||
|
|
||||||
private data() {
|
private data() {
|
||||||
return {
|
return {
|
||||||
decklist: [],
|
decklist: [],
|
||||||
filter: {},
|
filter: {},
|
||||||
filtered: []
|
filtered: [],
|
||||||
|
offset: 0,
|
||||||
|
rows: 2,
|
||||||
|
columns: 5
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private mounted() {
|
||||||
|
this.applyFilters();
|
||||||
|
}
|
||||||
|
|
||||||
private async applyFilters() {
|
private async applyFilters() {
|
||||||
this.filtered = await getCards(this.filter);
|
this.filtered = await getCards(this.filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private get itemsPerPage() {
|
||||||
|
return this.columns * this.rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
private get currentPage() {
|
||||||
|
return this.filtered.slice(this.offset, this.itemsPerPage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue