tried to dix the nap logic

This commit is contained in:
John Shaver 2018-12-12 19:28:49 -08:00
parent da848f6800
commit ffd9778e32
1 changed files with 25 additions and 22 deletions

View File

@ -24,7 +24,7 @@ let state = {
updateColorState();
let updateStateInterval = setInterval(updateColorState, 1000);
let updateColorStateInterval = setInterval(updateColorState, 1000);
let renderInterval = setInterval(render, 50);
@ -41,27 +41,30 @@ function startNap(level, tick) {
function updateColorState() {
let newColor = state.color;
switch(state.napTime) {
case true:
if(Date.now() < state.napEnd) {
newColor = "red";
break;
} else {
state = { ...state,
napTime: false,
napEnd: 0,
};
}
case false:
let time = getTime();
let timing = timings.find(x => x.start <= time && x.end > time);
newColor = timing.color
}
if(newColor !== state.color) {
state = { ...state,
color: timing.color
};
}
case true:
console.log("Nap time until :", state.napEnd);
if(Date.now() < state.napEnd) {
newColor = "red";
break;
} else {
state = { ...state,
napTime: false,
napEnd: 0,
};
}
case false:
console.log("NO NAP!");
let time = getTime();
let timing = timings.find(x => x.start <= time && x.end > time);
newColor = timing.color
}
if(newColor !== state.color) {
console.log("setting color to", newcolor);
state = { ...state,
color: newColor,
};
}
}
function render() {