Integrate CardPicker in DeckBuilder
This commit is contained in:
parent
5c908db181
commit
83058c5879
5 changed files with 81 additions and 20 deletions
|
@ -1,12 +1,52 @@
|
|||
<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>
|
||||
|
||||
<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">
|
||||
import { Component, Vue } from "vue-property-decorator";
|
||||
import { Component, Vue, Prop } from "vue-property-decorator";
|
||||
import { Card, cardImageURL } from "@/mlpccg";
|
||||
|
||||
@Component({
|
||||
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>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<template>
|
||||
<section class="decklist">
|
||||
<article v-for="(card, i) in cards" :key="i">
|
||||
<div class="name">{{fullname(card)}}</div>
|
||||
<div class="name">{{ cardFullName(card) }}</div>
|
||||
</article>
|
||||
</section>
|
||||
</template>
|
||||
|
@ -14,22 +14,13 @@
|
|||
|
||||
<script lang="ts">
|
||||
import { Component, Vue, Prop } from "vue-property-decorator";
|
||||
import { Card } from "@/mlpccg/types";
|
||||
import { Card, cardFullName } from "@/mlpccg";
|
||||
|
||||
@Component({
|
||||
components: {}
|
||||
})
|
||||
export default class DeckList extends Vue {
|
||||
@Prop({
|
||||
default: []
|
||||
})
|
||||
@Prop()
|
||||
public cards!: Card[];
|
||||
|
||||
private fullname(card: Card): string {
|
||||
if (card.Subname != "") {
|
||||
return `${card.Name}, ${card.Subname}`;
|
||||
}
|
||||
return card.Name;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
import { Card } from "./types";
|
||||
|
||||
const imgBaseURL = "https://mcg.zyg.ovh/images/cards/";
|
||||
|
||||
export function cardImageURL(cardid: string): string {
|
||||
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="filters"></section>
|
||||
<section class="cards">
|
||||
<CardPicker :cards="filtered" />
|
||||
<CardPicker :columns="columns" :rows="rows" :cards="currentPage" />
|
||||
</section>
|
||||
</section>
|
||||
<section class="decklist">
|
||||
|
@ -24,7 +24,7 @@
|
|||
.cardlist {
|
||||
display: grid;
|
||||
grid-column: 1;
|
||||
grid-template-rows: 50px 1fr;
|
||||
grid-template-rows: 100px 1fr;
|
||||
}
|
||||
.decklist {
|
||||
grid-column: 2;
|
||||
|
@ -37,10 +37,9 @@
|
|||
|
||||
<script lang="ts">
|
||||
import { Component, Vue } from "vue-property-decorator";
|
||||
import { Card, CardFilter } from "@/mlpccg/types";
|
||||
import DeckList from "@/components/DeckBuilder/DeckList.vue";
|
||||
import CardPicker from "@/components/DeckBuilder/CardPicker.vue";
|
||||
import { getCards } from "@/mlpccg/database";
|
||||
import { Card, CardFilter, getCards } from "@/mlpccg";
|
||||
|
||||
@Component({
|
||||
components: {
|
||||
|
@ -52,17 +51,35 @@ export default class DeckBuilder extends Vue {
|
|||
private decklist!: Card[];
|
||||
private filter!: CardFilter;
|
||||
private filtered!: Card[];
|
||||
private offset!: number;
|
||||
private rows!: number;
|
||||
private columns!: number;
|
||||
|
||||
private data() {
|
||||
return {
|
||||
decklist: [],
|
||||
filter: {},
|
||||
filtered: []
|
||||
filtered: [],
|
||||
offset: 0,
|
||||
rows: 2,
|
||||
columns: 5
|
||||
};
|
||||
}
|
||||
|
||||
private mounted() {
|
||||
this.applyFilters();
|
||||
}
|
||||
|
||||
private async applyFilters() {
|
||||
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>
|
||||
|
|
Loading…
Reference in a new issue