added inheritance support for ‘costume #’

upd4.1
Jens Mönig 2017-05-12 16:40:29 +02:00
rodzic 1a872934de
commit abd7ad6a37
3 zmienionych plików z 36 dodań i 8 usunięć

Wyświetl plik

@ -2466,7 +2466,8 @@ BlockMorph.prototype.userMenu = function () {
xPosition: 'x position', xPosition: 'x position',
yPosition: 'y position', yPosition: 'y position',
direction: 'direction', direction: 'direction',
getScale: 'size' getScale: 'size',
getCostumeIdx: 'costume #'
}[this.selector]; }[this.selector];
if (field && rcvr && rcvr.exemplar) { if (field && rcvr && rcvr.exemplar) {
menu.addLine(); menu.addLine();

Wyświetl plik

@ -3424,7 +3424,9 @@ Fixes:
170512 170512
------ ------
* added inheritance support for the wardrobe * exposed costumes as an attribute
* added inheritance support for the wardrobe (costumes)
* added inheritance support for costume #
Features: Features:

Wyświetl plik

@ -120,7 +120,8 @@ SpriteMorph.prototype.attributes =
'y position', 'y position',
'direction', 'direction',
'size', 'size',
'costumes' 'costumes',
'costume #'
]; ];
SpriteMorph.prototype.categories = SpriteMorph.prototype.categories =
@ -1814,7 +1815,7 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push(block('doSwitchToCostume')); blocks.push(block('doSwitchToCostume'));
blocks.push(block('doWearNextCostume')); blocks.push(block('doWearNextCostume'));
blocks.push(watcherToggle('getCostumeIdx')); blocks.push(watcherToggle('getCostumeIdx'));
blocks.push(block('getCostumeIdx')); blocks.push(block('getCostumeIdx', this.inheritsAttribute('costume #')));
blocks.push('-'); blocks.push('-');
blocks.push(block('doSayFor')); blocks.push(block('doSayFor'));
blocks.push(block('bubble')); blocks.push(block('bubble'));
@ -2906,9 +2907,10 @@ SpriteMorph.prototype.addCostume = function (costume) {
this.costumes.add(costume); this.costumes.add(costume);
}; };
SpriteMorph.prototype.wearCostume = function (costume) { SpriteMorph.prototype.wearCostume = function (costume, noShadow) {
var x = this.xPosition ? this.xPosition() : null, var x = this.xPosition ? this.xPosition() : null,
y = this.yPosition ? this.yPosition() : null, y = this.yPosition ? this.yPosition() : null,
idx = isNil(costume) ? null : this.costumes.asArray().indexOf(costume),
isWarped = this.isWarped; isWarped = this.isWarped;
if (isWarped) { if (isWarped) {
this.endWarp(); this.endWarp();
@ -2927,9 +2929,29 @@ SpriteMorph.prototype.wearCostume = function (costume) {
this.positionTalkBubble(); this.positionTalkBubble();
} }
this.version = Date.now(); this.version = Date.now();
// propagate to children that inherit my costume #
if (!noShadow) {
this.shadowAttribute('costume #');
}
this.specimens().forEach(function (instance) {
if (instance.inheritsAttribute('costume #')) {
if (idx === null) {
instance.wearCostume(null, true);
} else if (idx === -1) {
instance.wearCostume(costume, true);
} else {
instance.doSwitchToCostume(idx + 1, true);
}
}
});
}; };
SpriteMorph.prototype.getCostumeIdx = function () { SpriteMorph.prototype.getCostumeIdx = function () {
if (this.inheritsAttribute('costume #')) {
return this.exemplar.getCostumeIdx();
}
return this.costumes.asArray().indexOf(this.costume) + 1; return this.costumes.asArray().indexOf(this.costume) + 1;
}; };
@ -2963,9 +2985,9 @@ SpriteMorph.prototype.doWearPreviousCostume = function () {
} }
}; };
SpriteMorph.prototype.doSwitchToCostume = function (id) { SpriteMorph.prototype.doSwitchToCostume = function (id, noShadow) {
if (id instanceof Costume) { // allow first-class costumes if (id instanceof Costume) { // allow first-class costumes
this.wearCostume(id); this.wearCostume(id, noShadow);
return; return;
} }
@ -2996,7 +3018,7 @@ SpriteMorph.prototype.doSwitchToCostume = function (id) {
} }
} }
} }
this.wearCostume(costume); this.wearCostume(costume, noShadow);
}; };
SpriteMorph.prototype.reportCostumes = function () { SpriteMorph.prototype.reportCostumes = function () {
@ -5207,6 +5229,9 @@ SpriteMorph.prototype.refreshInheritedAttribute = function (aName) {
case 'size': case 'size':
this.setScale(this.getScale(), true); this.setScale(this.getScale(), true);
break; break;
case 'costume #':
this.doSwitchToCostume(this.getCostumeIdx(), true);
break;
default: default:
nop(); nop();
} }