mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-22 22:12:28 -05:00
Add stack glow and infrastructure for block glow
This commit is contained in:
parent
773f2e1bbc
commit
79f6725ff3
3 changed files with 73 additions and 12 deletions
|
@ -36,6 +36,30 @@ function Runtime () {
|
||||||
this.sequencer = new Sequencer(this);
|
this.sequencer = new Sequencer(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event name for glowing a stack
|
||||||
|
* @const {string}
|
||||||
|
*/
|
||||||
|
Runtime.STACK_GLOW_ON = 'STACK_GLOW_ON';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event name for unglowing a stack
|
||||||
|
* @const {string}
|
||||||
|
*/
|
||||||
|
Runtime.STACK_GLOW_OFF = 'STACK_GLOW_OFF';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event name for glowing a block
|
||||||
|
* @const {string}
|
||||||
|
*/
|
||||||
|
Runtime.BLOCK_GLOW_ON = 'BLOCK_GLOW_ON';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event name for unglowing a block
|
||||||
|
* @const {string}
|
||||||
|
*/
|
||||||
|
Runtime.BLOCK_GLOW_OFF = 'BLOCK_GLOW_OFF';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inherit from EventEmitter
|
* Inherit from EventEmitter
|
||||||
*/
|
*/
|
||||||
|
@ -165,7 +189,10 @@ Runtime.prototype.deleteBlock = function (e) {
|
||||||
* @param {!string} id ID of block that starts the stack
|
* @param {!string} id ID of block that starts the stack
|
||||||
*/
|
*/
|
||||||
Runtime.prototype._pushThread = function (id) {
|
Runtime.prototype._pushThread = function (id) {
|
||||||
if (this.stacks.indexOf(id) < -1) return;
|
if (this.stacks.indexOf(id) < -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.emit(Runtime.STACK_GLOW_ON, id);
|
||||||
var thread = new Thread(id);
|
var thread = new Thread(id);
|
||||||
this.threads.push(thread);
|
this.threads.push(thread);
|
||||||
};
|
};
|
||||||
|
@ -176,7 +203,10 @@ Runtime.prototype._pushThread = function (id) {
|
||||||
*/
|
*/
|
||||||
Runtime.prototype._removeThread = function (thread) {
|
Runtime.prototype._removeThread = function (thread) {
|
||||||
var i = this.threads.indexOf(thread);
|
var i = this.threads.indexOf(thread);
|
||||||
if (i > -1) this.threads.splice(i, 1);
|
if (i > -1) {
|
||||||
|
this.emit(Runtime.STACK_GLOW_OFF, thread.topBlock);
|
||||||
|
this.threads.splice(i, 1);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
41
vm.js
41
vm.js
|
@ -1214,6 +1214,30 @@
|
||||||
this.sequencer = new Sequencer(this);
|
this.sequencer = new Sequencer(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event name for glowing a stack
|
||||||
|
* @const {string}
|
||||||
|
*/
|
||||||
|
Runtime.STACK_GLOW_ON = 'STACK_GLOW_ON';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event name for unglowing a stack
|
||||||
|
* @const {string}
|
||||||
|
*/
|
||||||
|
Runtime.STACK_GLOW_OFF = 'STACK_GLOW_OFF';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event name for glowing a block
|
||||||
|
* @const {string}
|
||||||
|
*/
|
||||||
|
Runtime.BLOCK_GLOW_ON = 'BLOCK_GLOW_ON';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event name for unglowing a block
|
||||||
|
* @const {string}
|
||||||
|
*/
|
||||||
|
Runtime.BLOCK_GLOW_OFF = 'BLOCK_GLOW_OFF';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inherit from EventEmitter
|
* Inherit from EventEmitter
|
||||||
*/
|
*/
|
||||||
|
@ -1343,7 +1367,10 @@
|
||||||
* @param {!string} id ID of block that starts the stack
|
* @param {!string} id ID of block that starts the stack
|
||||||
*/
|
*/
|
||||||
Runtime.prototype._pushThread = function (id) {
|
Runtime.prototype._pushThread = function (id) {
|
||||||
if (this.stacks.indexOf(id) < -1) return;
|
if (this.stacks.indexOf(id) < -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.emit(Runtime.STACK_GLOW_ON, id);
|
||||||
var thread = new Thread(id);
|
var thread = new Thread(id);
|
||||||
this.threads.push(thread);
|
this.threads.push(thread);
|
||||||
};
|
};
|
||||||
|
@ -1354,7 +1381,10 @@
|
||||||
*/
|
*/
|
||||||
Runtime.prototype._removeThread = function (thread) {
|
Runtime.prototype._removeThread = function (thread) {
|
||||||
var i = this.threads.indexOf(thread);
|
var i = this.threads.indexOf(thread);
|
||||||
if (i > -1) this.threads.splice(i, 1);
|
if (i > -1) {
|
||||||
|
this.emit(Runtime.STACK_GLOW_OFF, thread.topBlock);
|
||||||
|
this.threads.splice(i, 1);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1567,12 +1597,13 @@
|
||||||
*/
|
*/
|
||||||
function Thread (firstBlock) {
|
function Thread (firstBlock) {
|
||||||
/**
|
/**
|
||||||
* Top block of the thread
|
* ID of top block of the thread
|
||||||
|
* @type {!string}
|
||||||
*/
|
*/
|
||||||
this.topBlock = firstBlock;
|
this.topBlock = firstBlock;
|
||||||
/**
|
/**
|
||||||
* Next block that the thread will execute.
|
* ID of next block that the thread will execute, or null if none.
|
||||||
* @type {string}
|
* @type {?string}
|
||||||
*/
|
*/
|
||||||
this.nextBlock = firstBlock;
|
this.nextBlock = firstBlock;
|
||||||
/**
|
/**
|
||||||
|
|
10
vm.min.js
vendored
10
vm.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue