summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@vistahigherlearning.com>2022-01-22 18:43:07 -0500
committerDavid Thompson <dthompson@vistahigherlearning.com>2022-01-22 18:43:07 -0500
commit12df16190941db0bae0b804030ff5623ba9c860e (patch)
tree482b8fe8eb43d1af32138ea0ba3157ab48cb2a18
parentd445a346dc578d6078191931064fc915c1bad78b (diff)
Properly handle transplanted succession plantings.
-rw-r--r--js/garden.js57
1 files 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
+ };
});
}