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