summaryrefslogtreecommitdiff
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
parent4c44efdc1e7a2c1bb06274b206de7a982fb03d12 (diff)
downloadsnap-byow-d267b696af1e7a429c4b31dc87b46dc638c3509f.tar.gz
snap-byow-d267b696af1e7a429c4b31dc87b46dc638c3509f.zip
Broadcast & Message enhancements, fixed #93
* When I receive <any msg> option * getLastMessage reporter + watcher
-rw-r--r--blocks.js38
-rwxr-xr-xhistory.txt1
-rw-r--r--lang-de.js6
-rw-r--r--locale.js4
-rw-r--r--objects.js37
-rw-r--r--threads.js21
6 files changed, 92 insertions, 15 deletions
diff --git a/blocks.js b/blocks.js
index dd5fed7..3e32b16 100644
--- a/blocks.js
+++ b/blocks.js
@@ -153,7 +153,7 @@ DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph*/
// Global stuff ////////////////////////////////////////////////////////
-modules.blocks = '2013-April-30';
+modules.blocks = '2013-May-14';
var SyntaxElementMorph;
var BlockMorph;
@@ -195,7 +195,7 @@ WorldMorph.prototype.customMorphs = function () {
new Color(20, 20, 20)
)
];
-
+*/
/*
var sm = new ScriptsMorph();
sm.setExtent(new Point(800, 600));
@@ -936,7 +936,7 @@ SyntaxElementMorph.prototype.labelPart = function (spec) {
part = new InputSlotMorph(
null,
false,
- 'messagesMenu',
+ 'messagesReceivedMenu',
true
);
part.isStatic = true;
@@ -5734,6 +5734,38 @@ InputSlotMorph.prototype.messagesMenu = function () {
return dict;
};
+InputSlotMorph.prototype.messagesReceivedMenu = function () {
+ var dict = {'any message': ['any message']},
+ rcvr = this.parentThatIsA(BlockMorph).receiver(),
+ stage = rcvr.parentThatIsA(StageMorph),
+ myself = this,
+ allNames = [];
+
+ stage.children.concat(stage).forEach(function (morph) {
+ if (morph instanceof SpriteMorph || morph instanceof StageMorph) {
+ allNames = allNames.concat(morph.allMessageNames());
+ }
+ });
+ allNames.forEach(function (name) {
+ dict[name] = name;
+ });
+ dict['~'] = null;
+ dict['new...'] = function () {
+
+ new DialogBoxMorph(
+ myself,
+ myself.setContents,
+ myself
+ ).prompt(
+ 'Message name',
+ null,
+ myself.world()
+ );
+ };
+
+ return dict;
+};
+
InputSlotMorph.prototype.collidablesMenu = function () {
var dict = {
'mouse-pointer' : ['mouse-pointer'],
diff --git a/history.txt b/history.txt
index e3a3934..4b47632 100755
--- a/history.txt
+++ b/history.txt
@@ -1704,3 +1704,4 @@ ______
140514
------
* paint.js: Paint editor, first version, contributed by Kartik Chandra, Yay!!
+* Threads, Objects, Blocks: Broadcast & message enhancements: When I receive <any msg>, and getLastMessage reporter + watcher
diff --git a/lang-de.js b/lang-de.js
index fc244e8..f6d4d57 100644
--- a/lang-de.js
+++ b/lang-de.js
@@ -185,7 +185,7 @@ SnapTranslator.dict.de = {
'translator_e-mail':
'jens@moenig.org', // optional
'last_changed':
- '2013-04-25', // this, too, will appear in the Translators tab
+ '2013-05-14', // this, too, will appear in the Translators tab
// GUI
// control bar:
@@ -427,6 +427,10 @@ SnapTranslator.dict.de = {
'sende %msg an alle und warte',
'Message name':
'Nachricht',
+ 'message':
+ 'Nachricht',
+ 'any message':
+ 'eine beliebige Nachricht',
'wait %n secs':
'warte %n Sek.',
'wait until %b':
diff --git a/locale.js b/locale.js
index 218b58b..3e2a9fb 100644
--- a/locale.js
+++ b/locale.js
@@ -42,7 +42,7 @@
/*global modules, contains*/
-modules.locale = '2013-April-25';
+modules.locale = '2013-May-14';
// Global stuff
@@ -149,7 +149,7 @@ SnapTranslator.dict.de = {
'translator_e-mail':
'jens@moenig.org',
'last_changed':
- '2013-04-25'
+ '2013-05-14'
};
SnapTranslator.dict.it = {
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:
diff --git a/threads.js b/threads.js
index 7068d38..2a1802c 100644
--- a/threads.js
+++ b/threads.js
@@ -83,7 +83,7 @@ ArgLabelMorph, localize*/
// Global stuff ////////////////////////////////////////////////////////
-modules.threads = '2013-April-19';
+modules.threads = '2013-May-14';
var ThreadManager;
var Process;
@@ -744,8 +744,7 @@ Process.prototype.evaluate = function (
extra,
parms = args.asArray(),
i,
- value,
- upvars;
+ value;
if (!outer.receiver) {
outer.receiver = context.receiver; // for custom blocks
@@ -815,9 +814,7 @@ Process.prototype.evaluate = function (
}
}
}
- if (upvars) {
- runnable.upvars = upvars;
- } else if (this.context.upvars) {
+ if (this.context.upvars) {
runnable.upvars = new UpvarReference(this.context.upvars);
}
@@ -1665,6 +1662,7 @@ Process.prototype.doBroadcast = function (message) {
procs = [];
if (message !== '') {
+ stage.lastMessage = message;
stage.children.concat(stage).forEach(function (morph) {
if (morph instanceof SpriteMorph || morph instanceof StageMorph) {
hats = hats.concat(morph.allHatBlocksFor(message));
@@ -1693,6 +1691,17 @@ Process.prototype.doBroadcastAndWait = function (message) {
this.pushContext();
};
+Process.prototype.getLastMessage = function () {
+ var stage;
+ if (this.homeContext.receiver) {
+ stage = this.homeContext.receiver.parentThatIsA(StageMorph);
+ if (stage) {
+ return stage.getLastMessage();
+ }
+ }
+ return '';
+};
+
// Process type inference
Process.prototype.reportIsA = function (thing, typeString) {