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

Initial Database

Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
2020-02-19 16:19:09 +01:00
commit be94e712b8
12302 changed files with 1142705 additions and 0 deletions

31
interfaces/Ability.ts Normal file
View File

@ -0,0 +1,31 @@
import AbilityType from "./AbilityType";
import LangList from "./LangList";
import { promises } from "fs";
interface Ability {
id?: number
type: AbilityType
name: LangList<string>
text: LangList<string>
}
const file = "./generated/abilities.json"
let abilities: Array<string> = []
namespace Ability {
export async function fetch(): Promise<void> {
const els = await promises.readFile(file)
abilities = JSON.parse(els.toString())
}
export function process(str: string): number | undefined {
return abilities.indexOf(str)
}
export async function save(): Promise<void> {
return promises.writeFile(file, JSON.stringify(abilities))
}
}
export default Ability

59
interfaces/AbilityType.ts Normal file
View File

@ -0,0 +1,59 @@
enum AbilityType {
POKEBODY,
POKEPOWER,
TALENT,
ANCIENTTRAIT
}
const en = [
"Poké-Body",
"Poké-Power",
"Ability",
"Ancient Trait"
]
const fr = [
"Poké-Body",
"Poké-Power",
"Talent",
"Trait Ancien"
]
namespace AbilityType {
export function toLang(a: AbilityType, lang: string): string {
switch (lang) {
case "en":
return en[a]
case "fr":
return fr[a]
}
throw new Error(`Error , abilityType not translated! (${lang})`)
}
export function getFromText(txt: string): AbilityType {
switch (txt) {
case "Ability":
case "Talent":
return AbilityType.TALENT
case "Poké-Body":
case "Pok<6F><6B>-Body":
return AbilityType.POKEBODY
case "Poké-Power":
case "Pokémon Power":
case "Pok<6F><6B>-Power":
return AbilityType.POKEPOWER
case "Ancient Trait":
case "Trait Antique":
return AbilityType.ANCIENTTRAIT
default:
throw new Error(`Ability Type (${txt}) not found!`)
}
}
}
export default AbilityType

18
interfaces/Attack.ts Normal file
View File

@ -0,0 +1,18 @@
import LangList from "./LangList";
import Type from "./Type";
interface Attack {
cost?: Array<Type>
name: LangList<string>
text?: LangList<string>
damage?: string|number
}
export interface LocalizedAttack {
cost?: Array<Type|string>
name: string|LangList<string>
text?: string|LangList<string>
damage?: string|number
}
export default Attack

65
interfaces/Card.ts Normal file
View File

@ -0,0 +1,65 @@
import Type from "./Type";
import Category from "./Category";
import Tag from "./Tag";
import LangList from "./LangList";
import Rarity from "./Rarity";
import Attack from "./Attack";
import Illustrator from "./Illutrator";
import Ability from "./Ability";
import Set from "./Set";
interface Card {
// global id made of setid and localId
id: string
// set id
localId: string|number
dexId?: number
// Card informations (from top to bottom of card)
name: LangList<string>
hp?: number //optionnal because energy/trainer cards might have not any hp
type?: Array<Type> // ex for multiple https://api.pokemon.com/us/pokemon-tcg/pokemon-cards/ex-series/ex13/17/
image?: {
low: LangList<string>
high?: LangList<string>
}
evolveFrom?: LangList<string>
evolveTo?: Array<LangList<string>>
tags: Array<Tag> // made after
illustrator?: Illustrator
abilities?: Array<Ability>
attacks?: Array<Attack>
// If card is trainer or energy effect is here
effect?: LangList<string>
weaknesses?: Array<{
type: Type
value?: string
}>
resistances?: Array<{
type: Type
value?: string
}>
retreat?: number
rarity: Rarity
// Other elements
category: Category
set: {
name: string
code: string
}| Set
}
export default Card

38
interfaces/Category.ts Normal file
View File

