Add basic deck builder #12
4 changed files with 28 additions and 18 deletions
|
@ -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<Card, string>;
|
||||
public images: Dexie.Table<Blob, string>;
|
||||
public images: Dexie.Table<StoredImages, string>;
|
||||
|
||||
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");
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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[];
|
||||
|
|
|
@ -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":
|
||||
|
|
Loading…
Reference in a new issue