kopia lustrzana https://github.com/backface/turtlestitch
pass message to upvar
rodzic
7394c69a27
commit
3a7a6e8ad9
43
src/api.js
43
src/api.js
|
@ -82,7 +82,7 @@ IDE_Morph.prototype.getCurrentScene = function () {
|
||||||
IDE_Morph.prototype.switchTo = function (sceneName) {
|
IDE_Morph.prototype.switchTo = function (sceneName) {
|
||||||
var scene = detect(this.scenes.itemsArray(), scn => scn.name === sceneName);
|
var scene = detect(this.scenes.itemsArray(), scn => scn.name === sceneName);
|
||||||
if (scene === null) {
|
if (scene === null) {
|
||||||
throw new Error('cannot find scene ' + sceneName);
|
throw new Error('cannot find scene ' + sceneName);
|
||||||
}
|
}
|
||||||
this.switchToScene(scene);
|
this.switchToScene(scene);
|
||||||
};
|
};
|
||||||
|
@ -135,16 +135,37 @@ IDE_Morph.prototype.broadcast = function(message, callback) {
|
||||||
throw new Error('message must be a String');
|
throw new Error('message must be a String');
|
||||||
}
|
}
|
||||||
this.stage.lastMessage = message;
|
this.stage.lastMessage = message;
|
||||||
rcvrs.forEach(sprite => {
|
rcvrs.forEach(morph => {
|
||||||
sprite.allHatBlocksFor(message).forEach(block => {
|
if (isSnapObject(morph)) {
|
||||||
procs.push(this.stage.threads.startProcess(
|
morph.allHatBlocksFor(message).forEach(block => {
|
||||||
block,
|
var varName, varFrame;
|
||||||
sprite,
|
if (block.selector === 'receiveMessage') {
|
||||||
this.stage.isThreadSafe,
|
varName = block.inputs()[1].evaluate()[0];
|
||||||
false,
|
if (varName) {
|
||||||
callback instanceof Function ? wait : null
|
varFrame = new VariableFrame();
|
||||||
));
|
varFrame.addVar(varName, message);
|
||||||
});
|
}
|
||||||
|
procs.push(this.stage.threads.startProcess(
|
||||||
|
block,
|
||||||
|
morph,
|
||||||
|
this.stage.isThreadSafe || // make "any msg" threadsafe
|
||||||
|
block.inputs()[0].evaluate() instanceof Array,
|
||||||
|
null, // exportResult (bool)
|
||||||
|
callback instanceof Function ? wait : null,
|
||||||
|
null, // isClicked
|
||||||
|
null, // rightAway
|
||||||
|
null, // atomic
|
||||||
|
varFrame
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
procs.push(stage.threads.startProcess(
|
||||||
|
block,
|
||||||
|
morph,
|
||||||
|
stage.isThreadSafe
|
||||||
|
));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
(this.stage.messageCallbacks[''] || []).forEach(
|
(this.stage.messageCallbacks[''] || []).forEach(
|
||||||
callback => callback(message)
|
callback => callback(message)
|
||||||
|
|
Ładowanie…
Reference in New Issue