Skip to content

Commit

Permalink
add skill api
Browse files Browse the repository at this point in the history
  • Loading branch information
guyutongxue committed Feb 10, 2024
1 parent be970b2 commit 593b022
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
37 changes: 27 additions & 10 deletions src/common/data.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check
/// <reference types="@genshin-db/tcg" />
import rawData from "@genshin-db/tcg/src/min/data.min.json" with { type: "json" };

/**
Expand All @@ -9,13 +11,13 @@ import rawData from "@genshin-db/tcg/src/min/data.min.json" with { type: "json"
* [key: string]: unknown;
* }} AnyData
*
* @typedef {"tcgcharactercards" | "tcgactioncards" | "tcgsummons" | "tcgstatuseffects"} TypeKey
* @typedef {"tcgcharactercards" | "tcgactioncards" | "tcgsummons" | "tcgstatuseffects" | "tcgkeywords" | "tcgskills"} TypeKey
*
* @typedef {{
* data: {
* [lang in Language]: Record<TypeKey, Record<string, AnyData>;
* [lang in Language]: Record<TypeKey, Record<string, AnyData>>
* },
* image: Record<Omit<TypeKey, "tcgstatuseffects">, object>;
* image: Record<TypeKey, Record<string, unknown> | undefined>;
* }} RawData
*
* @typedef {AnyData & {
Expand All @@ -36,17 +38,32 @@ const keys = [
];

/** @type {Record<Language, TransformedData[]>} */
// @ts-expect-error
const transformedData = Object.fromEntries(
Object.entries(data).map(([lang, langData]) => [
Object.entries(data).map(([lang, langData]) => ([
lang,
keys.flatMap((key) =>
Object.entries(langData[key]).map(([name, obj]) => ({
...obj,
TYPE: key,
image: image?.[key]?.[name] ?? null
})),
Object.entries(langData[key]).flatMap(([name, obj]) => {
const thisObj = {
...obj,
TYPE: key,
image: image?.[key]?.[name] ?? null
};
if (key === "tcgcharactercards" && "skills" in obj && Array.isArray(obj.skills)) {
return [
thisObj,
...obj.skills.map((skill) => ({
...skill,
TYPE: "tcgskills",
image: image?.tcgskills?.[skill.name] ?? null
})),
];
} else {
return [thisObj];
}
}),
),
]),
])),
);

export default transformedData;
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"module": "ESNext",
"moduleResolution": "Bundler",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"module": "ESNext",
"moduleResolution": "Bundler",
},
"include": ["vite.config.ts", "src/node/**/*.ts"]
"include": ["vite.config.ts", "src/node/**/*.ts", "api/**/*.js"]
}

0 comments on commit 593b022

Please sign in to comment.