1
0
mirror of https://github.com/tcgdex/cards-database.git synced 2025-07-29 03:09:49 +00:00

feat: Add status Dashboard (#187)

* feat: Add status Dashboard

Still need some polishing like using the compiler instead of the live DB

Signed-off-by: Avior <github@avior.me>

* refactor: Simplified compiler files generators

Signed-off-by: Avior <florian.bouillon@delta-wings.net>

* chore: Add step to compiler for stats and optimize

Signed-off-by: Avior <github@avior.me>

* refactor: Remove unused variable

Signed-off-by: Avior <github@avior.me>
This commit is contained in:
2021-11-23 15:12:50 +00:00
committed by GitHub
parent 8ef099273e
commit 762ce389c1
18 changed files with 431 additions and 142 deletions

View File

@ -54,7 +54,8 @@ export async function cardToCardSingle(localId: string, card: Card, lang: Suppor
firstEdition: typeof card.variants?.firstEdition === 'boolean' ? card.variants.firstEdition : false,
holo: typeof card.variants?.holo === 'boolean' ? card.variants.holo : true,
normal: typeof card.variants?.normal === 'boolean' ? card.variants.normal : true,
reverse: typeof card.variants?.reverse === 'boolean' ? card.variants.reverse : true
reverse: typeof card.variants?.reverse === 'boolean' ? card.variants.reverse : true,
wPromo: typeof card.variants?.wPromo === 'boolean' ? card.variants.wPromo : false
},
@ -120,6 +121,12 @@ export async function getCard(serie: string, setName: string, id: string): Promi
return (await import(`../../${DB_PATH}/data/${serie}/${setName}/${id}.js`)).default
}
/**
* Get cards filtered by the language they are available in
* @param lang the language of the cards
* @param set the set to filter in (optional)
* @returns An array with the 0 = localId, 1 = Card Object
*/
export async function getCards(lang: SupportedLanguages, set?: Set): Promise<Array<[string, Card]>> {
const cards = await smartGlob(`${DB_PATH}/data/${(set && set.serie.name.en) ?? '*'}/${(set && set.name.en) ?? '*'}/*.js`)
const list: Array<[string, Card]> = []

View File

@ -57,6 +57,8 @@ export async function serieToSerieSingle(serie: Serie, lang: SupportedLanguages)
.sort((a, b) => a.releaseDate > b.releaseDate ? 1 : -1)
.map((el) => setToSetSimple(el, lang)))
const logo = sets.find((set) => set.logo)?.logo
// Final data
return {
id: serie.id,
logo,

View File

@ -15,7 +15,7 @@ export function isSetAvailable(set: Set, lang: SupportedLanguages): boolean {
/**
* Return the set
* @param name the name of the set (don't include.js/.ts)
* @param name the name of the set
*/
export async function getSet(name: string, serie = '*'): Promise<Set> {
if (!setCache[name]) {

View File

@ -11,6 +11,11 @@ export const DB_PATH = "../"
const fileCache: fileCacheInterface = {}
/**
* Fetch a JSON file from a remote location
* @param url the URL to fetch
* @returns the JSON file content
*/
export async function fetchRemoteFile<T = any>(url: string): Promise<T> {
if (!fileCache[url]) {
const resp = await fetch(url, {
@ -32,6 +37,13 @@ export async function smartGlob(query: string): Promise<Array<string>> {
return globCache[query]
}
/**
* Check if a card is currently Legal
* @param type the type of legality
* @param card the card to check
* @param localId the card localid
* @returns {boolean} if the card is currently in the legal type
*/
export function cardIsLegal(type: 'standard' | 'expanded', card: Card, localId: string): boolean {
const legal = legals[type]
if (
@ -47,6 +59,12 @@ export function cardIsLegal(type: 'standard' | 'expanded', card: Card, localId:
return false
}
/**
* Check if a set is currently Legal
* @param type the type of legality
* @param set the set to check
* @returns {boolean} if the set is currently in the legal type
*/
export function setIsLegal(type: 'standard' | 'expanded', set: Set): boolean {
const legal = legals[type]
if (