mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-09 22:42:31 -05:00
Fix references to window
This commit is contained in:
parent
28432b6f01
commit
652cc8a31c
2 changed files with 22 additions and 9 deletions
|
@ -64,7 +64,7 @@ WeDo2Blocks.prototype._motorOnFor = function(direction, durationSeconds, util) {
|
||||||
YieldTimers.resolve(this._motorTimeout);
|
YieldTimers.resolve(this._motorTimeout);
|
||||||
this._motorTimeout = null;
|
this._motorTimeout = null;
|
||||||
}
|
}
|
||||||
if (window.native) {
|
if (typeof window !== 'undefined' && window.native) {
|
||||||
window.native.motorRun(direction, this._motorSpeed);
|
window.native.motorRun(direction, this._motorSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ WeDo2Blocks.prototype._motorOnFor = function(direction, durationSeconds, util) {
|
||||||
if (instance._motorTimeout == myTimeout) {
|
if (instance._motorTimeout == myTimeout) {
|
||||||
instance._motorTimeout = null;
|
instance._motorTimeout = null;
|
||||||
}
|
}
|
||||||
if (window.native) {
|
if (typeof window !== 'undefined' && window.native) {
|
||||||
window.native.motorStop();
|
window.native.motorStop();
|
||||||
}
|
}
|
||||||
util.done();
|
util.done();
|
||||||
|
@ -132,7 +132,7 @@ WeDo2Blocks.prototype._getColor = function(colorName) {
|
||||||
};
|
};
|
||||||
|
|
||||||
WeDo2Blocks.prototype.setColor = function(argValues, util) {
|
WeDo2Blocks.prototype.setColor = function(argValues, util) {
|
||||||
if (window.native) {
|
if (typeof window !== 'undefined' && window.native) {
|
||||||
var colorIndex = this._getColor(argValues[0]);
|
var colorIndex = this._getColor(argValues[0]);
|
||||||
window.native.setLedColor(colorIndex);
|
window.native.setLedColor(colorIndex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -210,10 +210,6 @@ Runtime.prototype.stopAll = function () {
|
||||||
// Actually remove the thread.
|
// Actually remove the thread.
|
||||||
this._removeThread(poppedThread);
|
this._removeThread(poppedThread);
|
||||||
}
|
}
|
||||||
// @todo call stop function in all extensions/packages/WeDo stub
|
|
||||||
if (window.native) {
|
|
||||||
window.native.motorStop();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -243,12 +239,29 @@ Runtime.prototype.glowBlock = function (blockId, isGlowing) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setInterval implementation that works in a WebWorker or not.
|
||||||
|
* @param {?Function} fcn Function to call.
|
||||||
|
* @param {number} interval Interval at which to call it.
|
||||||
|
* @return {number} Value returned by setInterval.
|
||||||
|
*/
|
||||||
|
Runtime.prototype._setInterval = function(fcn, interval) {
|
||||||
|
var setInterval = null;
|
||||||
|
if (typeof window !== 'undefined' && window.setInterval) {
|
||||||
|
setInterval = window.setInterval;
|
||||||
|
} else if (typeof self !== 'undefined' && self.setInterval) {
|
||||||
|
setInterval = self.setInterval;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return setInterval(fcn, interval);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up timers to repeatedly step in a browser
|
* Set up timers to repeatedly step in a browser
|
||||||
*/
|
*/
|
||||||
Runtime.prototype.start = function () {
|
Runtime.prototype.start = function () {
|
||||||
if (!window.setInterval) return;
|
this._setInterval(function() {
|
||||||
window.setInterval(function() {
|
|
||||||
this._step();
|
this._step();
|
||||||
}.bind(this), Runtime.THREAD_STEP_INTERVAL);
|
}.bind(this), Runtime.THREAD_STEP_INTERVAL);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue