mirror of
https://github.com/tcgdex/compiler.git
synced 2025-07-29 07:29:50 +00:00
Added Support for legal file (#13)
* Added Support for legal file Signed-off-by: Avior <florian.bouillon@delta-wings.net> * Fixed bug Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import { setToSetSimple } from "./setUtil"
|
||||
import { fetchRemoteFile, smartGlob } from "./util"
|
||||
import { cardIsLegal, fetchRemoteFile, smartGlob } from "./util"
|
||||
import { Set, SupportedLanguages, Card, Types } from 'db/interfaces'
|
||||
import { Card as CardSingle, CardResume } from '@tcgdex/sdk/interfaces'
|
||||
import translate from './translationUtil'
|
||||
@ -81,7 +81,7 @@ export async function cardToCardSingle(localId: string, card: Card, lang: Suppor
|
||||
})),
|
||||
|
||||
attacks: card.attacks?.map((el) => ({
|
||||
cost: el.cost?.map((t) => translate('types', t, lang)),
|
||||
cost: el.cost?.map((t) => translate('types', t, lang)) as Array<Types>,
|
||||
name: el.name[lang] as string,
|
||||
effect: el.effect ? el.effect[lang] : undefined,
|
||||
damage: el.damage
|
||||
@ -105,6 +105,11 @@ export async function cardToCardSingle(localId: string, card: Card, lang: Suppor
|
||||
energyType: translate('energyType', card.energyType, lang) as any,
|
||||
regulationMark: card.regulationMark,
|
||||
|
||||
legal: {
|
||||
standard: cardIsLegal('standard', card, localId),
|
||||
expanded: cardIsLegal('expanded', card, localId)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Set, SupportedLanguages } from "db/interfaces"
|
||||
import { fetchRemoteFile, smartGlob } from "./util"
|
||||
import { fetchRemoteFile, setIsLegal, smartGlob } from "./util"
|
||||
import { cardToCardSimple, getCards } from './cardUtil'
|
||||
import { SetResume, Set as SetSingle } from '@tcgdex/sdk/interfaces'
|
||||
|
||||
@ -99,9 +99,9 @@ export async function setToSetSingle(set: Set, lang: SupportedLanguages): Promis
|
||||
firstEd: cards.reduce((count, card) => count + (card[1].variants?.firstEdition ?? set.variants?.firstEdition ? 1 : 0), 0),
|
||||
},
|
||||
releaseDate: set.releaseDate,
|
||||
legal: set.legal && {
|
||||
standard: set.legal.standard,
|
||||
expanded: set.legal.expanded
|
||||
legal: {
|
||||
standard: setIsLegal('standard', set),
|
||||
expanded: setIsLegal('expanded', set)
|
||||
},
|
||||
logo: pics[0],
|
||||
symbol: pics[1],
|
||||
|
@ -73,10 +73,9 @@ const translations: Record<string, Record<translatable, Record<string, string>>>
|
||||
}
|
||||
}
|
||||
|
||||
export default function translate(item: translatable, key: string | undefined, lang: SupportedLanguages): string {
|
||||
export default function translate(item: translatable, key: string | undefined, lang: SupportedLanguages): string | undefined {
|
||||
if (!key) {
|
||||
throw new Error(`No Key ${lang}${item}.${key}`);
|
||||
return ''
|
||||
return key
|
||||
}
|
||||
if (lang === 'en') {
|
||||
return key
|
||||
|
@ -1,5 +1,7 @@
|
||||
import { Card, Set } from 'db/interfaces'
|
||||
import glob from 'glob'
|
||||
import fetch from 'node-fetch'
|
||||
import * as legals from '../db/legals'
|
||||
|
||||
export function urlize(str: string): string {
|
||||
return str.replace('?', '%3F').normalize('NFC').replace(/["'\u0300-\u036f]/g, "")
|
||||
@ -29,3 +31,29 @@ export async function smartGlob(query: string) {
|
||||
}
|
||||
return globCache[query]
|
||||
}
|
||||
|
||||
export function cardIsLegal(type: 'standard' | 'expanded', card: Card, localId: string) {
|
||||
const legal = legals[type]
|
||||
if (
|
||||
legal.includes.series.includes(card.set.serie.id) ||
|
||||
legal.includes.sets.includes(card.set.id) ||
|
||||
(card.regulationMark && legal.includes.regulationMark.includes(card.regulationMark))
|
||||
) {
|
||||
return !(
|
||||
legal.excludes.sets.includes(card.set.id) ||
|
||||
legal.excludes.cards.includes(`${card.set.id}-${localId}`)
|
||||
)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
export function setIsLegal(type: 'standard' | 'expanded', set: Set) {
|
||||
const legal = legals[type]
|
||||
if (
|
||||
legal.includes.series.includes(set.serie.id) ||
|
||||
legal.includes.sets.includes(set.id)
|
||||
) {
|
||||
return !legal.excludes.sets.includes(set.id)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Reference in New Issue
Block a user