@ -0,0 +1,38 @@
enum Category {
POKEMON,
TRAINER,
ENERGY
}
const en = [
"Pokémon",
"Trainer",
"Energy"
]
const fr = [
"Pokémon",
"Dresseur",
"Énergie"
]
namespace Category {
export function fromEnglish(str: string) {
let i = en.indexOf(str)
if (str === "Pok<6F><6B>mon") i = 1
if (i < 0) throw new Error(`Cannot get the category (${str})`)
return i
}
export function toLang(i: Category, lang: string): string {
switch (lang) {
case "en":
return en[i]
case "fr":
return fr[i]
}
throw new Error(`Error, Language not implemented! (${lang})`)
}
}
export default Category

7
interfaces/Expansion.ts Normal file
View File

@ -0,0 +1,7 @@
import LangList from "./LangList";
export default interface Expansion {
name: LangList<string> | string
code: string
sets?: Array<string>
}

6
interfaces/Illutrator.ts Normal file
View File

@ -0,0 +1,6 @@
interface Illustrator {
id: number
name: string
}
export default Illustrator

18
interfaces/LangList.ts Normal file
View File

@ -0,0 +1,18 @@
type LangList<T> = {
fr?: T
en?: T
es?: T
it?: T
}
export type Langs = "en" | "fr" | "es" | "it"
namespace LangList {
export function insert(from: LangList<any>, el: any, lang: Langs) {
if (typeof from !== "object") from = {}
from[lang] = el
return from
}
}
export default LangList

139
interfaces/Rarity.ts Normal file
View File

@ -0,0 +1,139 @@
enum Rarity {
Common,
Uncommon,
Rare,
// Rare holo
RareHolo,
RareHoloEX,
RareHoloGX,
RareHoloLvX,
// Rare other
RareUltra,
RarePrime,
RareACE,
RareBREAK,
RareRainbow,
// Other
LEGEND,
// V & Vmax
RareV,
RareVMAX,
}
const en = [
"Common",
"unCommon",
"Rare",
"Rare Holo",
"Rare Holo EX",
"Rare Holo GX",
"Rare Holo Lv.X",
"Rare Ultra",
"Rare Prime",
"Rare ACE",
"Rare BREAK",
"Rainbow Rare",
"LEGEND",
"V",
"VMax"
]
const fr = [
"Commun",
"Non Commun",
"Rare",
"Rare Holo",
"Rare Holo EX",
"Rare Holo GX",
"Rare Holo Lv.X",
"Rare Ultra",
"Rare Prime",
"Rare ACE",
"Rare BREAK",
"Rainbow Rare",
"LEGEND",
"V",
"VMax"
]
namespace Rarity {
export function toLang(r: Rarity, lang: string): string {
switch (lang) {
case "en":
return en[r]
case "fr":
return fr[r]
}
throw new Error(`Error, rarity lang not found! (${lang})`)
}
export function getLocalRarity(str?: string): Rarity {
switch (str) {
// Handle common Rarity errors
case undefined:
case "":
console.warn(`Rarity is (${str}) returning Common`)
case "Common":
return Rarity.Common
case "Uncommon":
return Rarity.Uncommon
// Rare
case "Rare":
case "Rare Secret":
case "Rare Promo":
case "Shining":
return Rarity.Rare
// Rare Holo
case "Rare Holo":
return Rarity.RareHolo
case "Rare Holo EX":
return Rarity.RareHoloEX
case "Rare Holo GX":
return Rarity.RareHoloGX
case "Rare Holo Lv.X":
return Rarity.RareHoloLvX
// Rare Other
case "Rare Ultra":
return Rarity.RareUltra
case "Rare Prime":
return Rarity.RarePrime
case "Rare ACE":
return Rarity.RareACE
case "Rare BREAK":
return Rarity.RareBREAK
case "Rainbow Rare":
case "Rare Rainbow":
return Rarity.RareRainbow
// LEGEND
case "LEGEND":
return Rarity.LEGEND
case "V":
return Rarity.RareV
case "VM":
return Rarity.RareVMAX
default:
throw new Error(`Rarity not known (${str})`)
}
}
}
export default Rarity

45
interfaces/Set.ts Normal file
View File

