Files
blitzkit/packages/website/src/components/ConsumablesManager.tsx
T

71 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-10-05 20:55:44 -05:00
import type { Consumable } from '@blitzkit/core';
2024-09-17 22:13:35 -05:00
import { Flex, type FlexProps } from '@radix-ui/themes';
2024-04-06 19:37:57 -05:00
import { ConsumableButton } from './ModuleButtons/ConsumableButton';
2024-08-21 19:45:33 -05:00
type ConsumablesManagerProps = FlexProps & {
2024-10-05 20:55:44 -05:00
consumables: Consumable[];
2024-04-06 19:37:57 -05:00
selected: number[];
2024-08-21 19:45:33 -05:00
onConsumablesChange?: (consumables: number[]) => void;
2024-04-06 19:37:57 -05:00
disabled?: boolean;
timers?: boolean;
hasHighEndConsumables?: boolean;
hasConsumableDeliverySystem?: boolean;
cooldownBooster?: number;
2024-08-21 19:45:33 -05:00
};
2024-04-06 19:37:57 -05:00
export function ConsumablesManager({
consumables,
selected,
2024-08-21 19:45:33 -05:00
onConsumablesChange,
2024-04-06 19:37:57 -05:00
disabled,
timers,
hasConsumableDeliverySystem,
cooldownBooster,
hasHighEndConsumables,
2024-08-21 19:45:33 -05:00
...props
2024-04-06 19:37:57 -05:00
}: ConsumablesManagerProps) {
return (
2024-08-21 19:45:33 -05:00
<Flex wrap="wrap" gap="2" {...props}>
2024-08-28 21:16:25 -05:00
{consumables.map((consumable) => {
2024-04-06 19:37:57 -05:00
const isSelected = selected.some((id) => id === consumable.id);
return (
<ConsumableButton
special={consumable.duration === undefined}
duration={
timers
? consumable.duration === undefined
? undefined
2024-04-20 11:45:41 -05:00
: consumable.duration * (hasHighEndConsumables ? 1.7 : 1)
2024-04-06 19:37:57 -05:00
: undefined
}
cooldown={
timers
? consumable.cooldown *
2024-05-22 13:04:39 -05:00
(hasConsumableDeliverySystem ? 0.88 : 1) *
2024-04-06 19:37:57 -05:00
(1 - cooldownBooster! * 0.1)
: undefined
}
key={consumable.id}
disabled={disabled && !isSelected}
consumable={consumable.id}
selected={isSelected}
onClick={() => {
2024-08-21 19:45:33 -05:00
if (!onConsumablesChange) return;
2024-04-06 19:37:57 -05:00
const draft = [...selected];
if (draft.some((id) => id === consumable.id)) {
draft.splice(draft.indexOf(consumable.id), 1);
} else {
draft.push(consumable.id);
}
2024-08-21 19:45:33 -05:00
onConsumablesChange(draft);
2024-04-06 19:37:57 -05:00
}}
/>
);
})}
</Flex>
);
}