“new clone of ...” primitive

also made TELL, ASK primitives offiical
upd4.1
Jens Mönig 2017-07-12 09:43:35 +02:00
rodzic 10e09ec3f2
commit a0cbf2993c
3 zmienionych plików z 45 dodań i 32 usunięć

Wyświetl plik

@ -3531,6 +3531,7 @@ Fixes:
170712
------
* Blocks: fixed #1800. Thanks, Ken, for the bug report!
* Objects, Threads: “new clone of ...” primitive, made TELL, ASK primitives official

Wyświetl plik

@ -82,7 +82,7 @@ SpeechBubbleMorph, RingMorph, isNil, FileReader, TableDialogMorph,
BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize,
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph*/
modules.objects = '2017-July-11';
modules.objects = '2017-July-12';
var SpriteMorph;
var StageMorph;
@ -753,6 +753,11 @@ SpriteMorph.prototype.initBlocks = function () {
category: 'control',
spec: 'create a clone of %cln'
},
newClone: {
type: 'reporter',
category: 'control',
spec: 'a new clone of %cln'
},
removeClone: {
type: 'command',
category: 'control',
@ -1992,23 +1997,13 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push('-');
blocks.push(block('receiveOnClone'));
blocks.push(block('createClone'));
blocks.push(block('newClone'));
blocks.push(block('removeClone'));
blocks.push('-');
blocks.push(block('doPauseAll'));
// for debugging: ///////////////
if (this.world().isDevMode) {
blocks.push('-');
txt = new TextMorph(localize(
'development mode \ndebugging primitives:'
));
txt.fontSize = 9;
txt.setColor(this.paletteTextColor);
blocks.push(txt);
blocks.push('-');
blocks.push(block('doTellTo'));
blocks.push(block('reportAskFor'));
}
blocks.push('-');
blocks.push(block('doTellTo'));
blocks.push(block('reportAskFor'));
} else if (cat === 'sensing') {
@ -3221,10 +3216,21 @@ SpriteMorph.prototype.remove = function () {
*/
SpriteMorph.prototype.createClone = function (immediately) {
var stage = this.parentThatIsA(StageMorph);
var stage = this.parentThatIsA(StageMorph),
clone;
if (stage && stage.cloneCount <= 5000) {
this.fullCopy(true).clonify(stage, immediately);
clone = this.fullCopy(true);
clone.clonify(stage, immediately);
}
return clone;
};
SpriteMorph.prototype.newClone = function (immediately) {
var clone = this.createClone(immediately);
if (isNil(clone)) {
throw new Error('exceeding maximum number of clones');
}
return clone;
};
SpriteMorph.prototype.clonify = function (stage, immediately) {
@ -6904,22 +6910,12 @@ StageMorph.prototype.blockTemplates = function (category) {
blocks.push(block('reportCallCC'));
blocks.push('-');
blocks.push(block('createClone'));
blocks.push(block('newClone'));
blocks.push('-');
blocks.push(block('doPauseAll'));
// for debugging: ///////////////
if (this.world().isDevMode) {
blocks.push('-');
txt = new TextMorph(localize(
'development mode \ndebugging primitives:'
));
txt.fontSize = 9;
txt.setColor(this.paletteTextColor);
blocks.push(txt);
blocks.push('-');
blocks.push(block('doTellTo'));
blocks.push(block('reportAskFor'));
}
blocks.push('-');
blocks.push(block('doTellTo'));
blocks.push(block('reportAskFor'));
} else if (cat === 'sensing') {

Wyświetl plik

@ -61,7 +61,7 @@ StageMorph, SpriteMorph, StagePrompterMorph, Note, modules, isString, copy,
isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph,
TableFrameMorph, ColorSlotMorph, isSnapObject*/
modules.threads = '2017-July-09';
modules.threads = '2017-July-12';
var ThreadManager;
var Process;
@ -2813,6 +2813,22 @@ Process.prototype.createClone = function (name) {
}
};
Process.prototype.newClone = function (name) {
var thisObj = this.blockReceiver(),
thatObj;
if (!name) {return; }
if (thisObj) {
if (this.inputOption(name) === 'myself') {
return thisObj.newClone(!this.isFirstStep);
}
thatObj = this.getOtherObject(name, thisObj);
if (thatObj) {
return thatObj.newClone(!this.isFirstStep);
}
}
};
// Process sensing primitives
Process.prototype.reportTouchingObject = function (name) {