fixed part role calls and some other stuff
This commit is contained in:
+25
-11
@@ -1,41 +1,55 @@
|
||||
import type { CategoryId } from "@/types/gunbuilder";
|
||||
|
||||
export const CATEGORY_TO_PART_ROLES: Record<CategoryId, string[]> = {
|
||||
/**
|
||||
* Maps canonical kebab-case CategoryIds to their associated part roles from the backend.
|
||||
*/
|
||||
export const CATEGORY_TO_PART_ROLES: Partial<Record<CategoryId, string[]>> = {
|
||||
// ===== UPPER =====
|
||||
upper: ["upper-receiver", "upper"],
|
||||
completeUpper: ["complete-upper"],
|
||||
"complete-upper": ["complete-upper"],
|
||||
barrel: ["barrel"],
|
||||
gasBlock: ["gas-block"],
|
||||
gasTube: ["gas-tube"],
|
||||
muzzleDevice: ["muzzle-device", "compensator", "brake"],
|
||||
"gas-block": ["gas-block"],
|
||||
"gas-tube": ["gas-tube"],
|
||||
"muzzle-device": ["muzzle-device", "compensator", "brake"],
|
||||
suppressor: ["suppressor"],
|
||||
handguard: ["handguard"],
|
||||
chargingHandle: ["charging-handle"],
|
||||
"charging-handle": ["charging-handle"],
|
||||
bcg: ["bcg", "bolt-carrier-group"],
|
||||
|
||||
// ===== LOWER =====
|
||||
lower: ["lower-receiver", "lower", "LOWER_RECEIVER_STRIPPED"],
|
||||
completeLower: ["complete-lower"],
|
||||
lowerParts: ["lower-parts-kit", "lower-parts"],
|
||||
"complete-lower": ["complete-lower"],
|
||||
"lower-parts": ["lower-parts-kit", "lower-parts"],
|
||||
trigger: ["trigger", "trigger-kit"],
|
||||
grip: ["pistol-grip", "grip"],
|
||||
safety: ["safety", "safety-selector"],
|
||||
buffer: ["buffer-kit", "buffer"],
|
||||
stock: ["stock"],
|
||||
|
||||
// ===== OPTICS =====
|
||||
sights: ["sight", "sights", "iron-sights"],
|
||||
optic: ["optic", "optics"],
|
||||
|
||||
// ===== ACCESSORIES =====
|
||||
magazine: ["magazine", "mag", "magazine-ar15", "magazine-308", "drum-magazine"],
|
||||
weaponLight: ["weapon-light", "light", "weapon-light-laser", "light-laser-combo", "laser"],
|
||||
"weapon-light": ["weapon-light", "light", "weapon-light-laser", "light-laser-combo", "laser"],
|
||||
foregrip: ["vertical-grip", "angled-foregrip", "foregrip", "handstop"],
|
||||
bipod: ["bipod"],
|
||||
sling: ["sling", "sling-mount", "sling-swivel", "qd-sling-mount"],
|
||||
railAccessory: ["rail-section", "picatinny-rail-section", "m-lok-rail-section", "keymod-rail-section", "rail-cover", "rail-panel"],
|
||||
"rail-accessory": ["rail-section", "picatinny-rail-section", "m-lok-rail-section", "keymod-rail-section", "rail-cover", "rail-panel"],
|
||||
tools: ["tool", "armorer-tool", "armorer-wrench", "cleaning-kit", "bore-snake", "vise-block", "torque-wrench"],
|
||||
};
|
||||
|
||||
export const PART_ROLE_TO_CATEGORY: Record<string, CategoryId> = Object.entries(
|
||||
CATEGORY_TO_PART_ROLES
|
||||
).reduce((acc, [categoryId, roles]) => {
|
||||
for (const role of roles) acc[role] = categoryId as CategoryId;
|
||||
for (const role of roles) {
|
||||
// store the original string
|
||||
acc[role] = categoryId as CategoryId;
|
||||
|
||||
// also store a normalized version (handles ENUM_CASE and snake_case)
|
||||
const normalized = role.trim().toLowerCase().replace(/_/g, "-");
|
||||
acc[normalized] = categoryId as CategoryId;
|
||||
}
|
||||
return acc;
|
||||
}, {} as Record<string, CategoryId>);
|
||||
Reference in New Issue
Block a user