import { memo } from 'react'
import type { ControllerIconStyle } from '../input'
import type { Spell } from '../game'
import { ControllerBindingLabel } from './ControllerIcons'
import { barFillStyle } from './barStyles'
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,
focusable = true,
onCast,
emptyKeyPrefix = 'empty',
}: {
spell: SpellSlot
binding?: string
iconStyle: ControllerIconStyle
resourceName: string
disabled?: boolean
focusable?: 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',
focusable = true,
}: {
spells: SpellSlot[]
bindings: Record
iconStyle: ControllerIconStyle
resource: number
resourceName: string
canCast: boolean
onCast: (spell: Spell) => void
className?: string
focusable?: boolean
}) {
return (
{spells.map((spell, slotIndex) => {
if (!spell) {
return (
{slotIndex + 1}Empty
)
}
return (
0}
focusable={focusable}
iconStyle={iconStyle}
key={spell.id}
onCast={onCast}
resourceName={resourceName}
spell={spell}
/>
)
})}
)
})