2026-09-27 17:19:39 -05:00
|
|
|
import type { EquipmentPreset } from "@blitzkit/protos";
|
|
|
|
|
import { Flex } from "@radix-ui/themes";
|
|
|
|
|
import { chunk, cloneDeep } from "lodash-es";
|
|
|
|
|
import type { EquipmentMatrix } from "../../stores/duel";
|
|
|
|
|
import { EquipmentButton } from "../ModuleButtons/EquipmentButton";
|
|
|
|
|
import "./index.css";
|
2024-04-06 10:06:59 -05:00
|
|
|
|
|
|
|
|
interface EquipmentManagerProps {
|
|
|
|
|
preset: EquipmentPreset;
|
|
|
|
|
matrix: EquipmentMatrix;
|
|
|
|
|
onChange: (matrix: EquipmentMatrix) => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function EquipmentManager({
|
|
|
|
|
preset,
|
|
|
|
|
matrix,
|
|
|
|
|
onChange,
|
|
|
|
|
}: EquipmentManagerProps) {
|
|
|
|
|
return (
|
2024-11-02 18:52:50 -05:00
|
|
|
<Flex direction="column" gap="2" className="equipment-manager">
|
2024-10-05 16:44:07 -05:00
|
|
|
{chunk(preset.slots, 3).map((equipmentRow, rowIndex) => (
|
2024-04-06 10:06:59 -05:00
|
|
|
<Flex gap="2" key={rowIndex}>
|
|
|
|
|
{equipmentRow.map((equipment, columnIndex) => (
|
|
|
|
|
<Flex key={columnIndex}>
|
|
|
|
|
<EquipmentButton
|
2024-11-02 18:52:50 -05:00
|
|
|
className="left"
|
2024-10-05 16:44:07 -05:00
|
|
|
equipment={equipment.left}
|
2024-04-06 10:06:59 -05:00
|
|
|
selected={matrix[rowIndex][columnIndex] === -1}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
const draft = cloneDeep(matrix);
|
|
|
|
|
|
|
|
|
|
if (draft[rowIndex][columnIndex] === -1) {
|
|
|
|
|
draft[rowIndex][columnIndex] = 0;
|
|
|
|
|
} else {
|
|
|
|
|
draft[rowIndex][columnIndex] = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onChange(draft);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<EquipmentButton
|
2024-11-02 18:52:50 -05:00
|
|
|
className="right"
|
2024-10-05 16:44:07 -05:00
|
|
|
equipment={equipment.right}
|
2024-04-06 10:06:59 -05:00
|
|
|
selected={matrix[rowIndex][columnIndex] === 1}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
const draft = cloneDeep(matrix);
|
|
|
|
|
|
|
|
|
|
if (draft[rowIndex][columnIndex] === 1) {
|
|
|
|
|
draft[rowIndex][columnIndex] = 0;
|
|
|
|
|
} else {
|
|
|
|
|
draft[rowIndex][columnIndex] = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onChange(draft);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</Flex>
|
|
|
|
|
))}
|
|
|
|
|
</Flex>
|
|
|
|
|
))}
|
|
|
|
|
</Flex>
|
|
|
|
|
);
|
|
|
|
|
}
|