Add support for weapon combobox abbreviations Closes #1217

This commit is contained in:
Kalle 2023-08-27 00:17:02 +03:00
parent 191de711c0
commit 4a28aca753
2 changed files with 50 additions and 6 deletions

View File

@ -28,6 +28,7 @@ import {
subWeaponImageUrl,
} from "~/utils/urls";
import { Image } from "./Image";
import { weaponAltNames } from "~/modules/in-game-lists/weapon-alt-names";
const MAX_RESULTS_SHOWN = 6;
@ -57,7 +58,7 @@ interface ComboboxProps<T> {
}
export function Combobox<
T extends Record<string, string | string[] | null | undefined | number>,
T extends Record<string, string | string[] | null | undefined | number>
>({
options,
inputName,
@ -197,11 +198,27 @@ export function WeaponCombobox({
}) {
const { t, i18n } = useTranslation("weapons");
const alt = (id: (typeof mainWeaponIds)[number]) => {
const result: string[] = [];
if (i18n.language !== "en") {
result.push(t(`MAIN_${id}`, { lng: "en" }));
}
const altNames = weaponAltNames.get(id);
if (typeof altNames === "string") {
result.push(altNames);
} else if (Array.isArray(altNames)) {
result.push(...altNames);
}
return result;
};
const idToWeapon = (id: (typeof mainWeaponIds)[number]) => ({
value: String(id),
label: t(`MAIN_${id}`),
imgPath: mainWeaponImageUrl(id),
alt: i18n.language !== "en" ? [t(`MAIN_${id}`, { lng: "en" })] : undefined,
alt: alt(id),
});
return (
@ -329,7 +346,7 @@ export function GearCombobox({
}
const mapPoolEventToOption = (
e: SerializedMapPoolEvent,
e: SerializedMapPoolEvent
): ComboboxOption<Pick<SerializedMapPoolEvent, "serializedMapPool">> => ({
serializedMapPool: e.serializedMapPool,
label: e.name,
@ -357,13 +374,13 @@ export function MapPoolEventsCombobox({
const options = React.useMemo(
() => (events ? events.map(mapPoolEventToOption) : []),
[events],
[events]
);
// this is important so that we don't trigger the reset to the initialEvent every time
const initialOption = React.useMemo(
() => initialEvent && mapPoolEventToOption(initialEvent),
[initialEvent],
[initialEvent]
);
if (isError) {
@ -384,7 +401,7 @@ export function MapPoolEventsCombobox({
id: parseInt(e.value, 10),
name: e.label,
serializedMapPool: e.serializedMapPool,
},
}
);
}}
className={className}

View File

@ -0,0 +1,27 @@
import type { MainWeaponId } from "./types";
export const weaponAltNames = new Map<MainWeaponId, string[] | string>()
.set(10, "vjr")
.set(11, "cjr")
.set(21, "nsplash")
.set(41, "ttek")
.set(81, "96d")
.set(91, ["cjs", "cjet"])
.set(1041, "swex")
.set(1120, "vincent")
.set(2070, "pencil")
.set(3000, "bucket")
.set(3001, "bucket")
.set(4001, "zimi")
.set(4030, "bp")
.set(5001, "napples")
.set(5030, "vds")
.set(5031, "cds")
.set(5040, "detras")
.set(5041, "letras")
.set(6010, "tent")
.set(6011, "tent")
.set(7010, "bow")
.set(8000, ["sword", "chainsaw"])
.set(8010, ["sword", "vwiper"])
.set(8011, ["sword", "diper", "dwiper"]);