mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-06-03 17:14:27 -04:00
Merge pull request #33 from tmickel/feature/wedo-fixes
A few WeDo fixes
This commit is contained in:
commit
c7a7e47cd4
5 changed files with 63 additions and 11 deletions
|
@ -177,11 +177,16 @@ WeDo2Blocks.prototype._getColor = function(colorName) {
|
||||||
}[colorName];
|
}[colorName];
|
||||||
};
|
};
|
||||||
|
|
||||||
WeDo2Blocks.prototype.setColor = function(argValues) {
|
WeDo2Blocks.prototype.setColor = function(argValues, util) {
|
||||||
if (window.native) {
|
if (window.native) {
|
||||||
var rgbColor = this._getColor(argValues[0]);
|
var rgbColor = this._getColor(argValues[0]);
|
||||||
window.native.setLedColor(rgbColor[0], rgbColor[1], rgbColor[2]);
|
window.native.setLedColor(rgbColor[0], rgbColor[1], rgbColor[2]);
|
||||||
}
|
}
|
||||||
|
// Pause for quarter second
|
||||||
|
util.yield();
|
||||||
|
util.timeout(function() {
|
||||||
|
util.done();
|
||||||
|
}, 250);
|
||||||
};
|
};
|
||||||
|
|
||||||
WeDo2Blocks.prototype.whenDistanceClose = function() {
|
WeDo2Blocks.prototype.whenDistanceClose = function() {
|
||||||
|
|
|
@ -288,6 +288,27 @@ Runtime.prototype.greenFlag = function () {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Distance sensor hack
|
||||||
|
*/
|
||||||
|
Runtime.prototype.startDistanceSensors = function () {
|
||||||
|
// Add all top stacks with distance sensor
|
||||||
|
for (var j = 0; j < this.stacks.length; j++) {
|
||||||
|
var topBlock = this.stacks[j];
|
||||||
|
if (this.blocks[topBlock].opcode === 'wedo_whendistanceclose') {
|
||||||
|
var alreadyRunning = false;
|
||||||
|
for (var k = 0; k < this.threads.length; k++) {
|
||||||
|
if (this.threads[k].topBlock === topBlock) {
|
||||||
|
alreadyRunning = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!alreadyRunning) {
|
||||||
|
this._pushThread(this.stacks[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop "everything"
|
* Stop "everything"
|
||||||
*/
|
*/
|
||||||
|
@ -297,6 +318,9 @@ Runtime.prototype.stopAll = function () {
|
||||||
this._removeThread(threadsCopy.pop());
|
this._removeThread(threadsCopy.pop());
|
||||||
}
|
}
|
||||||
// @todo call stop function in all extensions/packages/WeDo stub
|
// @todo call stop function in all extensions/packages/WeDo stub
|
||||||
|
if (window.native) {
|
||||||
|
window.native.motorStop();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -131,7 +131,6 @@ Sequencer.prototype.stepThread = function (thread) {
|
||||||
thread.status = Thread.STATUS_DONE;
|
thread.status = Thread.STATUS_DONE;
|
||||||
// Refresh nextBlock in case it has changed during a yield.
|
// Refresh nextBlock in case it has changed during a yield.
|
||||||
thread.nextBlock = instance.runtime._getNextBlock(currentBlock);
|
thread.nextBlock = instance.runtime._getNextBlock(currentBlock);
|
||||||
instance.runtime.glowBlock(currentBlock, false);
|
|
||||||
// Pop the stack and stack frame
|
// Pop the stack and stack frame
|
||||||
thread.stack.pop();
|
thread.stack.pop();
|
||||||
thread.stackFrames.pop();
|
thread.stackFrames.pop();
|
||||||
|
@ -181,7 +180,6 @@ Sequencer.prototype.stepThread = function (thread) {
|
||||||
} else {
|
} else {
|
||||||
thread.nextBlock = null;
|
thread.nextBlock = null;
|
||||||
}
|
}
|
||||||
instance.runtime.glowBlock(currentBlock, false);
|
|
||||||
switchedStack = true;
|
switchedStack = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -210,7 +208,6 @@ Sequencer.prototype.stepThread = function (thread) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
this.runtime.glowBlock(currentBlock, true);
|
|
||||||
// @todo deal with the return value
|
// @todo deal with the return value
|
||||||
blockFunction(argValues, {
|
blockFunction(argValues, {
|
||||||
yield: threadYieldCallback,
|
yield: threadYieldCallback,
|
||||||
|
|
34
vm.js
34
vm.js
|
@ -1466,6 +1466,27 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Distance sensor hack
|
||||||
|
*/
|
||||||
|
Runtime.prototype.startDistanceSensors = function () {
|
||||||
|
// Add all top stacks with distance sensor
|
||||||
|
for (var j = 0; j < this.stacks.length; j++) {
|
||||||
|
var topBlock = this.stacks[j];
|
||||||
|
if (this.blocks[topBlock].opcode === 'wedo_whendistanceclose') {
|
||||||
|
var alreadyRunning = false;
|
||||||
|
for (var k = 0; k < this.threads.length; k++) {
|
||||||
|
if (this.threads[k].topBlock === topBlock) {
|
||||||
|
alreadyRunning = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!alreadyRunning) {
|
||||||
|
this._pushThread(this.stacks[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop "everything"
|
* Stop "everything"
|
||||||
*/
|
*/
|
||||||
|
@ -1475,6 +1496,9 @@
|
||||||
this._removeThread(threadsCopy.pop());
|
this._removeThread(threadsCopy.pop());
|
||||||
}
|
}
|
||||||
// @todo call stop function in all extensions/packages/WeDo stub
|
// @todo call stop function in all extensions/packages/WeDo stub
|
||||||
|
if (window.native) {
|
||||||
|
window.native.motorStop();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1693,7 +1717,6 @@
|
||||||
thread.status = Thread.STATUS_DONE;
|
thread.status = Thread.STATUS_DONE;
|
||||||
// Refresh nextBlock in case it has changed during a yield.
|
// Refresh nextBlock in case it has changed during a yield.
|
||||||
thread.nextBlock = instance.runtime._getNextBlock(currentBlock);
|
thread.nextBlock = instance.runtime._getNextBlock(currentBlock);
|
||||||
instance.runtime.glowBlock(currentBlock, false);
|
|
||||||
// Pop the stack and stack frame
|
// Pop the stack and stack frame
|
||||||
thread.stack.pop();
|
thread.stack.pop();
|
||||||
thread.stackFrames.pop();
|
thread.stackFrames.pop();
|
||||||
|
@ -1743,7 +1766,6 @@
|
||||||
} else {
|
} else {
|
||||||
thread.nextBlock = null;
|
thread.nextBlock = null;
|
||||||
}
|
}
|
||||||
instance.runtime.glowBlock(currentBlock, false);
|
|
||||||
switchedStack = true;
|
switchedStack = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1772,7 +1794,6 @@
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
this.runtime.glowBlock(currentBlock, true);
|
|
||||||
// @todo deal with the return value
|
// @todo deal with the return value
|
||||||
blockFunction(argValues, {
|
blockFunction(argValues, {
|
||||||
yield: threadYieldCallback,
|
yield: threadYieldCallback,
|
||||||
|
@ -2270,11 +2291,16 @@
|
||||||
}[colorName];
|
}[colorName];
|
||||||
};
|
};
|
||||||
|
|
||||||
WeDo2Blocks.prototype.setColor = function(argValues) {
|
WeDo2Blocks.prototype.setColor = function(argValues, util) {
|
||||||
if (window.native) {
|
if (window.native) {
|
||||||
var rgbColor = this._getColor(argValues[0]);
|
var rgbColor = this._getColor(argValues[0]);
|
||||||
window.native.setLedColor(rgbColor[0], rgbColor[1], rgbColor[2]);
|
window.native.setLedColor(rgbColor[0], rgbColor[1], rgbColor[2]);
|
||||||
}
|
}
|
||||||
|
// Pause for quarter second
|
||||||
|
util.yield();
|
||||||
|
util.timeout(function() {
|
||||||
|
util.done();
|
||||||
|
}, 250);
|
||||||
};
|
};
|
||||||
|
|
||||||
WeDo2Blocks.prototype.whenDistanceClose = function() {
|
WeDo2Blocks.prototype.whenDistanceClose = function() {
|
||||||
|
|
6
vm.min.js
vendored
6
vm.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue