Spaces:
Sleeping
Sleeping
File size: 4,574 Bytes
e067c2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
import React, { useState } from 'react';
import { useGridStore } from '../../store/gridStore';
import { Card, CardContent, CardHeader, CardTitle } from '../ui/card';
import { Button } from '../ui/button';
import { Settings, Shuffle } from 'lucide-react';
import type { GridConfig } from '../../types';
export const GridGenerator: React.FC = () => {
const { generateNewGrid, isLoading } = useGridStore();
const [config, setConfig] = useState<GridConfig>({
width: 8,
height: 8,
numStores: 2,
numDestinations: 3,
numTunnels: 2,
obstacleDensity: 0.1,
});
const handleGenerate = () => {
generateNewGrid(config);
};
return (
<Card>
<CardHeader className="pb-3">
<CardTitle className="flex items-center gap-2 text-zinc-400 font-medium">
<Settings className="w-4 h-4" />
Configuration
</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
<div className="grid grid-cols-2 gap-3">
<div className="space-y-1">
<label className="text-xs text-zinc-500">Width</label>
<input
type="number"
min={5}
max={20}
value={config.width}
onChange={(e) => setConfig({ ...config, width: parseInt(e.target.value) })}
className="w-full px-2.5 py-1.5 bg-zinc-800 border border-zinc-700 rounded text-zinc-200 text-sm font-mono focus:outline-none focus:border-zinc-600"
/>
</div>
<div className="space-y-1">
<label className="text-xs text-zinc-500">Height</label>
<input
type="number"
min={5}
max={20}
value={config.height}
onChange={(e) => setConfig({ ...config, height: parseInt(e.target.value) })}
className="w-full px-2.5 py-1.5 bg-zinc-800 border border-zinc-700 rounded text-zinc-200 text-sm font-mono focus:outline-none focus:border-zinc-600"
/>
</div>
<div className="space-y-1">
<label className="text-xs text-zinc-500">Stores</label>
<input
type="number"
min={1}
max={3}
value={config.numStores}
onChange={(e) => setConfig({ ...config, numStores: parseInt(e.target.value) })}
className="w-full px-2.5 py-1.5 bg-zinc-800 border border-zinc-700 rounded text-zinc-200 text-sm font-mono focus:outline-none focus:border-zinc-600"
/>
</div>
<div className="space-y-1">
<label className="text-xs text-zinc-500">Destinations</label>
<input
type="number"
min={1}
max={10}
value={config.numDestinations}
onChange={(e) => setConfig({ ...config, numDestinations: parseInt(e.target.value) })}
className="w-full px-2.5 py-1.5 bg-zinc-800 border border-zinc-700 rounded text-zinc-200 text-sm font-mono focus:outline-none focus:border-zinc-600"
/>
</div>
<div className="space-y-1">
<label className="text-xs text-zinc-500">Tunnels</label>
<input
type="number"
min={0}
max={5}
value={config.numTunnels}
onChange={(e) => setConfig({ ...config, numTunnels: parseInt(e.target.value) })}
className="w-full px-2.5 py-1.5 bg-zinc-800 border border-zinc-700 rounded text-zinc-200 text-sm font-mono focus:outline-none focus:border-zinc-600"
/>
</div>
<div className="space-y-1">
<label className="text-xs text-zinc-500">Obstacles</label>
<input
type="number"
min={0}
max={0.5}
step={0.05}
value={config.obstacleDensity}
onChange={(e) => setConfig({ ...config, obstacleDensity: parseFloat(e.target.value) })}
className="w-full px-2.5 py-1.5 bg-zinc-800 border border-zinc-700 rounded text-zinc-200 text-sm font-mono focus:outline-none focus:border-zinc-600"
/>
</div>
</div>
<Button
onClick={handleGenerate}
disabled={isLoading}
variant="primary"
className="w-full"
size="sm"
>
<Shuffle className="w-4 h-4" />
{isLoading ? 'Generating...' : 'Generate Grid'}
</Button>
</CardContent>
</Card>
);
};
export default GridGenerator;
|