diff options
| author | jmoenig <jens@moenig.org> | 2013-05-14 16:16:21 +0200 |
|---|---|---|
| committer | jmoenig <jens@moenig.org> | 2013-05-14 16:16:21 +0200 |
| commit | d267b696af1e7a429c4b31dc87b46dc638c3509f (patch) | |
| tree | 55ea3f81aa2f60b552ad0a649e58fc2d43debbc9 | |
| parent | 4c44efdc1e7a2c1bb06274b206de7a982fb03d12 (diff) | |
| download | snap-d267b696af1e7a429c4b31dc87b46dc638c3509f.tar.gz snap-d267b696af1e7a429c4b31dc87b46dc638c3509f.zip | |
Broadcast & Message enhancements, fixed #93
* When I receive <any msg> option
* getLastMessage reporter + watcher
| -rw-r--r-- | blocks.js | 38 | ||||
| -rwxr-xr-x | history.txt | 1 | ||||
| -rw-r--r-- | lang-de.js | 6 | ||||
| -rw-r--r-- | locale.js | 4 | ||||
| -rw-r--r-- | objects.js | 37 | ||||
| -rw-r--r-- | threads.js | 21 |
6 files changed, 92 insertions, 15 deletions
@@ -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 @@ -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': @@ -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 = { @@ -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: @@ -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) { |
