1
0
mirror of https://github.com/tcgdex/cards-database.git synced 2025-06-15 00:49:18 +00:00

feat: Add support for Asians Pokémon Cards (#481)

This commit is contained in:
2024-06-07 12:53:08 +02:00
committed by GitHub
parent a35fadd50c
commit a26ef0e5eb
8069 changed files with 379200 additions and 423 deletions

View File

@ -4,7 +4,10 @@ import { cardToCardSingle, getCards } from '../utils/cardUtil'
const fn: FileFunction = async (lang: SupportedLanguages) => {
const common = await getCards(lang)
return await Promise.all(common.map((card) => cardToCardSingle(card[0], card[1], lang)))
return await Promise.all(common.map((card) => cardToCardSingle(card[0], card[1], lang).catch((e) => {
console.log('error compiling card', `${card[1].set.id}-${card[0]}`)
throw e
})))
}
export default fn

View File

@ -1,8 +1,9 @@
import { getSets, setToSetSingle } from '../utils/setUtil'
import { SupportedLanguages } from '../../../interfaces'
import { Set } from '../../../meta/definitions/api'
import { FileFunction } from '../compilerInterfaces'
import { getCards } from '../utils/cardUtil'
import { getSeries } from '../utils/serieUtil'
import { getSets, setToSetSingle } from '../utils/setUtil'
interface Stats {
count: number
@ -14,10 +15,20 @@ interface Stats {
const fn: FileFunction = async (lang: SupportedLanguages) => {
const stats: Partial<Stats> = {}
stats.count = (await getCards(lang)).length
// temporary fix until a better solution is found
const referenceLang = ['ja', 'ko', 'zh-tw', 'id', 'th', 'zh-cn'].includes(lang) ? 'ja' : 'en'
const langSets = await Promise.all(await getSets(undefined, lang).then((sets) => sets.map(async (set) => await setToSetSingle(set, lang))))
const englishSets = await Promise.all(await getSets(undefined, 'en').then((sets) => sets.map(async (set) => await setToSetSingle(set, 'en'))))
stats.total = langSets.reduce((p, set) => p + (englishSets.find((s) => set.id === s.id)?.cardCount?.total ?? 0), 0)
const englishSets = await Promise.all(await getSets(undefined, referenceLang).then((sets) => sets.map(async (set) => await setToSetSingle(set, referenceLang))))
function max(lSet?: Set, refSet?: Set) {
if (!lSet) return refSet!.cardCount.total
if (!refSet) return lSet.cardCount.total
if (lSet.cardCount.total > refSet.cardCount.total) {
return lSet.cardCount.total
}
return refSet.cardCount.total
}
stats.total = langSets.reduce((p, set) => p + max(set, englishSets.find((s) => set.id === s.id)), 0)
stats.images = langSets.reduce((p1, set) => p1 + (set.cards.reduce((p2, card) => p2 + (card.image ? 1 : 0), 0)), 0)
stats.sets = {}