mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-26 13:17:15 -05:00
Build by weapon loader refactoring
This commit is contained in:
@@ -2,16 +2,17 @@ import type { MainWeaponId } from "~/modules/in-game-lists/types";
|
||||
import weaponTranslations from "../../locales/en/weapons.json";
|
||||
import { mySlugify } from "./urls";
|
||||
|
||||
const SLUG_TO_WEAPON_ID = Object.fromEntries(
|
||||
Object.entries(weaponTranslations)
|
||||
.filter(([id]) => id.startsWith("MAIN"))
|
||||
.map(([id, name]) => [
|
||||
mySlugify(name),
|
||||
Number(id.replace("MAIN_", "")) as MainWeaponId,
|
||||
]),
|
||||
) as Record<string, MainWeaponId>;
|
||||
|
||||
export function weaponNameSlugToId(slug?: string) {
|
||||
if (!slug) return null;
|
||||
|
||||
for (const [id, name] of Object.entries(weaponTranslations)) {
|
||||
if (!id.startsWith("MAIN")) continue;
|
||||
|
||||
if (mySlugify(name) === slug.toLowerCase()) {
|
||||
return Number(id.replace("MAIN_", "")) as MainWeaponId;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return SLUG_TO_WEAPON_ID[slug.toLowerCase()] ?? null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user