import React, { useState } from 'react' import { useGameStore } from '../store/useGameStore' import { CROPS } from '../constants' const fieldContainerStyle: React.CSSProperties = { display: 'flex', flexDirection: 'column', gap: '1rem', padding: '1rem', } const titleStyle: React.CSSProperties = { fontSize: '1.5rem', fontWeight: 'bold', marginBottom: '1rem', textAlign: 'center', } const cropSelectionContainerStyle: React.CSSProperties = { display: 'flex', flexWrap: 'wrap', gap: '0.5rem', marginBottom: '1rem', justifyContent: 'center', } const cropSelectionLabelStyle: React.CSSProperties = { width: '100%', textAlign: 'center', fontWeight: 500, marginBottom: '0.5rem', } const getCropButtonStyle = (active: boolean): React.CSSProperties => ({ padding: '0.5rem 1rem', borderRadius: '0.25rem', border: '1px solid #ccc', backgroundColor: active ? '#4ade80' : '#f3f4f6', cursor: 'pointer', }) const actionsContainerStyle: React.CSSProperties = { display: 'flex', gap: '0.5rem', marginBottom: '1rem', justifyContent: 'center', } const speedSelectorContainerStyle: React.CSSProperties = { display: 'flex', flexDirection: 'column', alignItems: 'center', marginBottom: '1rem', padding: '0.5rem', backgroundColor: '#f9fafb', borderRadius: '0.5rem', border: '1px solid #e5e7eb', } const speedSelectorLabelStyle: React.CSSProperties = { fontWeight: 500, marginBottom: '0.5rem', } const speedButtonsContainerStyle: React.CSSProperties = { display: 'flex', gap: '0.5rem', } const getSpeedButtonStyle = (active: boolean): React.CSSProperties => ({ padding: '0.5rem 1rem', borderRadius: '0.25rem', border: '1px solid #ccc', backgroundColor: active ? '#4ade80' : '#f3f4f6', cursor: 'pointer', }) const getActionButtonStyle = (disabled: boolean): React.CSSProperties => ({ padding: '0.5rem 1rem', borderRadius: '0.25rem', fontWeight: 'bold', color: 'white', backgroundColor: disabled ? '#9ca3af' : '#22c55e', cursor: disabled ? 'not-allowed' : 'pointer', }) const getFieldGridStyle = (size: number): React.CSSProperties => ({ display: 'grid', gridTemplateColumns: `repeat(${size}, 1fr)`, gridTemplateRows: `repeat(${size}, 1fr)`, gap: '0.5rem', width: '100%', maxWidth: '600px', margin: '0 auto', }) const getPlotStyle = (bgColor: string): React.CSSProperties => ({ border: '1px solid #78350f', aspectRatio: '1', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', position: 'relative', cursor: 'pointer', backgroundColor: bgColor, }) const getMoistureIndicatorStyle = (level: number): React.CSSProperties => ({ position: 'absolute', bottom: 0, left: 0, width: '100%', height: `${Math.min(level * 100, 100)}%`, backgroundColor: 'rgba(147, 197, 253, 0.3)', transition: 'height 0.3s', zIndex: 1, }) const getMaturityProgressContainerStyle = (): React.CSSProperties => ({ position: 'absolute', bottom: '10px', // Moved up from the bottom to separate from moisture indicator left: 0, width: '100%', height: '10px', // Increased height for better visibility backgroundColor: 'rgba(0, 0, 0, 0.3)', // Darker background for better contrast zIndex: 5, // Increased z-index to ensure it's above other elements border: '1px solid #000', // Added border for better visibility }) const getMaturityProgressBarStyle = ( progress: number, total: number, ): React.CSSProperties => ({ position: 'absolute', bottom: 0, left: 0, width: `${Math.min((progress / total) * 100, 100)}%`, height: '10px', // Increased height to match container backgroundColor: '#ff5722', // Brighter orange color for better visibility transition: 'width 0.3s', zIndex: 6, // Increased z-index to ensure it's above the container boxShadow: '0 0 3px rgba(0, 0, 0, 0.5)', // Added shadow for better visibility }) const FieldComponent: React.FC = () => { const { plots, fieldSize, plant, water, harvest, assignCrop, gameSpeed, setGameSpeed, actionCooldown, } = useGameStore() const [selectedCrop, setSelectedCrop] = useState(null) const handlePlotClick = (row: number, col: number) => { if (selectedCrop) { assignCrop(row, col, selectedCrop) } } const getBgColor = ( hasCrop: boolean, isMature: boolean, fertility: number, ) => { if (isMature) return '#22c55e' if (hasCrop) return '#86efac' // For empty plots, show fertility level through color // Convert fertility (0-1) to a color between light grey-brown and dark brown const r = Math.floor(146 + (73 - 146) * fertility) // 146 to 73 const g = Math.floor(131 + (47 - 131) * fertility) // 131 to 47 const b = Math.floor(120 + (23 - 120) * fertility) // 120 to 23 return `rgb(${r}, ${g}, ${b})` } const availableSpeeds = [1, 2, 4, 8, 16, 32, 64] return (

Fields

Game Speed:

{availableSpeeds.map((speed) => ( ))}

Select a crop to plant:

{Object.values(CROPS).map((crop) => ( ))}
{plots.slice(0, fieldSize).map((row, rowIndex) => row.slice(0, fieldSize).map((plot, colIndex) => { const hasCrop = !!plot.current const isMature = !!plot.current?.mature const bgColor = getBgColor(hasCrop, isMature, plot.fertility) return (
handlePlotClick(rowIndex, colIndex)} > {plot.intended && !plot.current && (
🌱 {CROPS[plot.intended]?.name}
)} {plot.current && (
{plot.current.mature ? '🌿' : '🌱'}{' '} {CROPS[plot.current.cropId]?.name}
)}
{plot.current && !plot.current.mature && (
)}
) }), )}
) } export default FieldComponent