|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { useMemo } from "react"; |
| 4 | +import { useMapStore } from "@/lib/store"; |
| 5 | +import { |
| 6 | + CHARACTERS, |
| 7 | + CHARACTER_REALMS, |
| 8 | + getCharacterPath, |
| 9 | +} from "@/lib/characters"; |
| 10 | +import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"; |
| 11 | +import { cn } from "@/lib/utils"; |
| 12 | +import { |
| 13 | + Tooltip, |
| 14 | + TooltipContent, |
| 15 | + TooltipProvider, |
| 16 | + TooltipTrigger, |
| 17 | +} from "@/components/ui/tooltip"; |
| 18 | +import { MIXED_TEXTURE_PLACE_ID, TEXTURE_PLACES } from "@/lib/textures"; |
| 19 | + |
| 20 | +export default function CharacterPicker() { |
| 21 | + const { activeCharacterTool, setActiveCharacterTool, location } = useMapStore(); |
| 22 | + const locationLabel = |
| 23 | + location === MIXED_TEXTURE_PLACE_ID |
| 24 | + ? "Mixed" |
| 25 | + : (TEXTURE_PLACES.find((place) => place.id === location)?.label ?? "Shire"); |
| 26 | + |
| 27 | + const groupedCharacters = useMemo( |
| 28 | + () => |
| 29 | + CHARACTER_REALMS.map((realm) => ({ |
| 30 | + ...realm, |
| 31 | + characters: CHARACTERS.filter((character) => character.realm === realm.id), |
| 32 | + })).filter((realm) => realm.characters.length > 0), |
| 33 | + [], |
| 34 | + ); |
| 35 | + |
| 36 | + return ( |
| 37 | + <ScrollArea className="h-full w-full bg-background/80"> |
| 38 | + <div className="flex flex-col gap-2 p-2 sm:p-3"> |
| 39 | + <span className="px-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground whitespace-nowrap"> |
| 40 | + {locationLabel} |
| 41 | + </span> |
| 42 | + <div className="flex gap-3 sm:gap-4"> |
| 43 | + <TooltipProvider delayDuration={200}> |
| 44 | + {groupedCharacters.map((realm) => ( |
| 45 | + <div key={realm.id} className="flex flex-col gap-1"> |
| 46 | + <span className="px-1 text-[11px] font-semibold text-muted-foreground whitespace-nowrap sm:text-xs"> |
| 47 | + {realm.label} |
| 48 | + </span> |
| 49 | + <div className="flex gap-1"> |
| 50 | + {realm.characters.map((character) => { |
| 51 | + const isActive = activeCharacterTool === character.id; |
| 52 | + return ( |
| 53 | + <Tooltip key={character.id}> |
| 54 | + <TooltipTrigger asChild> |
| 55 | + <button |
| 56 | + className={cn( |
| 57 | + "block h-[96px] w-[54px] shrink-0 overflow-hidden rounded-md border-2 transition-colors sm:h-[115px] sm:w-[65px]", |
| 58 | + isActive |
| 59 | + ? "border-primary ring-2 ring-primary/30" |
| 60 | + : "border-transparent hover:border-muted-foreground/30", |
| 61 | + )} |
| 62 | + style={{ |
| 63 | + backgroundImage: `url('${getCharacterPath(character.id)}')`, |
| 64 | + backgroundRepeat: "no-repeat", |
| 65 | + backgroundPosition: "center", |
| 66 | + backgroundSize: "cover", |
| 67 | + }} |
| 68 | + onClick={() => setActiveCharacterTool(character.id)} |
| 69 | + /> |
| 70 | + </TooltipTrigger> |
| 71 | + <TooltipContent side="top"> |
| 72 | + <p>{character.label}</p> |
| 73 | + </TooltipContent> |
| 74 | + </Tooltip> |
| 75 | + ); |
| 76 | + })} |
| 77 | + </div> |
| 78 | + </div> |
| 79 | + ))} |
| 80 | + </TooltipProvider> |
| 81 | + </div> |
| 82 | + </div> |
| 83 | + <ScrollBar orientation="horizontal" /> |
| 84 | + </ScrollArea> |
| 85 | + ); |
| 86 | +} |
0 commit comments