diff --git a/src/mlpccg/database.ts b/src/mlpccg/database.ts index 9e4502d..16d6991 100644 --- a/src/mlpccg/database.ts +++ b/src/mlpccg/database.ts @@ -1,15 +1,16 @@ import Dexie from "dexie"; -import { Card, CardFilter } from "./types"; +import { Card, CardFilter, StoredImages } from "./types"; import { cardFullName } from "./card"; class CardDatabase extends Dexie { public cards: Dexie.Table; - public images: Dexie.Table; + public images: Dexie.Table; public constructor() { super("CardDatabase"); this.version(1).stores({ - cards: "ID,Set,Type,Cost,Power" + cards: "ID,Set,Type,Cost,Power", + images: "id" }); this.cards = this.table("cards"); this.images = this.table("images"); diff --git a/src/mlpccg/images.ts b/src/mlpccg/images.ts index 1bbd3b1..6e5da16 100644 --- a/src/mlpccg/images.ts +++ b/src/mlpccg/images.ts @@ -25,7 +25,7 @@ export async function getImages() { url: `${imgBaseURL}${img}`, responseType: "blob" }); - return table.put(req.data, img); + return table.put({ id: img, image: req.data }); }); return await Promise.all(promises); } diff --git a/src/mlpccg/types.ts b/src/mlpccg/types.ts index 2630a48..01cbbb4 100644 --- a/src/mlpccg/types.ts +++ b/src/mlpccg/types.ts @@ -2,6 +2,11 @@ export type Rarity = "C" | "U" | "R" | "SR" | "UR" | "RR"; export type PowerRequirement = { [key: string]: number }; +export interface StoredImages { + id: string; + image: Blob; +} + export interface SetFile { Name: string; Cards: Card[]; diff --git a/src/views/DeckBuilder.vue b/src/views/DeckBuilder.vue index c4ab95e..0591a67 100644 --- a/src/views/DeckBuilder.vue +++ b/src/views/DeckBuilder.vue @@ -187,23 +187,27 @@ function sortByColor(a: Card, b: Card) { switch (a.Type) { case "Friend": case "Mane Character": - const elemA = multiElemStr(a.Element); - const elemB = multiElemStr(b.Element); - if (elemA > elemB) { - return 1; - } - if (elemB > elemA) { - return -1; + { + const elemA = multiElemStr(a.Element); + const elemB = multiElemStr(b.Element); + if (elemA > elemB) { + return 1; + } + if (elemB > elemA) { + return -1; + } } break; case "Problem": - const preqA = multiElemStr(Object.keys(a.ProblemRequirement!)); - const preqB = multiElemStr(Object.keys(b.ProblemRequirement!)); - if (preqA > preqB) { - return 1; - } - if (preqB > preqA) { - return -1; + if (a.ProblemRequirement && b.ProblemRequirement) { + const preqA = multiElemStr(Object.keys(a.ProblemRequirement)); + const preqB = multiElemStr(Object.keys(b.ProblemRequirement)); + if (preqA > preqB) { + return 1; + } + if (preqB > preqA) { + return -1; + } } break; case "Event":