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

View file

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