diff --git a/src/mlpccg/database.ts b/src/mlpccg/database.ts index 641f702..9923fd5 100644 --- a/src/mlpccg/database.ts +++ b/src/mlpccg/database.ts @@ -1,5 +1,6 @@ import Dexie from "dexie"; import { Card, CardFilter } from "./types"; +import { cardFullName } from "./card"; class CardDatabase extends Dexie { public cards: Dexie.Table; @@ -43,95 +44,91 @@ export async function getCards(filter: CardFilter) { } } - return await query - .filter(x => { - if (filter.Name) { - if ( - !`${x.Name}, ${x.Subname}` - .toLowerCase() - .includes(filter.Name.toLowerCase()) - ) { - return false; + const results = query.filter(x => { + if (filter.Name) { + if ( + !cardFullName(x) + .toLowerCase() + .includes(filter.Name.toLowerCase()) + ) { + return false; + } + } + if (filter.Rules) { + if ( + !`${x.Keywords.join(" ~ ")} ~ ${x.Text}` + .toLowerCase() + .includes(filter.Rules.toLowerCase()) + ) { + return false; + } + } + if (filter.Traits && filter.Traits.length > 0) { + let found = false; + for (const trait of x.Traits) { + if (filter.Traits.includes(trait)) { + found = true; + break; } } - if (filter.Rules) { - if ( - !`${x.Keywords.join(" ~ ")} ~ ${x.Text}` - .toLowerCase() - .includes(filter.Rules.toLowerCase()) - ) { - return false; + if (!found) { + return false; + } + } + if (filter.Sets && filter.Sets.length > 0) { + if (!filter.Sets.includes(x.Set)) { + return false; + } + } + if (filter.Types && filter.Types.length > 0) { + if (!filter.Types.includes(x.Type)) { + return false; + } + } + if (filter.Elements && filter.Elements.length > 0) { + let found = false; + for (const element of x.Element) { + if (filter.Elements.includes(element)) { + found = true; + break; } } - if (filter.Traits && filter.Traits.length > 0) { - let found = false; - for (const trait of x.Traits) { - if (filter.Traits.includes(trait)) { - found = true; - break; - } - } - if (!found) { - return false; - } - } - if (filter.Sets && filter.Sets.length > 0) { - if (!filter.Sets.includes(x.Set)) { - return false; - } - } - if (filter.Types && filter.Types.length > 0) { - if (!filter.Types.includes(x.Type)) { - return false; - } - } - if (filter.Elements && filter.Elements.length > 0) { - let found = false; - for (const element of x.Element) { + if (x.Requirement) { + for (const element in x.Requirement) { if (filter.Elements.includes(element)) { found = true; break; } } - if (x.Requirement) { - for (const element in x.Requirement) { - if (filter.Elements.includes(element)) { - found = true; - break; - } + } + if (x.ProblemRequirement) { + for (const element in x.ProblemRequirement) { + if (filter.Elements.includes(element)) { + found = true; + break; } } - if (x.ProblemRequirement) { - for (const element in x.ProblemRequirement) { - if (filter.Elements.includes(element)) { - found = true; - break; - } - } - } - if (!found) { - return false; - } } - if (filter.Powers && filter.Powers.length > 0) { - if ( - typeof x.Power === "undefined" || - !filter.Powers.includes(x.Power) - ) { - return false; - } + if (!found) { + return false; } - if (filter.Costs && filter.Costs.length > 0) { - if (typeof x.Cost === "undefined" || !filter.Costs.includes(x.Cost)) { - return false; - } + } + if (filter.Powers && filter.Powers.length > 0) { + if (typeof x.Power === "undefined" || !filter.Powers.includes(x.Power)) { + return false; } - if (filter.Rarities && filter.Rarities.length > 0) { - if (!filter.Rarities.includes(x.Rarity)) { - return false; - } + } + if (filter.Costs && filter.Costs.length > 0) { + if (typeof x.Cost === "undefined" || !filter.Costs.includes(x.Cost)) { + return false; } - return true; - }) - .toArray(); + } + if (filter.Rarities && filter.Rarities.length > 0) { + if (!filter.Rarities.includes(x.Rarity)) { + return false; + } + } + return true; + }); + return await results.toArray(); } diff --git a/src/mlpccg/set.ts b/src/mlpccg/set.ts index 694a360..e6a5538 100644 --- a/src/mlpccg/set.ts +++ b/src/mlpccg/set.ts @@ -2,7 +2,7 @@ import { SetFile } from "./types"; import { Database } from "./database"; const baseURL = "https://mcg.zyg.ovh/setdata/"; -const allSets = [ +export const allSets = [ "PR", "CN", "RR", diff --git a/src/views/DeckBuilder.vue b/src/views/DeckBuilder.vue index bff7f6f..77f75d9 100644 --- a/src/views/DeckBuilder.vue +++ b/src/views/DeckBuilder.vue @@ -1,7 +1,31 @@