UNPKG

@jeremyckahn/farmhand

Version:
31 lines (24 loc) 615 B
import { getPlotContentType } from '../../utils/getPlotContentType.js' import { itemType } from '../../enums.js' import { modifyFieldPlotAt } from './modifyFieldPlotAt.js' export const waterPlot = ( state: farmhand.state, x: number, y: number ): farmhand.state => { const plotContent = state.field[y][x] const canBeWatered = plotContent && getPlotContentType(plotContent) === itemType.CROP if (!canBeWatered) { return state } return modifyFieldPlotAt(state, x, y, crop => { if (!crop) { return crop } return { ...crop, wasWateredToday: true, } }) }