@ -0,0 +1,45 @@
import LangList from "./LangList";
import Expansion from "./Expansion";
export default interface Set {
// Display Name
name: LangList<string> | string
expansion?: Expansion
expansionCode?: string
code: string
tcgoCode?: string
cardCount?: {
// total containing all secrets
total: number
// official count on cards
official: number
}
format?: string
releaseDate?: string // date in format yyyy-mm-dd
// api endpoint for scrapping
api?: string
legal?: {
standard: boolean
expanded: boolean
}
images?: {
// thingy on bottom of cards
symbol?: string
// Official logo of set
logo?: string
}
//temp
slug?: string
subsets?: Array<Set>
}

247
interfaces/Tag.ts Normal file
View File

@ -0,0 +1,247 @@
enum Tag {
BASIC,
BASICENERGY,
BREAK,
EX,
GX,
ITEM,
LEGEND,
LEVELUP,
MEGA,
RESTORED,
ROCKETSECRETMACHINE,
SP, // not in switch case
SPECIAL,
STADIUM,
STAGE1,
STAGE2,
SUPPORTER,
TAGTEAM,
TECHNICALMACHINE,
TOOL,
V,
VMAX,
}
const en = [
"Basic Pokémon",
"Basic Energy",
"BREAK",
"EX",
"GX",
"Item",
"LEGEND",
"Level-Up",
"MEGA",
"Restored",
"Rocket's Secret Machine",
"SP",
"Special",
"Stadium",
"Stage 1",
"Stage 2",
"Supporter",
"Tag Team",
"Technical Machine",
"Tool",
"Pokémon V",
"Pokémon VMAX"
]
const fr = [
"Pokémon de base",
"Energie de base",
"TURBO",
"EX",
"GX",
"Objet",
"LÉGENDE",
"Niveau Sup",
"Méga",
"Restauré",
"Machine secrète dees Rocket",
"SP",
"Spéciale",
"Stadium",
"Niveau 1",
"Niveau 2",
"Supporter",
"ESCOUADE",
"Machine Technique",
"Outil",
"Pokémon V",
"Pokémon VMAX"
]
namespace Tag {
export function toLang(i: Tag, lang: string) {
switch (lang) {
case "en":
return en[i]
case "fr":
return fr[i]
default:
break;
}
}
export function lookup(str: string): Array<Tag> {
const list: Array<Tag> = []
switch (str) {
// BASIC
case "Basic Pokémon":
case "Basic":
case "Pokémon de base":
list.push(Tag.BASIC)
break
case "Basic Energy":
case "Énergie de base":
list.push(Tag.BASICENERGY)
break
// BREAK
case "BREAK":
case "TURBO":
list.push(Tag.BREAK)
break
// EX
case "Pokémon-EX":
case "EX":
case "EX Pokémon":
list.push(Tag.EX)
break
// GX
case "Pokémon-GX":
case "GX":
list.push(Tag.GX)
break
// Item
case "Trainer - Item":
case "Item":
case "Dresseur - Object":
list.push(Tag.ITEM)
break
// LEGEND
case "Pokémon LEGEND":
case "LEGEND":
case "Pokémon Légende":
list.push(Tag.LEGEND)
break
// Level-Up
case "Level-Up Pokémon":
case "Level Up":
case "Niveau Sup. Pokémon":
list.push(Tag.LEVELUP)
break
// MEGA
case "MEGA":
case "Méga-":
list.push(Tag.MEGA)
break
// Restored
case "Restored Pokémon":
case "Restored":
list.push(Tag.RESTORED)
break
// Rocket's Secret Machine
case "Trainer [Rocket's Secret Machine]":
case "Rocket's Secret Machine":
list.push(Tag.ROCKETSECRETMACHINE)
break
case "Special Energy":
case "Special":
case "Énergie spéciale":
list.push(Tag.SPECIAL)
break
case "Trainer - Stadium":
case "Trainer [Stadium]":
case "Stadium":
case "Dresseur - Stade":
list.push(Tag.STADIUM)
break
// Stage 1
case "Stage 1 Pokémon":
case "Stage 1":
case "Pokémon Niveau 1":
list.push(Tag.STAGE1)
break
// Stage 2
case "Stage 2 Pokémon":
case "Stage 2":
case "Pokémon Niveau 2":
list.push(Tag.STAGE2)
break
// Supporter
case "Trainer - Supporter":
case "Trainer [Supporter]":
case "Supporter":
case "Dresseur - Supporter":
list.push(Tag.SUPPORTER)
break
// TAG TEAM
case "Pokémon-TAG TEAM":
case "TAG TEAM":
case "Pokémon-ESCOUADE":
list.push(Tag.TAGTEAM)
break
case "Trainer [Technical Machine]":
case "Technical Machine":
case "Machine Technique":
list.push(Tag.TECHNICALMACHINE)
break
case "Trainer [Pokémon Tool]":
case "Pokémon Tool":
case "Pok<6F><6B>mon Tool":
case "Dresseur [Outil Pokémon]":
list.push(Tag.TOOL)
break
case "Pokémon-V":
list.push(Tag.V)
break
case "Pokémon-VMAX":
list.push(Tag.VMAX)
case "null":
break
default:
throw new Error(`Tag is not corresponding to anything (${str})`);
}
return list
}
}
export default Tag

