From d5b950b541d67b3221a7d1d63e3adab013e57c2e Mon Sep 17 00:00:00 2001 From: Ryan Lanny Jenkins Date: Wed, 4 Jun 2025 20:54:09 -0500 Subject: [PATCH] Got rid of the mark/plant distinction, player can plant directly. --- src/components/Field.tsx | 68 ++++++++++++++++++++++----------------- src/store/useGameStore.ts | 43 +++++++++---------------- src/types/index.ts | 3 +- 3 files changed, 56 insertions(+), 58 deletions(-) diff --git a/src/components/Field.tsx b/src/components/Field.tsx index 0a5eb8e..1ec2374 100644 --- a/src/components/Field.tsx +++ b/src/components/Field.tsx @@ -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 = ({ plot, onClose }) => { : 'None'} -
- Intended Crop: - {plot.intended ? CROPS[plot.intended].name : 'None'} -
Water Level: {formatPercentage(plot.moisture)} @@ -190,12 +186,12 @@ const FieldComponent: React.FC = () => { water, harvest, remove, - assignCrop, + inventory, actionCooldown, } = useGameStore() - const [selectedCrop, setSelectedCrop] = useState(null) - const [selectedTool, setSelectedTool] = useState('mark') + const [selectedSeed, setSelectedSeed] = useState(null) + const [selectedTool, setSelectedTool] = useState('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 (

Fields

@@ -271,18 +274,28 @@ const FieldComponent: React.FC = () => { ))}
- {selectedTool === 'mark' && ( + {selectedTool === 'plant' && (
-

Select a crop to mark:

- {Object.values(CROPS).map((crop) => ( - - ))} +

Select a seed to plant:

+ {availableSeeds.length > 0 ? ( + availableSeeds.map((seedId) => { + const crop = Object.values(CROPS).find(c => c.seedType === seedId) + if (!crop) return null + return ( + + ) + }) + ) : ( +

+ No seeds available in inventory +

+ )}
)} @@ -299,9 +312,6 @@ const FieldComponent: React.FC = () => { style={getPlotStyle(bgColor)} onClick={() => handlePlotClick(rowIndex, colIndex)} > - {plot.intended && !plot.current && ( -
🌱 {CROPS[plot.intended]?.name}
- )} {plot.current && (
{plot.current.mature ? '🌿' : '🌱'}{' '} diff --git a/src/store/useGameStore.ts b/src/store/useGameStore.ts index e1d7285..d038219 100644 --- a/src/store/useGameStore.ts +++ b/src/store/useGameStore.ts @@ -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,24 +147,22 @@ export const useGameStore = create< } const plot = plots[row][col] - if (plot.intended && !plot.current) { - const crop = CROPS[plot.intended] - const seedId = crop.seedType + const crop = CROPS[cropId] + const seedId = crop.seedType - if (inventory[seedId] && inventory[seedId] > 0) { - set( - produce((state) => { - state.plots[row][col].current = { - cropId: plot.intended!, - progress: 0, - mature: false, - } + if (!plot.current && inventory[seedId] && inventory[seedId] > 0) { + set( + produce((state) => { + state.plots[row][col].current = { + cropId: cropId, + progress: 0, + mature: false, + } - state.inventory[seedId] = state.inventory[seedId] - 1 - state.actionCooldown = COOLDOWN_DURATION - }), - ) - } + state.inventory[seedId] = state.inventory[seedId] - 1 + state.actionCooldown = COOLDOWN_DURATION + }), + ) } }, diff --git a/src/types/index.ts b/src/types/index.ts index 3d60bdf..1cf31dd 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -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