Skip to content
This repository has been archived by the owner on Jun 1, 2021. It is now read-only.

Commit

Permalink
Delay automatic highlighting by one interval (second) each time the u…
Browse files Browse the repository at this point in the history
…ser manually highlights something, up to

about ten intervals.
  • Loading branch information
joelpurra committed May 20, 2014
1 parent 7f178d1 commit c548bba
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/resources/javascript/main.js
Expand Up @@ -95,12 +95,20 @@
return node;
},
highlightOnInterval = function() {
var highlightHasHappened = false,
var MAX_AUTO_HIGHLIGHT_DELAY = 10,
highlightCounter = 0,
highlightCounterInterval,
isAutomatedHighlight = false,
interval;
highlightInterval;

function highlightCounterDecreaser() {
highlightCounter = Math.max(0, highlightCounter - 1);
}

document.addEventListener("hexagonif.line.highlight", function() {
highlightHasHappened = highlightHasHappened || !isAutomatedHighlight;
if (!isAutomatedHighlight) {
highlightCounter = Math.min(Number.MAX_VALUE - 1, highlightCounter + 1, MAX_AUTO_HIGHLIGHT_DELAY);
}
});

document.addEventListener("hexagonif.line.unhighlight", function() {
Expand Down Expand Up @@ -134,13 +142,14 @@
}

function highlightSomethingThatIfNothingHasHappened() {
if (!highlightHasHappened) {
if (highlightCounter === 0) {
highlightRandomLine();
highlightRandomHexagon();
}
}

interval = setInterval(highlightSomethingThatIfNothingHasHappened, 1000);
highlightCounterInterval = setInterval(highlightCounterDecreaser, 1000);
highlightInterval = setInterval(highlightSomethingThatIfNothingHasHappened, 1000);
},
scene = profiledRenderer();

Expand Down

0 comments on commit c548bba

Please sign in to comment.