Got rid of the mark/plant distinction, player can plant directly.

This commit is contained in:
Ryan Lanny Jenkins 2025-06-04 20:54:09 -05:00
parent b2820bbb47
commit d5b950b541
3 changed files with 56 additions and 58 deletions

View file

@ -1,6 +1,6 @@
import React, { useState } from 'react'
import { useGameStore } from '../store/useGameStore'
import { CROPS } from '../constants'
import { CROPS, ITEMS } from '../constants'
import { FieldTool, PlotState } from '../types'
import Modal from './Modal'
@ -154,10 +154,6 @@ const PlotInfoModal: React.FC<PlotInfoModalProps> = ({ plot, onClose }) => {
: 'None'}
</span>
</div>
<div style={plotInfoItemStyle}>
<span>Intended Crop:</span>
<span>{plot.intended ? CROPS[plot.intended].name : 'None'}</span>
</div>
<div style={plotInfoItemStyle}>
<span>Water Level:</span>
<span>{formatPercentage(plot.moisture)}</span>
@ -190,12 +186,12 @@ const FieldComponent: React.FC = () => {
water,
harvest,
remove,
assignCrop,
inventory,
actionCooldown,
} = useGameStore()
const [selectedCrop, setSelectedCrop] = useState<string | null>(null)
const [selectedTool, setSelectedTool] = useState<FieldTool>('mark')
const [selectedSeed, setSelectedSeed] = useState<string | null>(null)
const [selectedTool, setSelectedTool] = useState<FieldTool>('plant')
const [inspectedPlot, setInspectedPlot] = useState<{
plot: PlotState
row: number
@ -206,13 +202,13 @@ const FieldComponent: React.FC = () => {
if (actionCooldown > 0) return
switch (selectedTool) {
case 'mark':
if (selectedCrop) {
assignCrop(row, col, selectedCrop)
}
break
case 'plant':
plant(row, col)
if (selectedSeed) {
const crop = Object.values(CROPS).find(c => c.seedType === selectedSeed)
if (crop && inventory[selectedSeed] > 0) {
plant(row, col, crop.id)
}
}
break
case 'water':
water(row, col)
@ -246,7 +242,6 @@ const FieldComponent: React.FC = () => {
}
const tools: { id: FieldTool; label: string; icon: string }[] = [
{ id: 'mark', label: 'Mark', icon: '🎯' },
{ id: 'plant', label: 'Plant', icon: '🌱' },
{ id: 'water', label: 'Water', icon: '💧' },
{ id: 'harvest', label: 'Harvest', icon: '✂️' },
@ -254,6 +249,14 @@ const FieldComponent: React.FC = () => {
{ id: 'inspect', label: 'Inspect', icon: '🔍' },
]
// Get available seeds from inventory
const availableSeeds = Object.entries(inventory)
.filter(([itemId, count]) => {
const crop = Object.values(CROPS).find(c => c.seedType === itemId)
return crop && count > 0
})
.map(([itemId]) => itemId)
return (
<div style={fieldContainerStyle}>
<h2 style={titleStyle}>Fields</h2>
@ -271,18 +274,28 @@ const FieldComponent: React.FC = () => {
))}
</div>
{selectedTool === 'mark' && (
{selectedTool === 'plant' && (
<div style={cropSelectionContainerStyle}>
<p style={cropSelectionLabelStyle}>Select a crop to mark:</p>
{Object.values(CROPS).map((crop) => (
<p style={cropSelectionLabelStyle}>Select a seed to plant:</p>
{availableSeeds.length > 0 ? (
availableSeeds.map((seedId) => {
const crop = Object.values(CROPS).find(c => c.seedType === seedId)
if (!crop) return null
return (
<button
key={crop.id}
style={getCropButtonStyle(selectedCrop === crop.id)}
onClick={() => setSelectedCrop(crop.id)}
key={seedId}
style={getCropButtonStyle(selectedSeed === seedId)}
onClick={() => setSelectedSeed(seedId)}
>
{crop.name}
{ITEMS[seedId].emoji} {crop.name} ({inventory[seedId]})
</button>
))}
)
})
) : (
<p style={{ width: '100%', textAlign: 'center', color: '#666' }}>
No seeds available in inventory
</p>
)}
</div>
)}
@ -299,9 +312,6 @@ const FieldComponent: React.FC = () => {
style={getPlotStyle(bgColor)}
onClick={() => handlePlotClick(rowIndex, colIndex)}
>
{plot.intended && !plot.current && (
<div>🌱 {CROPS[plot.intended]?.name}</div>
)}
{plot.current && (
<div>
{plot.current.mature ? '🌿' : '🌱'}{' '}

View file

@ -98,12 +98,11 @@ const progressRandomImmaturePlot = (
export const useGameStore = create<
GameState & {
plant: (row: number, col: number) => void
plant: (row: number, col: number, cropId: string) => void
water: (row: number, col: number) => void
harvest: (row: number, col: number) => void
remove: (row: number, col: number) => void
tick: () => void
assignCrop: (row: number, col: number, cropId: string) => void
upgradeField: () => void
setGameSpeed: (speed: number) => void
setActionCooldown: (cooldown: number) => void
@ -140,15 +139,7 @@ export const useGameStore = create<
equipment: {},
milestones: {},
assignCrop: (row, col, cropId) => {
set(
produce((state) => {
state.plots[row][col].intended = cropId
}),
)
},
plant: (row, col) => {
plant: (row, col, cropId) => {
const { plots, inventory, actionCooldown } = get()
if (actionCooldown > 0) {
@ -156,15 +147,14 @@ export const useGameStore = create<
}
const plot = plots[row][col]
if (plot.intended && !plot.current) {
const crop = CROPS[plot.intended]
const crop = CROPS[cropId]
const seedId = crop.seedType
if (inventory[seedId] && inventory[seedId] > 0) {
if (!plot.current && inventory[seedId] && inventory[seedId] > 0) {
set(
produce((state) => {
state.plots[row][col].current = {
cropId: plot.intended!,
cropId: cropId,
progress: 0,
mature: false,
}
@ -174,7 +164,6 @@ export const useGameStore = create<
}),
)
}
}
},
water: (row, col) => {

View file

@ -16,7 +16,6 @@ export interface CropDefinitions {
}
export interface PlotState {
intended?: string
current?: {
cropId: string
progress: number
@ -31,7 +30,7 @@ export interface InventoryItem {
count: number
}
export type FieldTool = 'mark' | 'plant' | 'water' | 'harvest' | 'inspect' | 'remove'
export type FieldTool = 'plant' | 'water' | 'harvest' | 'inspect' | 'remove'
export interface ConsoleMessage {
id: string