kopia lustrzana https://github.com/backface/turtlestitch
added attributes to the “delete” block’s drop-down menu
rodzic
39bf4cadbe
commit
c14e15f7b1
24
blocks.js
24
blocks.js
|
@ -150,7 +150,7 @@ CustomCommandBlockMorph*/
|
||||||
|
|
||||||
// Global stuff ////////////////////////////////////////////////////////
|
// Global stuff ////////////////////////////////////////////////////////
|
||||||
|
|
||||||
modules.blocks = '2017-May-05';
|
modules.blocks = '2017-May-09';
|
||||||
|
|
||||||
var SyntaxElementMorph;
|
var SyntaxElementMorph;
|
||||||
var BlockMorph;
|
var BlockMorph;
|
||||||
|
@ -2463,9 +2463,9 @@ BlockMorph.prototype.userMenu = function () {
|
||||||
if (StageMorph.prototype.enableInheritance) {
|
if (StageMorph.prototype.enableInheritance) {
|
||||||
rcvr = this.receiver();
|
rcvr = this.receiver();
|
||||||
field = {
|
field = {
|
||||||
xPosition: 'x',
|
xPosition: 'x position',
|
||||||
yPosition: 'y',
|
yPosition: 'y position',
|
||||||
direction: 'dir',
|
direction: 'direction',
|
||||||
getScale: 'size'
|
getScale: 'size'
|
||||||
}[this.selector];
|
}[this.selector];
|
||||||
if (field && rcvr && rcvr.exemplar) {
|
if (field && rcvr && rcvr.exemplar) {
|
||||||
|
@ -8249,15 +8249,27 @@ InputSlotMorph.prototype.setChoices = function (dict, readonly) {
|
||||||
|
|
||||||
InputSlotMorph.prototype.shadowedVariablesMenu = function () {
|
InputSlotMorph.prototype.shadowedVariablesMenu = function () {
|
||||||
var block = this.parentThatIsA(BlockMorph),
|
var block = this.parentThatIsA(BlockMorph),
|
||||||
|
vars,
|
||||||
|
attribs,
|
||||||
rcvr,
|
rcvr,
|
||||||
dict = {};
|
dict = {};
|
||||||
|
|
||||||
if (!block) {return dict; }
|
if (!block) {return dict; }
|
||||||
rcvr = block.receiver();
|
rcvr = block.receiver();
|
||||||
if (rcvr) {
|
if (rcvr && rcvr.exemplar) {
|
||||||
rcvr.inheritedVariableNames(true).forEach(function (name) {
|
vars = rcvr.inheritedVariableNames(true);
|
||||||
|
vars.forEach(function (name) {
|
||||||
dict[name] = name;
|
dict[name] = name;
|
||||||
});
|
});
|
||||||
|
attribs = rcvr.shadowedAttributes();
|
||||||
|
/*
|
||||||
|
if (vars.length && attribs.length) {
|
||||||
|
dict['~'] = null; // add line
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
attribs.forEach(function (name) {
|
||||||
|
dict[name] = [name];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return dict;
|
return dict;
|
||||||
};
|
};
|
||||||
|
|
|
@ -3417,6 +3417,11 @@ Fixes:
|
||||||
------
|
------
|
||||||
* attribute inheritance support for ‘x’, ‘y’, ‘dir’ and ‘size’
|
* attribute inheritance support for ‘x’, ‘y’, ‘dir’ and ‘size’
|
||||||
|
|
||||||
|
170509
|
||||||
|
------
|
||||||
|
* added tools to the library browser
|
||||||
|
* added attributes to the “delete” block’s drop-down menu
|
||||||
|
|
||||||
Features:
|
Features:
|
||||||
* polymorphic sprite-local custom blocks
|
* polymorphic sprite-local custom blocks
|
||||||
* inheritance of sprite-local custom blocks
|
* inheritance of sprite-local custom blocks
|
||||||
|
|
70
objects.js
70
objects.js
|
@ -82,7 +82,7 @@ SpeechBubbleMorph, RingMorph, isNil, FileReader, TableDialogMorph,
|
||||||
BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize,
|
BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize,
|
||||||
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph*/
|
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph*/
|
||||||
|
|
||||||
modules.objects = '2017-May-05';
|
modules.objects = '2017-May-09';
|
||||||
|
|
||||||
var SpriteMorph;
|
var SpriteMorph;
|
||||||
var StageMorph;
|
var StageMorph;
|
||||||
|
@ -116,9 +116,9 @@ SpriteMorph.uber = PenMorph.prototype;
|
||||||
|
|
||||||
SpriteMorph.prototype.attributes =
|
SpriteMorph.prototype.attributes =
|
||||||
[
|
[
|
||||||
'x',
|
'x position',
|
||||||
'y',
|
'y position',
|
||||||
'dir',
|
'direction',
|
||||||
'size'
|
'size'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -1387,7 +1387,7 @@ SpriteMorph.prototype.init = function (globals) {
|
||||||
// sprite inheritance
|
// sprite inheritance
|
||||||
this.exemplar = null;
|
this.exemplar = null;
|
||||||
this.cachedSpecimens = null; // temporary for morphic animations
|
this.cachedSpecimens = null; // temporary for morphic animations
|
||||||
this.inheritedAttributes = []; // 'x', 'y', 'dir', 'size' etc...
|
this.inheritedAttributes = []; // 'x position', 'direction', 'size' etc...
|
||||||
|
|
||||||
SpriteMorph.uber.init.call(this);
|
SpriteMorph.uber.init.call(this);
|
||||||
|
|
||||||
|
@ -1802,11 +1802,11 @@ SpriteMorph.prototype.blockTemplates = function (category) {
|
||||||
blocks.push(block('bounceOffEdge'));
|
blocks.push(block('bounceOffEdge'));
|
||||||
blocks.push('-');
|
blocks.push('-');
|
||||||
blocks.push(watcherToggle('xPosition'));
|
blocks.push(watcherToggle('xPosition'));
|
||||||
blocks.push(block('xPosition', this.inheritsAttribute('x')));
|
blocks.push(block('xPosition', this.inheritsAttribute('x position')));
|
||||||
blocks.push(watcherToggle('yPosition'));
|
blocks.push(watcherToggle('yPosition'));
|
||||||
blocks.push(block('yPosition', this.inheritsAttribute('y')));
|
blocks.push(block('yPosition', this.inheritsAttribute('y position')));
|
||||||
blocks.push(watcherToggle('direction'));
|
blocks.push(watcherToggle('direction'));
|
||||||
blocks.push(block('direction', this.inheritsAttribute('dir')));
|
blocks.push(block('direction', this.inheritsAttribute('direction')));
|
||||||
|
|
||||||
} else if (cat === 'looks') {
|
} else if (cat === 'looks') {
|
||||||
|
|
||||||
|
@ -3873,8 +3873,8 @@ SpriteMorph.prototype.positionTalkBubble = function () {
|
||||||
SpriteMorph.prototype.prepareToBeGrabbed = function (hand) {
|
SpriteMorph.prototype.prepareToBeGrabbed = function (hand) {
|
||||||
this.removeShadow();
|
this.removeShadow();
|
||||||
this.recordLayers();
|
this.recordLayers();
|
||||||
this.shadowAttribute('x');
|
this.shadowAttribute('x position');
|
||||||
this.shadowAttribute('y');
|
this.shadowAttribute('y position');
|
||||||
this.cachedSpecimens = this.specimens();
|
this.cachedSpecimens = this.specimens();
|
||||||
if (!this.bounds.containsPoint(hand.position()) &&
|
if (!this.bounds.containsPoint(hand.position()) &&
|
||||||
this.isCorrectingOutsideDrag()) {
|
this.isCorrectingOutsideDrag()) {
|
||||||
|
@ -4014,8 +4014,8 @@ SpriteMorph.prototype.moveBy = function (delta, justMe) {
|
||||||
part.moveBy(delta);
|
part.moveBy(delta);
|
||||||
});
|
});
|
||||||
this.specimens().forEach(function (instance) {
|
this.specimens().forEach(function (instance) {
|
||||||
var inheritsX = instance.inheritsAttribute('x'),
|
var inheritsX = instance.inheritsAttribute('x position'),
|
||||||
inheritsY = instance.inheritsAttribute('y');
|
inheritsY = instance.inheritsAttribute('y position');
|
||||||
if (inheritsX && inheritsY) {
|
if (inheritsX && inheritsY) {
|
||||||
instance.moveBy(delta);
|
instance.moveBy(delta);
|
||||||
} else if (inheritsX) {
|
} else if (inheritsX) {
|
||||||
|
@ -4034,8 +4034,8 @@ SpriteMorph.prototype.silentMoveBy = function (delta, justMe) {
|
||||||
part.moveBy(delta);
|
part.moveBy(delta);
|
||||||
});
|
});
|
||||||
this.specimens().forEach(function (instance) {
|
this.specimens().forEach(function (instance) {
|
||||||
var inheritsX = instance.inheritsAttribute('x'),
|
var inheritsX = instance.inheritsAttribute('x position'),
|
||||||
inheritsY = instance.inheritsAttribute('y');
|
inheritsY = instance.inheritsAttribute('y position');
|
||||||
if (inheritsX && inheritsY) {
|
if (inheritsX && inheritsY) {
|
||||||
instance.moveBy(delta);
|
instance.moveBy(delta);
|
||||||
} else if (inheritsX) {
|
} else if (inheritsX) {
|
||||||
|
@ -4129,8 +4129,8 @@ SpriteMorph.prototype.forward = function (steps) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.shadowAttribute('x');
|
this.shadowAttribute('x position');
|
||||||
this.shadowAttribute('y');
|
this.shadowAttribute('y position');
|
||||||
|
|
||||||
this.setPosition(dest);
|
this.setPosition(dest);
|
||||||
this.positionTalkBubble();
|
this.positionTalkBubble();
|
||||||
|
@ -4164,10 +4164,10 @@ SpriteMorph.prototype.setHeading = function (degrees, noShadow) {
|
||||||
|
|
||||||
// propagate to children that inherit my direction
|
// propagate to children that inherit my direction
|
||||||
if (!noShadow) {
|
if (!noShadow) {
|
||||||
this.shadowAttribute('dir');
|
this.shadowAttribute('direction');
|
||||||
}
|
}
|
||||||
this.specimens().forEach(function (instance) {
|
this.specimens().forEach(function (instance) {
|
||||||
if (instance.inheritsAttribute('dir')) {
|
if (instance.inheritsAttribute('direction')) {
|
||||||
instance.setHeading(degrees, true);
|
instance.setHeading(degrees, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -4193,7 +4193,7 @@ SpriteMorph.prototype.turnLeft = function (degrees) {
|
||||||
};
|
};
|
||||||
|
|
||||||
SpriteMorph.prototype.xPosition = function () {
|
SpriteMorph.prototype.xPosition = function () {
|
||||||
if (this.inheritsAttribute('x')) {
|
if (this.inheritsAttribute('x position')) {
|
||||||
return this.exemplar.xPosition();
|
return this.exemplar.xPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4209,7 +4209,7 @@ SpriteMorph.prototype.xPosition = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
SpriteMorph.prototype.yPosition = function () {
|
SpriteMorph.prototype.yPosition = function () {
|
||||||
if (this.inheritsAttribute('y')) {
|
if (this.inheritsAttribute('y position')) {
|
||||||
return this.exemplar.yPosition();
|
return this.exemplar.yPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4225,7 +4225,7 @@ SpriteMorph.prototype.yPosition = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
SpriteMorph.prototype.direction = function () {
|
SpriteMorph.prototype.direction = function () {
|
||||||
if (this.inheritsAttribute('dir')) {
|
if (this.inheritsAttribute('direction')) {
|
||||||
return this.exemplar.direction();
|
return this.exemplar.direction();
|
||||||
}
|
}
|
||||||
return this.heading;
|
return this.heading;
|
||||||
|
@ -4243,8 +4243,8 @@ SpriteMorph.prototype.gotoXY = function (x, y, justMe, noShadow) {
|
||||||
|
|
||||||
if (!stage) {return; }
|
if (!stage) {return; }
|
||||||
if (!noShadow) {
|
if (!noShadow) {
|
||||||
this.shadowAttribute('x');
|
this.shadowAttribute('x position');
|
||||||
this.shadowAttribute('y');
|
this.shadowAttribute('y position');
|
||||||
}
|
}
|
||||||
newX = stage.center().x + (+x || 0) * stage.scale;
|
newX = stage.center().x + (+x || 0) * stage.scale;
|
||||||
newY = stage.center().y - (+y || 0) * stage.scale;
|
newY = stage.center().y - (+y || 0) * stage.scale;
|
||||||
|
@ -4267,7 +4267,7 @@ SpriteMorph.prototype.silentGotoXY = function (x, y, justMe) {
|
||||||
};
|
};
|
||||||
|
|
||||||
SpriteMorph.prototype.setXPosition = function (num) {
|
SpriteMorph.prototype.setXPosition = function (num) {
|
||||||
this.shadowAttribute('x');
|
this.shadowAttribute('x position');
|
||||||
this.gotoXY(+num || 0, this.yPosition(), false, true);
|
this.gotoXY(+num || 0, this.yPosition(), false, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4276,7 +4276,7 @@ SpriteMorph.prototype.changeXPosition = function (delta) {
|
||||||
};
|
};
|
||||||
|
|
||||||
SpriteMorph.prototype.setYPosition = function (num) {
|
SpriteMorph.prototype.setYPosition = function (num) {
|
||||||
this.shadowAttribute('y');
|
this.shadowAttribute('y position');
|
||||||
this.gotoXY(this.xPosition(), +num || 0, false, true);
|
this.gotoXY(this.xPosition(), +num || 0, false, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4326,9 +4326,9 @@ SpriteMorph.prototype.bounceOffEdge = function () {
|
||||||
dirY = Math.abs(dirY);
|
dirY = Math.abs(dirY);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.shadowAttribute('x');
|
this.shadowAttribute('x position');
|
||||||
this.shadowAttribute('y');
|
this.shadowAttribute('y position');
|
||||||
this.shadowAttribute('dir');
|
this.shadowAttribute('direction');
|
||||||
|
|
||||||
this.setHeading(degrees(Math.atan2(-dirY, dirX)) + 90);
|
this.setHeading(degrees(Math.atan2(-dirY, dirX)) + 90);
|
||||||
this.setPosition(this.position().add(
|
this.setPosition(this.position().add(
|
||||||
|
@ -5140,6 +5140,14 @@ SpriteMorph.prototype.inheritsAttribute = function (aName) {
|
||||||
return !isNil(this.exemplar) && contains(this.inheritedAttributes, aName);
|
return !isNil(this.exemplar) && contains(this.inheritedAttributes, aName);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SpriteMorph.prototype.shadowedAttributes = function () {
|
||||||
|
// answer an array of attribute names that can be deleted/shared
|
||||||
|
var inherited = this.inheritedAttributes;
|
||||||
|
return this.attributes.filter(function (each) {
|
||||||
|
return !contains(inherited, each);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
SpriteMorph.prototype.shadowAttribute = function (aName) {
|
SpriteMorph.prototype.shadowAttribute = function (aName) {
|
||||||
var ide;
|
var ide;
|
||||||
if (!this.inheritsAttribute(aName)) {
|
if (!this.inheritsAttribute(aName)) {
|
||||||
|
@ -5172,11 +5180,11 @@ SpriteMorph.prototype.inheritAttribute = function (aName) {
|
||||||
|
|
||||||
SpriteMorph.prototype.refreshInheritedAttribute = function (aName) {
|
SpriteMorph.prototype.refreshInheritedAttribute = function (aName) {
|
||||||
switch (aName) {
|
switch (aName) {
|
||||||
case 'x':
|
case 'x position':
|
||||||
case 'y':
|
case 'y position':
|
||||||
this.gotoXY(this.xPosition(), this.yPosition(), false, true);
|
this.gotoXY(this.xPosition(), this.yPosition(), false, true);
|
||||||
break;
|
break;
|
||||||
case 'dir':
|
case 'direction':
|
||||||
this.setHeading(this.direction(), true);
|
this.setHeading(this.direction(), true);
|
||||||
break;
|
break;
|
||||||
case 'size':
|
case 'size':
|
||||||
|
|
13
threads.js
13
threads.js
|
@ -61,7 +61,7 @@ StageMorph, SpriteMorph, StagePrompterMorph, Note, modules, isString, copy,
|
||||||
isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph,
|
isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph,
|
||||||
TableFrameMorph, ColorSlotMorph, isSnapObject*/
|
TableFrameMorph, ColorSlotMorph, isSnapObject*/
|
||||||
|
|
||||||
modules.threads = '2017-April-10';
|
modules.threads = '2017-May-09';
|
||||||
|
|
||||||
var ThreadManager;
|
var ThreadManager;
|
||||||
var Process;
|
var Process;
|
||||||
|
@ -1544,15 +1544,15 @@ Process.prototype.doRemoveTemporaries = function () {
|
||||||
Process.prototype.doDeleteAttr = function (attrName) {
|
Process.prototype.doDeleteAttr = function (attrName) {
|
||||||
var name = attrName,
|
var name = attrName,
|
||||||
rcvr = this.blockReceiver();
|
rcvr = this.blockReceiver();
|
||||||
|
|
||||||
if (name instanceof Context) {
|
if (name instanceof Context) {
|
||||||
if (name.expression.selector === 'reportGetVar') {
|
if (name.expression.selector === 'reportGetVar') {
|
||||||
name = name.expression.blockSpec;
|
name = name.expression.blockSpec;
|
||||||
} else { // attribute
|
} else { // attribute
|
||||||
name = {
|
name = {
|
||||||
xPosition: 'x',
|
xPosition: 'x position',
|
||||||
yPosition: 'y',
|
yPosition: 'y position',
|
||||||
direction: 'dir'
|
direction: 'direction',
|
||||||
|
size: 'size'
|
||||||
}[name.expression.selector];
|
}[name.expression.selector];
|
||||||
if (!isNil(name)) {
|
if (!isNil(name)) {
|
||||||
rcvr.inheritAttribute(name);
|
rcvr.inheritAttribute(name);
|
||||||
|
@ -1560,6 +1560,9 @@ Process.prototype.doDeleteAttr = function (attrName) {
|
||||||
return; // +++ error: cannot delete attribute...
|
return; // +++ error: cannot delete attribute...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (name instanceof Array) {
|
||||||
|
return rcvr.inheritAttribute(this.inputOption(name));
|
||||||
|
}
|
||||||
if (contains(rcvr.inheritedVariableNames(true), name)) {
|
if (contains(rcvr.inheritedVariableNames(true), name)) {
|
||||||
rcvr.deleteVariable(name);
|
rcvr.deleteVariable(name);
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue