Properly initialize images database
This commit is contained in:
parent
f67ad90f69
commit
0eb8e1a47d
4 changed files with 28 additions and 18 deletions
|
@ -1,15 +1,16 @@
|
||||||
import Dexie from "dexie";
|
import Dexie from "dexie";
|
||||||
import { Card, CardFilter } from "./types";
|
import { Card, CardFilter, StoredImages } from "./types";
|
||||||
import { cardFullName } from "./card";
|
import { cardFullName } from "./card";
|
||||||
|
|
||||||
class CardDatabase extends Dexie {
|
class CardDatabase extends Dexie {
|
||||||
public cards: Dexie.Table<Card, string>;
|
public cards: Dexie.Table<Card, string>;
|
||||||
public images: Dexie.Table<Blob, string>;
|
public images: Dexie.Table<StoredImages, string>;
|
||||||
|
|
||||||
public constructor() {
|
public constructor() {
|
||||||
super("CardDatabase");
|
super("CardDatabase");
|
||||||
this.version(1).stores({
|
this.version(1).stores({
|
||||||
cards: "ID,Set,Type,Cost,Power"
|
cards: "ID,Set,Type,Cost,Power",
|
||||||
|
images: "id"
|
||||||
});
|
});
|
||||||
this.cards = this.table("cards");
|
this.cards = this.table("cards");
|
||||||
this.images = this.table("images");
|
this.images = this.table("images");
|
||||||
|
|
|
@ -25,7 +25,7 @@ export async function getImages() {
|
||||||
url: `${imgBaseURL}${img}`,
|
url: `${imgBaseURL}${img}`,
|
||||||
responseType: "blob"
|
responseType: "blob"
|
||||||
});
|
});
|
||||||
return table.put(req.data, img);
|
return table.put({ id: img, image: req.data });
|
||||||
});
|
});
|
||||||
return await Promise.all(promises);
|
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 type PowerRequirement = { [key: string]: number };
|
||||||
|
|
||||||
|
export interface StoredImages {
|
||||||
|
id: string;
|
||||||
|
image: Blob;
|
||||||
|
}
|
||||||
|
|
||||||
export interface SetFile {
|
export interface SetFile {
|
||||||
Name: string;
|
Name: string;
|
||||||
Cards: Card[];
|
Cards: Card[];
|
||||||
|
|
|
@ -187,6 +187,7 @@ function sortByColor(a: Card, b: Card) {
|
||||||
switch (a.Type) {
|
switch (a.Type) {
|
||||||
case "Friend":
|
case "Friend":
|
||||||
case "Mane Character":
|
case "Mane Character":
|
||||||
|
{
|
||||||
const elemA = multiElemStr(a.Element);
|
const elemA = multiElemStr(a.Element);
|
||||||
const elemB = multiElemStr(b.Element);
|
const elemB = multiElemStr(b.Element);
|
||||||
if (elemA > elemB) {
|
if (elemA > elemB) {
|
||||||
|
@ -195,16 +196,19 @@ function sortByColor(a: Card, b: Card) {
|
||||||
if (elemB > elemA) {
|
if (elemB > elemA) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "Problem":
|
case "Problem":
|
||||||
const preqA = multiElemStr(Object.keys(a.ProblemRequirement!));
|
if (a.ProblemRequirement && b.ProblemRequirement) {
|
||||||
const preqB = multiElemStr(Object.keys(b.ProblemRequirement!));
|
const preqA = multiElemStr(Object.keys(a.ProblemRequirement));
|
||||||
|
const preqB = multiElemStr(Object.keys(b.ProblemRequirement));
|
||||||
if (preqA > preqB) {
|
if (preqA > preqB) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (preqB > preqA) {
|
if (preqB > preqA) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "Event":
|
case "Event":
|
||||||
case "Resource":
|
case "Resource":
|
||||||
|
|
Loading…
Reference in a new issue