new "send (msg) to (sprite)" primitive

pull/95/head
jmoenig 2020-04-26 13:11:58 +02:00
rodzic 69179a8cb8
commit 7efaa4321c
2 zmienionych plików z 23 dodań i 2 usunięć

Wyświetl plik

@ -84,7 +84,7 @@ BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, BooleanSlotMorph,
localize, TableMorph, TableFrameMorph, normalizeCanvas, VectorPaintEditorMorph,
HandleMorph, AlignmentMorph, Process, XML_Element, WorldMap, copyCanvas*/
modules.objects = '2020-April-25';
modules.objects = '2020-April-26';
var SpriteMorph;
var StageMorph;
@ -741,6 +741,11 @@ SpriteMorph.prototype.initBlocks = function () {
category: 'control',
spec: 'message'
},
doSend: {
type: 'command',
category: 'control',
spec: 'send %msg to %spr'
},
doWait: {
type: 'command',
category: 'control',
@ -2363,6 +2368,7 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push('-');
blocks.push(block('doBroadcast'));
blocks.push(block('doBroadcastAndWait'));
blocks.push(block('doSend'));
blocks.push(watcherToggle('getLastMessage'));
blocks.push(block('getLastMessage'));
blocks.push('-');
@ -8439,6 +8445,7 @@ StageMorph.prototype.blockTemplates = function (category) {
blocks.push('-');
blocks.push(block('doBroadcast'));
blocks.push(block('doBroadcastAndWait'));
blocks.push(block('doSend'));
blocks.push(watcherToggle('getLastMessage'));
blocks.push(block('getLastMessage'));
blocks.push('-');

Wyświetl plik

@ -61,7 +61,7 @@ StageMorph, SpriteMorph, StagePrompterMorph, Note, modules, isString, copy, Map,
isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph, Color,
TableFrameMorph, ColorSlotMorph, isSnapObject, newCanvas, Symbol, SVG_Costume*/
modules.threads = '2020-April-25';
modules.threads = '2020-April-26';
var ThreadManager;
var Process;
@ -3287,6 +3287,20 @@ Process.prototype.getLastMessage = function () {
return '';
};
Process.prototype.doSend = function (message, target) {
var stage = this.homeContext.receiver.parentThatIsA(StageMorph);
this.doBroadcast(
new List(
[
message,
target instanceof List ? target :
target === stage.name ? new List([stage]) :
new List([target])
]
)
);
};
// Process type inference
Process.prototype.reportIsA = function (thing, typeString) {