import { memo } from 'react' import type { ControllerIconStyle } from '../input' import type { Spell } from '../game' import { ControllerBindingLabel } from './ControllerIcons' export type SpellSlot = (Spell & { cost: number remaining: number slotIndex: number }) | null export const ResourceBar = memo(function ResourceBar({ resource, maxResource, resourceName, speedMultiplier, unavailableText, }: { resource: number maxResource: number resourceName: string speedMultiplier?: 1 | 2 unavailableText?: string }) { return (
{unavailableText ?? `${resourceName} ${Math.floor(resource)} / ${maxResource}`} {speedMultiplier === 2 && 2x speed}
) }) export const SpellButton = memo(function SpellButton({ spell, binding, iconStyle, resourceName, disabled, onCast, emptyKeyPrefix = 'empty', }: { spell: SpellSlot binding?: string iconStyle: ControllerIconStyle resourceName: string disabled?: boolean onCast: (spell: Spell) => void emptyKeyPrefix?: string }) { if (!spell) { return (
{emptyKeyPrefix}Empty
) } return ( ) }) export const SpellBar = memo(function SpellBar({ spells, bindings, iconStyle, resource, resourceName, canCast, onCast, className = 'spell-bar six-slots vertical-spell-bar', }: { spells: SpellSlot[] bindings: Record iconStyle: ControllerIconStyle resource: number resourceName: string canCast: boolean onCast: (spell: Spell) => void className?: string }) { return (
{spells.map((spell, slotIndex) => { if (!spell) { return (
{slotIndex + 1}Empty
) } return ( 0} iconStyle={iconStyle} key={spell.id} onCast={onCast} resourceName={resourceName} spell={spell} /> ) })}
) })