mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-22 14:02:37 -05:00
Merge pull request #11 from tmickel/feature/blockly-feedback
Block and stack glowing
This commit is contained in:
commit
f90fccb0d1
4 changed files with 77 additions and 15 deletions
|
@ -36,6 +36,30 @@ function Runtime () {
|
|||
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
|
||||
*/
|
||||
|
@ -165,7 +189,10 @@ Runtime.prototype.deleteBlock = function (e) {
|
|||
* @param {!string} id ID of block that starts the stack
|
||||
*/
|
||||
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);
|
||||
this.threads.push(thread);
|
||||
};
|
||||
|
@ -176,7 +203,10 @@ Runtime.prototype._pushThread = function (id) {
|
|||
*/
|
||||
Runtime.prototype._removeThread = function (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);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,12 +5,13 @@
|
|||
*/
|
||||
function Thread (firstBlock) {
|
||||
/**
|
||||
* Top block of the thread
|
||||
* ID of top block of the thread
|
||||
* @type {!string}
|
||||
*/
|
||||
this.topBlock = firstBlock;
|
||||
/**
|
||||
* Next block that the thread will execute.
|
||||
* @type {string}
|
||||
* ID of next block that the thread will execute, or null if none.
|
||||
* @type {?string}
|
||||
*/
|
||||
this.nextBlock = firstBlock;
|
||||
/**
|
||||
|
|
41
vm.js
41
vm.js
|
@ -1214,6 +1214,30 @@
|
|||
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
|
||||
*/
|
||||
|
@ -1343,7 +1367,10 @@
|
|||
* @param {!string} id ID of block that starts the stack
|
||||
*/
|
||||
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);
|
||||
this.threads.push(thread);
|
||||
};
|
||||
|
@ -1354,7 +1381,10 @@
|
|||
*/
|
||||
Runtime.prototype._removeThread = function (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) {
|
||||
/**
|
||||
* Top block of the thread
|
||||
* ID of top block of the thread
|
||||
* @type {!string}
|
||||
*/
|
||||
this.topBlock = firstBlock;
|
||||
/**
|
||||
* Next block that the thread will execute.
|
||||
* @type {string}
|
||||
* ID of next block that the thread will execute, or null if none.
|
||||
* @type {?string}
|
||||
*/
|
||||
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