From 12df16190941db0bae0b804030ff5623ba9c860e Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 22 Jan 2022 18:43:07 -0500 Subject: Properly handle transplanted succession plantings. --- js/garden.js | 57 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/js/garden.js b/js/garden.js index cb8a0ac..3e0ba35 100644 --- a/js/garden.js +++ b/js/garden.js @@ -428,6 +428,19 @@ function makeCropSchedule(crop, season) { function isSuccession(offset) { const start = offset <= crop.pause ? crop.springPlant : crop.resume; return crop.interval > 0 && + offset != crop.springPlant && + offset >= crop.springPlant && + offset <= fallPlant && + (offset <= crop.pause || offset >= resume) && + (offset - start) % crop.interval == 0; + } + + function isSuccessionStart(offset) { + offset += crop.headStart; + const start = offset <= crop.pause ? crop.springPlant : crop.resume; + return crop.interval > 0 && + crop.transplant && + offset != crop.springPlant && offset >= crop.springPlant && offset <= fallPlant && (offset <= crop.pause || offset >= resume) && @@ -440,31 +453,37 @@ function makeCropSchedule(crop, season) { const resume = season.length - crop.resume; return season.weeks.map(week => { - function action(type) { - const date = weeksLater(season.lastFrostDate, week.offset); - return { - date: date, - actions: type ? [type] : [] - }; - } + const actions = []; if(crop.transplant && week.offset == springStart) { - return action("start"); + actions.push("start"); } else if(crop.transplant && week.offset == crop.springPlant) { - return action("transplant"); + actions.push("transplant"); } else if(week.offset == crop.springPlant) { - return action("sow"); - } else if(isSuccession(week.offset)) { - return action("sow"); - } else if(crop.fallCrop && crop.transplant && week.offset == fallStart) { - return action("start"); - } else if(crop.fallCrop && crop.transplant && week.offset == fallPlant) { - return action("transplant"); - } else if(crop.fallCrop && week.offset == fallPlant) { - return action("sow"); + actions.push("sow"); } - return action(null); + if(isSuccession(week.offset)) { + actions.push(crop.transplant ? "transplant" : "sow"); + } + if(isSuccessionStart(week.offset)) { + actions.push("start"); + } + + if(crop.fallCrop) { + if(crop.transplant && week.offset == fallStart) { + actions.push("start"); + } else if(crop.transplant && week.offset == fallPlant) { + actions.push("transplant"); + } else if(week.offset == fallPlant) { + actions.push("sow"); + } + } + + return { + date: weeksLater(season.lastFrostDate, week.offset), + actions: actions + }; }); } -- cgit v1.2.3