new experimental "When I receive message" hat block

featuring an upvar for the transmission, hidden in dev mode
snap7
jmoenig 2021-09-28 18:57:22 +02:00
rodzic 1ba8716f32
commit 0e4a9280b5
5 zmienionych plików z 78 dodań i 21 usunięć

Wyświetl plik

@ -10,6 +10,7 @@
* user defined custom block palettes
* PWA, thanks, Joan and John, for pioneering this at Robolot and in Mircoblocks!
* new "blocksZoom=n" url parameter, thanks, Bernat!
* new "When I receive message" hat block featuring an upvar for the transmission, experimental in dev mode
* **Notable Changes:**
* saved projects remember the last edited sprite
* libraries no longer rely on the JSF primitive, project may need to re-import their libraries to run without having to enable JS extensions
@ -32,6 +33,9 @@
* German
* Chinese, thanks, Simon!
### 2021-09-28
* objects, blocks, threads: new "When I receive message" hat block featuring an upvar for the transmission, experimental in dev mode
### 2021-09-27
* objects: renamed scene event hat block
* German translation update

Wyświetl plik

@ -16,9 +16,9 @@
<script src="src/morphic.js?version=2021-07-09"></script>
<script src="src/symbols.js?version=2021-03-03"></script>
<script src="src/widgets.js?version=2021-07-21"></script>
<script src="src/blocks.js?version=2021-09-08"></script>
<script src="src/threads.js?version=2021-09-08"></script>
<script src="src/objects.js?version=2021-09-27"></script>
<script src="src/blocks.js?version=2021-09-28"></script>
<script src="src/threads.js?version=2021-09-28"></script>
<script src="src/objects.js?version=2021-09-28"></script>
<script src="src/scenes.js?version=2021-07-21"></script>
<script src="src/gui.js?version=2021-09-07"></script>
<script src="src/paint.js?version=2021-07-05"></script>

Wyświetl plik

@ -160,7 +160,7 @@ CustomCommandBlockMorph, ToggleButtonMorph, DialMorph, SnapExtensions*/
// Global stuff ////////////////////////////////////////////////////////
modules.blocks = '2021-September-08';
modules.blocks = '2021-September-28';
var SyntaxElementMorph;
var BlockMorph;
@ -959,6 +959,10 @@ SyntaxElementMorph.prototype.labelParts = {
type: 'template',
label: 'a'
},
'%transmission': { // experimental v7
type: 'template',
label: 'message'
},
'%upvar': {
type: 'template',
label: '\u2191' // up-arrow
@ -1629,7 +1633,7 @@ SyntaxElementMorph.prototype.labelPart = function (spec) {
}
break;
case 'template':
part = new TemplateSlotMorph(info.label);
part = new TemplateSlotMorph(localize(info.label));
break;
case 'color':
part = new ColorSlotMorph();

Wyświetl plik

@ -86,7 +86,7 @@ AlignmentMorph, Process, WorldMap, copyCanvas, useBlurredShadows*/
/*jshint esversion: 6*/
modules.objects = '2021-September-27';
modules.objects = '2021-September-28';
var SpriteMorph;
var StageMorph;
@ -743,6 +743,12 @@ SpriteMorph.prototype.initBlocks = function () {
category: 'control',
spec: 'when I receive %msgHat'
},
receiveTransmission: { // experimental v7
dev: true,
type: 'hat',
category: 'control',
spec: 'when I receive %transmission'
},
receiveCondition: {
type: 'hat',
category: 'control',
@ -2557,6 +2563,14 @@ SpriteMorph.prototype.blockTemplates = function (category = 'motion') {
blocks.push('-');
blocks.push(block('doPauseAll'));
// for debugging: ///////////////
if (devMode) {
blocks.push('-');
blocks.push(this.devModeText());
blocks.push('-');
blocks.push(block('receiveTransmission'));
}
} else if (category === 'sensing') {
blocks.push(block('reportTouchingObject'));
@ -6083,22 +6097,29 @@ SpriteMorph.prototype.allSendersOf = function (message, receiverName, known) {
SpriteMorph.prototype.allHatBlocksFor = function (message) {
if (typeof message === 'number') { message = message.toString(); }
return this.scripts.children.filter(morph => {
var event;
if (morph.selector) {
if (morph.selector === 'receiveMessage') {
var sel = morph.selector,
event;
if (sel) {
if (sel === 'receiveMessage') {
event = morph.inputs()[0].evaluate();
return event === message
|| (event instanceof Array
&& message !== '__shout__go__'
&& message !== '__clone__init__');
&& message !== '__clone__init__'
&& message !== '__scene__init__');
}
if (morph.selector === 'receiveGo') {
if (sel === 'receiveTransmission') {
return message !== '__shout__go__'
&& message !== '__clone__init__'
&& message !== '__scene__init__';
}
if (sel === 'receiveGo') {
return message === '__shout__go__';
}
if (morph.selector === 'receiveOnClone') {
if (sel === 'receiveOnClone') {
return message === '__clone__init__';
}
if (morph.selector === 'receiveOnScene') {
if (sel === 'receiveOnScene') {
return message === '__scene__init__';
}
}
@ -8725,11 +8746,11 @@ StageMorph.prototype.blockTemplates = function (category = 'motion') {
blocks.push(block('receiveCondition'));
blocks.push('-');
blocks.push(block('receiveMessage'));
blocks.push(watcherToggle('getLastMessage'));
blocks.push(block('getLastMessage'));
blocks.push(block('doBroadcast'));
blocks.push(block('doBroadcastAndWait'));
blocks.push(block('doSend'));
blocks.push(watcherToggle('getLastMessage'));
blocks.push(block('getLastMessage'));
blocks.push('-');
blocks.push(block('doWarp'));
blocks.push('-');
@ -8766,6 +8787,14 @@ StageMorph.prototype.blockTemplates = function (category = 'motion') {
blocks.push('-');
blocks.push(block('doPauseAll'));
// for debugging: ///////////////
if (this.world().isDevMode) {
blocks.push('-');
blocks.push(this.devModeText());
blocks.push('-');
blocks.push(block('receiveTransmission'));
}
} else if (category === 'sensing') {
blocks.push(block('doAsk'));

Wyświetl plik

@ -64,7 +64,7 @@ SnapExtensions, AlignmentMorph, TextMorph, Cloud*/
/*jshint esversion: 6*/
modules.threads = '2021-September-08';
modules.threads = '2021-September-28';
var ThreadManager;
var Process;
@ -3729,13 +3729,33 @@ Process.prototype.doBroadcast = function (message) {
if (msg !== '') {
stage.lastMessage = message; // the actual data structure
rcvrs.forEach(morph => {
var varFrame;
if (isSnapObject(morph)) {
morph.allHatBlocksFor(msg).forEach(block => {
procs.push(stage.threads.startProcess(
block,
morph,
stage.isThreadSafe
));
if (block.selector === 'receiveTransmission') {
varFrame = new VariableFrame();
varFrame.addVar(
block.inputs()[0].evaluate(),
message
);
procs.push(stage.threads.startProcess(
block,
morph,
stage.isThreadSafe,
null, // exportResult (bool)
null, // callback
null, // isClicked
null, // rightAway
null, // atomic
varFrame
));
} else {
procs.push(stage.threads.startProcess(
block,
morph,
stage.isThreadSafe
));
}
});
}
});