146
interfaces/Type.ts Normal file
View File

@ -0,0 +1,146 @@
enum Type {
COLORLESS,
DARKNESS,
DRAGON,
FAIRY,
FIGHTING,
FIRE,
GRASS,
LIGHTNING,
METAL,
PSYCHIC,
WATER,
}
const en = [
"Colorless",
"Darkness",
"Dragon",
"Fairy",
"Fighting",
"Fire",
"Grass",
"Lightning",
"Metal",
"Psychic",
"Water"
]
const fr = [
"Incolore",
"Obscurité",
"Dragon",
"Fée",
"Combat",
"Feu",
"Plante",
"Électrique",
"Métal",
"Psy",
"Eau"
]
namespace Type {
export function toLang(type: Type, lang: string): string {
switch (lang) {
case "fr":
return fr[type]
break;
case "en":
return en[type]
default:
break;
}
return fr[type]
}
export function getFromClass(classe: string): Type {
switch (classe) {
case "icon-grass":
return Type.GRASS
case "icon-fire":
return Type.FIRE
case "icon-water":
return Type.WATER
case "icon-lightning":
return Type.LIGHTNING
case "icon-psychic":
return Type.PSYCHIC
case "icon-fighting":
return Type.FIGHTING
case "icon-darkness":
case "icon-dark":
return Type.DARKNESS
case "icon-metal":
return Type.METAL
case "icon-colorless":
return Type.COLORLESS
case "icon-fairy":
return Type.FAIRY
case "icon-dragon":
return Type.DRAGON
}
throw new Error(`Error, type (${classe}) not found !`)
}
export function getFromFrench(fr: string): Type|undefined {
switch (fr.toLowerCase()) {
case "plante":
return Type.GRASS
case "feux":
return Type.FIRE
case "eau":
return Type.WATER
case "electrique":
return Type.LIGHTNING
case "psy":
return Type.PSYCHIC
case "combat":
return Type.FIGHTING
case "obscurité":
return Type.DARKNESS
case "métal":
return Type.METAL
case "sanscouleur": // ???
return Type.COLORLESS
case "fée":
return Type.FAIRY
case "dragon":
return Type.DRAGON
}
throw new Error(`Error, type (${fr}) not found !`)
}
export function getFromSpanish(fr: string): Type {
switch (fr.toLowerCase()) {
case "planta":
return Type.GRASS
case "fuego":
return Type.FIRE
case "agua":
return Type.WATER
case "rayo":
return Type.LIGHTNING
case "psíquica":
return Type.PSYCHIC
case "lucha":
return Type.FIGHTING
case "oscura":
return Type.DARKNESS
case "metálica":
return Type.METAL
case "colorless": // ???
return Type.COLORLESS
case "hada":
return Type.FAIRY
case "dragón":
return Type.DRAGON
}
throw new Error(`Error, type (${fr}) not found !`)
}
export function getFromEnglish(en: string): Type {
return Type.getFromClass(`icon-${en.toLowerCase()}`)
}
}
export default Type