mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
tank search
This commit is contained in:
1 parent
5477616917
commit
4a0fccc526
6 files changed
+54
-73
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { BlitzKitAPI } from "@blitzkit/core";
|
||||
import { BlitzKitAPI } from "@blitzkit/core/src/blitzkit/api/base";
|
||||
import locales from "@blitzkit/i18n/locales.json";
|
||||
import { deburr } from "lodash-es";
|
||||
import { deburr, times } from "lodash-es";
|
||||
import { I18nString } from "../protos";
|
||||
|
||||
export async function fetchTankNames(api: BlitzKitAPI) {
|
||||
@@ -12,40 +12,53 @@ export async function fetchTankNames(api: BlitzKitAPI) {
|
||||
|
||||
return await Promise.all(
|
||||
tankDefinitionsArray.map(async (tank) => {
|
||||
const searchableNameDeburr: I18nString = { locales: {} };
|
||||
const name_deburr: I18nString = I18nString.create();
|
||||
const camouflages_deburr: I18nString[] = [];
|
||||
|
||||
const camouflages = tank.camouflages.map(
|
||||
(id) => camouflageDefinitions.camouflages[id].name!,
|
||||
);
|
||||
|
||||
Object.entries(tank.name!).forEach(([key, value]) => {
|
||||
searchableNameDeburr.locales[key] = deburr(value);
|
||||
name_deburr.locales[key] = deburr(value);
|
||||
});
|
||||
|
||||
camouflages.forEach((camouflage, index) => {
|
||||
camouflages_deburr[index] = I18nString.create();
|
||||
Object.entries(camouflage).forEach(([key, value]) => {
|
||||
camouflages_deburr[index].locales[key] = deburr(value);
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
id: tank.id,
|
||||
name: tank.name,
|
||||
searchableName: tank.name,
|
||||
searchableNameDeburr,
|
||||
camouflages: tank.camouflages
|
||||
?.map((id) =>
|
||||
locales.supported.map(
|
||||
({ locale }) =>
|
||||
camouflageDefinitions.camouflages[id]?.name!.locales[locale],
|
||||
),
|
||||
)
|
||||
.flat()
|
||||
.filter(Boolean)
|
||||
.map(deburr)
|
||||
.join(" "),
|
||||
treeType: tank.type,
|
||||
slug: tank.slug,
|
||||
dev_name: tank.dev_name,
|
||||
|
||||
name: tank.name!,
|
||||
name_deburr,
|
||||
|
||||
camouflages,
|
||||
camouflages_deburr,
|
||||
};
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export const SEARCH_KEYS = [
|
||||
"id",
|
||||
"slug",
|
||||
"dev_name",
|
||||
|
||||
...locales.supported
|
||||
.map(({ locale }) => [
|
||||
`searchableName.locales.${locale}`,
|
||||
`searchableNameDeburr.locales.${locale}`,
|
||||
`name.locales.${locale}`,
|
||||
`name_deburr.locales.${locale}`,
|
||||
|
||||
...times(8, (index) => [
|
||||
`camouflages.${index}.locales.${locale}`,
|
||||
`camouflages_deburr.${index}.locales.${locale}`,
|
||||
]),
|
||||
])
|
||||
.flat(),
|
||||
"camouflages",
|
||||
.flat(2),
|
||||
];
|
||||
Reference in new issue
Block a user