Skip to content

Commit

Permalink
Temporary pause changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AshimeeAlt committed Oct 4, 2024
1 parent d49d0eb commit 5cf159b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/engine/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,11 @@ class Runtime extends EventEmitter {
*/
this.finishedAssetRequests = 0;

/**
* Whether or not the project is currently paused
*/
this.paused = false;

/**
* Export some internal values for extensions.
*/
Expand Down Expand Up @@ -756,6 +761,14 @@ class Runtime extends EventEmitter {
return 'PROJECT_START';
}

/**
* Event name when the project is paused
* @const {string}
*/
static get PROJECT_PAUSE () {
return 'PROJECT_PAUSE';
}

/**
* Event name when threads start running.
* Used by the UI to indicate running status.
Expand Down Expand Up @@ -2202,6 +2215,23 @@ class Runtime extends EventEmitter {
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------

setPause(status) {
status = status || false;
const didChange = this.paused !== status;
this.paused = status;
if (status) {
if (!this.ioDevices.clock._paused) {
this.ioDevices.clock.pause();
}
this.audioEngine.audioContext.suspend();
}
if (!status && didChange) {
this.audioEngine.audioContext.resume();
this.ioDevices.clock.resume();
}
this.emit(Runtime.PROJECT_PAUSE, status);
}

/**
* Create a thread and push it to the list of threads.
* @param {!string} id ID of block that starts the stack.
Expand Down Expand Up @@ -2667,6 +2697,7 @@ class Runtime extends EventEmitter {
*/
greenFlag () {
this.stopAll();
this.setPause(false);
this.emit(Runtime.PROJECT_START);
this.updateCurrentMSecs();
this.ioDevices.clock.resetProjectTimer();
Expand Down
3 changes: 3 additions & 0 deletions src/virtual-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ class VirtualMachine extends EventEmitter {
this.runtime.on(Runtime.PROJECT_START, () => {
this.emit(Runtime.PROJECT_START);
});
this.runtime.on(Runtime.PROJECT_PAUSE, paused => {
this.emit(Runtime.PROJECT_PAUSE, paused);
});
this.runtime.on(Runtime.PROJECT_RUN_START, () => {
this.emit(Runtime.PROJECT_RUN_START);
});
Expand Down

0 comments on commit 5cf159b

Please sign in to comment.