kopia lustrzana https://github.com/backface/turtlestitch
Broadcast & Message enhancements, fixed #93
* When I receive <any msg> option * getLastMessage reporter + watcherpull/3/merge
rodzic
4c44efdc1e
commit
d267b696af
38
blocks.js
38
blocks.js
|
@ -153,7 +153,7 @@ DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph*/
|
||||||
|
|
||||||
// Global stuff ////////////////////////////////////////////////////////
|
// Global stuff ////////////////////////////////////////////////////////
|
||||||
|
|
||||||
modules.blocks = '2013-April-30';
|
modules.blocks = '2013-May-14';
|
||||||
|
|
||||||
var SyntaxElementMorph;
|
var SyntaxElementMorph;
|
||||||
var BlockMorph;
|
var BlockMorph;
|
||||||
|
@ -195,7 +195,7 @@ WorldMorph.prototype.customMorphs = function () {
|
||||||
new Color(20, 20, 20)
|
new Color(20, 20, 20)
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
|
*/
|
||||||
/*
|
/*
|
||||||
var sm = new ScriptsMorph();
|
var sm = new ScriptsMorph();
|
||||||
sm.setExtent(new Point(800, 600));
|
sm.setExtent(new Point(800, 600));
|
||||||
|
@ -936,7 +936,7 @@ SyntaxElementMorph.prototype.labelPart = function (spec) {
|
||||||
part = new InputSlotMorph(
|
part = new InputSlotMorph(
|
||||||
null,
|
null,
|
||||||
false,
|
false,
|
||||||
'messagesMenu',
|
'messagesReceivedMenu',
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
part.isStatic = true;
|
part.isStatic = true;
|
||||||
|
@ -5734,6 +5734,38 @@ InputSlotMorph.prototype.messagesMenu = function () {
|
||||||
return dict;
|
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 () {
|
InputSlotMorph.prototype.collidablesMenu = function () {
|
||||||
var dict = {
|
var dict = {
|
||||||
'mouse-pointer' : ['mouse-pointer'],
|
'mouse-pointer' : ['mouse-pointer'],
|
||||||
|
|
|
@ -1704,3 +1704,4 @@ ______
|
||||||
140514
|
140514
|
||||||
------
|
------
|
||||||
* paint.js: Paint editor, first version, contributed by Kartik Chandra, Yay!!
|
* 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':
|
'translator_e-mail':
|
||||||
'jens@moenig.org', // optional
|
'jens@moenig.org', // optional
|
||||||
'last_changed':
|
'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
|
// GUI
|
||||||
// control bar:
|
// control bar:
|
||||||
|
@ -427,6 +427,10 @@ SnapTranslator.dict.de = {
|
||||||
'sende %msg an alle und warte',
|
'sende %msg an alle und warte',
|
||||||
'Message name':
|
'Message name':
|
||||||
'Nachricht',
|
'Nachricht',
|
||||||
|
'message':
|
||||||
|
'Nachricht',
|
||||||
|
'any message':
|
||||||
|
'eine beliebige Nachricht',
|
||||||
'wait %n secs':
|
'wait %n secs':
|
||||||
'warte %n Sek.',
|
'warte %n Sek.',
|
||||||
'wait until %b':
|
'wait until %b':
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
|
|
||||||
/*global modules, contains*/
|
/*global modules, contains*/
|
||||||
|
|
||||||
modules.locale = '2013-April-25';
|
modules.locale = '2013-May-14';
|
||||||
|
|
||||||
// Global stuff
|
// Global stuff
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ SnapTranslator.dict.de = {
|
||||||
'translator_e-mail':
|
'translator_e-mail':
|
||||||
'jens@moenig.org',
|
'jens@moenig.org',
|
||||||
'last_changed':
|
'last_changed':
|
||||||
'2013-04-25'
|
'2013-05-14'
|
||||||
};
|
};
|
||||||
|
|
||||||
SnapTranslator.dict.it = {
|
SnapTranslator.dict.it = {
|
||||||
|
|
37
objects.js
37
objects.js
|
@ -532,6 +532,11 @@ SpriteMorph.prototype.initBlocks = function () {
|
||||||
category: 'control',
|
category: 'control',
|
||||||
spec: 'broadcast %msg and wait'
|
spec: 'broadcast %msg and wait'
|
||||||
},
|
},
|
||||||
|
getLastMessage: {
|
||||||
|
type: 'reporter',
|
||||||
|
category: 'control',
|
||||||
|
spec: 'message'
|
||||||
|
},
|
||||||
doWait: {
|
doWait: {
|
||||||
type: 'command',
|
type: 'command',
|
||||||
category: 'control',
|
category: 'control',
|
||||||
|
@ -1539,6 +1544,8 @@ SpriteMorph.prototype.blockTemplates = function (category) {
|
||||||
blocks.push('-');
|
blocks.push('-');
|
||||||
blocks.push(block('doBroadcast'));
|
blocks.push(block('doBroadcast'));
|
||||||
blocks.push(block('doBroadcastAndWait'));
|
blocks.push(block('doBroadcastAndWait'));
|
||||||
|
blocks.push(watcherToggle('getLastMessage'));
|
||||||
|
blocks.push(block('getLastMessage'));
|
||||||
blocks.push('-');
|
blocks.push('-');
|
||||||
blocks.push(block('doWarp'));
|
blocks.push(block('doWarp'));
|
||||||
blocks.push('-');
|
blocks.push('-');
|
||||||
|
@ -2719,7 +2726,7 @@ SpriteMorph.prototype.allMessageNames = function () {
|
||||||
morph.selector
|
morph.selector
|
||||||
)) {
|
)) {
|
||||||
txt = morph.inputs()[0].evaluate();
|
txt = morph.inputs()[0].evaluate();
|
||||||
if (txt !== '') {
|
if (isString(txt) && txt !== '') {
|
||||||
if (!contains(msgs, txt)) {
|
if (!contains(msgs, txt)) {
|
||||||
msgs.push(txt);
|
msgs.push(txt);
|
||||||
}
|
}
|
||||||
|
@ -2732,9 +2739,11 @@ SpriteMorph.prototype.allMessageNames = function () {
|
||||||
|
|
||||||
SpriteMorph.prototype.allHatBlocksFor = function (message) {
|
SpriteMorph.prototype.allHatBlocksFor = function (message) {
|
||||||
return this.scripts.children.filter(function (morph) {
|
return this.scripts.children.filter(function (morph) {
|
||||||
|
var event;
|
||||||
if (morph.selector) {
|
if (morph.selector) {
|
||||||
if (morph.selector === 'receiveMessage') {
|
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') {
|
if (morph.selector === 'receiveGo') {
|
||||||
return message === '__shout__go__';
|
return message === '__shout__go__';
|
||||||
|
@ -2794,6 +2803,16 @@ SpriteMorph.prototype.getTempo = function () {
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// SpriteMorph last message
|
||||||
|
|
||||||
|
SpriteMorph.prototype.getLastMessage = function () {
|
||||||
|
var stage = this.parentThatIsA(StageMorph);
|
||||||
|
if (stage) {
|
||||||
|
return stage.getLastMessage();
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
};
|
||||||
|
|
||||||
// SpriteMorph user prompting
|
// SpriteMorph user prompting
|
||||||
|
|
||||||
SpriteMorph.prototype.getLastAnswer = function () {
|
SpriteMorph.prototype.getLastAnswer = function () {
|
||||||
|
@ -3189,6 +3208,7 @@ StageMorph.prototype.init = function (globals) {
|
||||||
|
|
||||||
this.timerStart = Date.now();
|
this.timerStart = Date.now();
|
||||||
this.tempo = 60; // bpm
|
this.tempo = 60; // bpm
|
||||||
|
this.lastMessage = '';
|
||||||
|
|
||||||
this.watcherUpdateFrequency = 2;
|
this.watcherUpdateFrequency = 2;
|
||||||
this.lastWatcherUpdate = Date.now();
|
this.lastWatcherUpdate = Date.now();
|
||||||
|
@ -3436,6 +3456,12 @@ StageMorph.prototype.getTempo = function () {
|
||||||
return +this.tempo;
|
return +this.tempo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// StageMorph messages
|
||||||
|
|
||||||
|
StageMorph.prototype.getLastMessage = function () {
|
||||||
|
return this.lastMessage || '';
|
||||||
|
};
|
||||||
|
|
||||||
// StageMorph drag & drop
|
// StageMorph drag & drop
|
||||||
|
|
||||||
StageMorph.prototype.wantsDropOf = function (aMorph) {
|
StageMorph.prototype.wantsDropOf = function (aMorph) {
|
||||||
|
@ -3767,6 +3793,8 @@ StageMorph.prototype.blockTemplates = function (category) {
|
||||||
blocks.push('-');
|
blocks.push('-');
|
||||||
blocks.push(block('doBroadcast'));
|
blocks.push(block('doBroadcast'));
|
||||||
blocks.push(block('doBroadcastAndWait'));
|
blocks.push(block('doBroadcastAndWait'));
|
||||||
|
blocks.push(watcherToggle('getLastMessage'));
|
||||||
|
blocks.push(block('getLastMessage'));
|
||||||
blocks.push('-');
|
blocks.push('-');
|
||||||
blocks.push(block('doWarp'));
|
blocks.push(block('doWarp'));
|
||||||
blocks.push('-');
|
blocks.push('-');
|
||||||
|
@ -5417,7 +5445,10 @@ WatcherMorph.prototype.object = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
WatcherMorph.prototype.isGlobal = function (selector) {
|
WatcherMorph.prototype.isGlobal = function (selector) {
|
||||||
return contains(['getTimer', 'getLastAnswer', 'getTempo'], selector);
|
return contains(
|
||||||
|
['getTimer', 'getLastAnswer', 'getTempo', 'getLastMessage'],
|
||||||
|
selector
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// WatcherMorph slider accessing:
|
// WatcherMorph slider accessing:
|
||||||
|
|
21
threads.js
21
threads.js
|
@ -83,7 +83,7 @@ ArgLabelMorph, localize*/
|
||||||
|
|
||||||
// Global stuff ////////////////////////////////////////////////////////
|
// Global stuff ////////////////////////////////////////////////////////
|
||||||
|
|
||||||
modules.threads = '2013-April-19';
|
modules.threads = '2013-May-14';
|
||||||
|
|
||||||
var ThreadManager;
|
var ThreadManager;
|
||||||
var Process;
|
var Process;
|
||||||
|
@ -744,8 +744,7 @@ Process.prototype.evaluate = function (
|
||||||
extra,
|
extra,
|
||||||
parms = args.asArray(),
|
parms = args.asArray(),
|
||||||
i,
|
i,
|
||||||
value,
|
value;
|
||||||
upvars;
|
|
||||||
|
|
||||||
if (!outer.receiver) {
|
if (!outer.receiver) {
|
||||||
outer.receiver = context.receiver; // for custom blocks
|
outer.receiver = context.receiver; // for custom blocks
|
||||||
|
@ -815,9 +814,7 @@ Process.prototype.evaluate = function (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (upvars) {
|
if (this.context.upvars) {
|
||||||
runnable.upvars = upvars;
|
|
||||||
} else if (this.context.upvars) {
|
|
||||||
runnable.upvars = new UpvarReference(this.context.upvars);
|
runnable.upvars = new UpvarReference(this.context.upvars);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1665,6 +1662,7 @@ Process.prototype.doBroadcast = function (message) {
|
||||||
procs = [];
|
procs = [];
|
||||||
|
|
||||||
if (message !== '') {
|
if (message !== '') {
|
||||||
|
stage.lastMessage = message;
|
||||||
stage.children.concat(stage).forEach(function (morph) {
|
stage.children.concat(stage).forEach(function (morph) {
|
||||||
if (morph instanceof SpriteMorph || morph instanceof StageMorph) {
|
if (morph instanceof SpriteMorph || morph instanceof StageMorph) {
|
||||||
hats = hats.concat(morph.allHatBlocksFor(message));
|
hats = hats.concat(morph.allHatBlocksFor(message));
|
||||||
|
@ -1693,6 +1691,17 @@ Process.prototype.doBroadcastAndWait = function (message) {
|
||||||
this.pushContext();
|
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 type inference
|
||||||
|
|
||||||
Process.prototype.reportIsA = function (thing, typeString) {
|
Process.prototype.reportIsA = function (thing, typeString) {
|
||||||
|
|
Ładowanie…
Reference in New Issue