@jeremyckahn/farmhand
Version:
A farming game
18 lines (12 loc) • 516 B
text/typescript
import { cropLifeStage } from '../enums.js'
import { itemsMap } from '../data/maps.js'
import { getLifeStageRange } from './getLifeStageRange.js'
const { SEED, GROWING, GROWN } = cropLifeStage
export const getCropLifeStage = (crop: farmhand.crop): cropLifeStage => {
const { itemId, daysWatered = 0 } = crop
const { cropTimeline } = itemsMap[itemId]
if (!cropTimeline) {
throw new Error(`${itemId} has no cropTimeline`)
}
return getLifeStageRange(cropTimeline)[Math.floor(daysWatered)] || GROWN
}