Add basic deck builder #12

Merged
hamcha merged 42 commits from feature/deckbuilder into master 2019-09-12 09:11:32 +00:00
4 changed files with 28 additions and 18 deletions
Showing only changes of commit 0eb8e1a47d - Show all commits

View file

@ -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");

View file

@ -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);
}

View file

@ -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[];

View file

@ -187,6 +187,7 @@ 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) {
@ -195,16 +196,19 @@ function sortByColor(a: Card, b: Card) {
if (elemB > elemA) {
return -1;
}
}
break;
case "Problem":
const preqA = multiElemStr(Object.keys(a.ProblemRequirement!));
const preqB = multiElemStr(Object.keys(b.ProblemRequirement!));
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":
case "Resource":