Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrussell2 committed Oct 1, 2024
1 parent a3001e9 commit 7a39a16
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions heap.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ var LINE_COLOR = BLUE;
var TEXT_COLOR = DARKGREY;
var ALGO_SPEED = 1;
var ALGO_STATUS = 'stopped';
var USER_PAUSED = false;

// these will change dependent on the above params
var BOX_DIM = DEF_BOX_DIM;
Expand All @@ -119,6 +120,16 @@ var PAUSE_CONTROLLER;
var SWAPS = [];
var SWAP_IDX = 0;

function handleVisibilityChange() {
if (document.hidden && ALGO_STATUS === "running") {
ALGO_STATUS = "paused";
}
if (!document.hidden && ALGO_STATUS === "paused" && !USER_PAUSED) {
ALGO_STATUS = "running";
}
}
document.addEventListener("visibilitychange", handleVisibilityChange);


function createNode( x, y, z, i, format ) {

Expand Down Expand Up @@ -775,14 +786,17 @@ function runFunc( pcFunc, userFunc, button ) {
button.name('pause');
button.updateDisplay();
pcFunc();
USER_PAUSED = false;
}else if (ALGO_STATUS === "running") {
ALGO_STATUS = "paused";
button.name('resume');
button.updateDisplay();
USER_PAUSED = true;
}else if (ALGO_STATUS === "paused") {
ALGO_STATUS = "running";
button.name('pause');
button.updateDisplay();
USER_PAUSED = false;
}
} else {
userFunc();
Expand Down

0 comments on commit 7a39a16

Please sign in to comment.