summaryrefslogtreecommitdiff
path: root/objects.js
diff options
context:
space:
mode:
authorjmoenig <jens@moenig.org>2013-05-14 16:16:21 +0200
committerjmoenig <jens@moenig.org>2013-05-14 16:16:21 +0200
commitd267b696af1e7a429c4b31dc87b46dc638c3509f (patch)
tree55ea3f81aa2f60b552ad0a649e58fc2d43debbc9 /objects.js
parent4c44efdc1e7a2c1bb06274b206de7a982fb03d12 (diff)
downloadsnap-d267b696af1e7a429c4b31dc87b46dc638c3509f.tar.gz
snap-d267b696af1e7a429c4b31dc87b46dc638c3509f.zip
Broadcast & Message enhancements, fixed #93
* When I receive <any msg> option * getLastMessage reporter + watcher
Diffstat (limited to 'objects.js')
-rw-r--r--objects.js37
1 files changed, 34 insertions, 3 deletions
diff --git a/objects.js b/objects.js
index 5b03f2d..086b1f6 100644
--- a/objects.js
+++ b/objects.js
@@ -532,6 +532,11 @@ SpriteMorph.prototype.initBlocks = function () {
category: 'control',
spec: 'broadcast %msg and wait'
},
+ getLastMessage: {
+ type: 'reporter',
+ category: 'control',
+ spec: 'message'
+ },
doWait: {
type: 'command',
category: 'control',
@@ -1539,6 +1544,8 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push('-');
blocks.push(block('doBroadcast'));
blocks.push(block('doBroadcastAndWait'));
+ blocks.push(watcherToggle('getLastMessage'));
+ blocks.push(block('getLastMessage'));
blocks.push('-');
blocks.push(block('doWarp'));
blocks.push('-');
@@ -2719,7 +2726,7 @@ SpriteMorph.prototype.allMessageNames = function () {
morph.selector
)) {
txt = morph.inputs()[0].evaluate();
- if (txt !== '') {
+ if (isString(txt) && txt !== '') {
if (!contains(msgs, txt)) {
msgs.push(txt);
}
@@ -2732,9 +2739,11 @@ SpriteMorph.prototype.allMessageNames = function () {
SpriteMorph.prototype.allHatBlocksFor = function (message) {
return this.scripts.children.filter(function (morph) {
+ var event;
if (morph.selector) {
if (morph.selector === 'receiveMessage') {
- return morph.inputs()[0].evaluate() === message;
+ event = morph.inputs()[0].evaluate();
+ return event === message || (event instanceof Array);
}
if (morph.selector === 'receiveGo') {
return message === '__shout__go__';
@@ -2794,6 +2803,16 @@ SpriteMorph.prototype.getTempo = function () {
return 0;
};
+// SpriteMorph last message
+
+SpriteMorph.prototype.getLastMessage = function () {
+ var stage = this.parentThatIsA(StageMorph);
+ if (stage) {
+ return stage.getLastMessage();
+ }
+ return '';
+};
+
// SpriteMorph user prompting
SpriteMorph.prototype.getLastAnswer = function () {
@@ -3189,6 +3208,7 @@ StageMorph.prototype.init = function (globals) {
this.timerStart = Date.now();
this.tempo = 60; // bpm
+ this.lastMessage = '';
this.watcherUpdateFrequency = 2;
this.lastWatcherUpdate = Date.now();
@@ -3436,6 +3456,12 @@ StageMorph.prototype.getTempo = function () {
return +this.tempo;
};
+// StageMorph messages
+
+StageMorph.prototype.getLastMessage = function () {
+ return this.lastMessage || '';
+};
+
// StageMorph drag & drop
StageMorph.prototype.wantsDropOf = function (aMorph) {
@@ -3767,6 +3793,8 @@ StageMorph.prototype.blockTemplates = function (category) {
blocks.push('-');
blocks.push(block('doBroadcast'));
blocks.push(block('doBroadcastAndWait'));
+ blocks.push(watcherToggle('getLastMessage'));
+ blocks.push(block('getLastMessage'));
blocks.push('-');
blocks.push(block('doWarp'));
blocks.push('-');
@@ -5417,7 +5445,10 @@ WatcherMorph.prototype.object = function () {
};
WatcherMorph.prototype.isGlobal = function (selector) {
- return contains(['getTimer', 'getLastAnswer', 'getTempo'], selector);
+ return contains(
+ ['getTimer', 'getLastAnswer', 'getTempo', 'getLastMessage'],
+ selector
+ );
};
// WatcherMorph slider accessing: