tried to dix the nap logic
This commit is contained in:
parent
da848f6800
commit
ffd9778e32
1 changed files with 25 additions and 22 deletions
|
@ -24,7 +24,7 @@ let state = {
|
|||
|
||||
updateColorState();
|
||||
|
||||
let updateStateInterval = setInterval(updateColorState, 1000);
|
||||
let updateColorStateInterval = setInterval(updateColorState, 1000);
|
||||
|
||||
let renderInterval = setInterval(render, 50);
|
||||
|
||||
|
@ -42,6 +42,7 @@ function updateColorState() {
|
|||
let newColor = state.color;
|
||||
switch(state.napTime) {
|
||||
case true:
|
||||
console.log("Nap time until :", state.napEnd);
|
||||
if(Date.now() < state.napEnd) {
|
||||
newColor = "red";
|
||||
break;
|
||||
|
@ -52,16 +53,18 @@ function updateColorState() {
|
|||
};
|
||||
}
|
||||
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: timing.color
|
||||
color: newColor,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
|
Loading…
Reference in a new issue