added inheritance support for scripts

partly done, copy-on-write is still missing
upd4.1
Jens Mönig 2017-05-31 16:08:30 +02:00
rodzic eea1d08c82
commit 7ec3e16c4f
5 zmienionych plików z 65 dodań i 10 usunięć

Wyświetl plik

@ -145,12 +145,12 @@ radians, useBlurredShadows, SpeechBubbleMorph, modules, StageMorph,
fontHeight, TableFrameMorph, SpriteMorph, Context, ListWatcherMorph,
CellMorph, DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph,
Costume, IDE_Morph, BlockDialogMorph, BlockEditorMorph, localize, isNil,
isSnapObject, copy, PushButtonMorph, SpriteIconMorph, Process, AlignmentMorph,
isSnapObject, PushButtonMorph, SpriteIconMorph, Process, AlignmentMorph,
CustomCommandBlockMorph*/
// Global stuff ////////////////////////////////////////////////////////
modules.blocks = '2017-May-30';
modules.blocks = '2017-May-31';
var SyntaxElementMorph;
var BlockMorph;
@ -6141,6 +6141,24 @@ ScriptsMorph.prototype.userMenu = function () {
);
if (ide) {
menu.addLine();
if (obj.exemplar) {
if (obj.inheritsAttribute('scripts')) {
menu.addItem(
'disinherit scripts',
function () {
obj.shadowAttribute('scripts');
}
);
} else {
menu.addItem(
'inherit scripts\nfrom' + ' ' + obj.exemplar.name,
function () {
obj.inheritAttribute('scripts');
}
);
menu.addLine();
}
}
menu.addItem(
'make a block...',
function () {

2
gui.js
Wyświetl plik

@ -74,7 +74,7 @@ isRetinaSupported, SliderMorph, Animation*/
// Global stuff ////////////////////////////////////////////////////////
modules.gui = '2017-May-30';
modules.gui = '2017-May-31';
// Declarations

Wyświetl plik

@ -3432,11 +3432,15 @@ Fixes:
------
* let clones share the orginals scripts without shallow-copying them
170531
------
* added inheritance support for scripts, partly done, copy-on-write is still missing
Features:
* polymorphic sprite-local custom blocks
* inheritance of sprite-local custom blocks
* inheritance of sprite attributes (x, y, direction, size)
* inheritance of sprite attributes (x, y, direction, size, costumes, costume #, scripts)
* localization support when typing expressions
* support for user-forced line-breaks in custom block labels
* ternary Boolean slot setting: support to limit Boolean input slots to “true/false” outside of rings and in palette

Wyświetl plik

@ -82,7 +82,7 @@ SpeechBubbleMorph, RingMorph, isNil, FileReader, TableDialogMorph,
BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize,
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph*/
modules.objects = '2017-May-30';
modules.objects = '2017-May-31';
var SpriteMorph;
var StageMorph;
@ -121,7 +121,8 @@ SpriteMorph.prototype.attributes =
'direction',
'size',
'costumes',
'costume #'
'costume #',
'scripts'
];
SpriteMorph.prototype.categories =
@ -5201,6 +5202,13 @@ SpriteMorph.prototype.shadowAttribute = function (aName) {
}
});
this.costumes = wardrobe;
} else if (aName === 'scripts') {
this.scripts = this.exemplar.scripts.fullCopy();
if (ide && (contains(ide.currentSprite.allExemplars(), this))) {
ide.createSpriteEditor();
ide.fixLayout('selectSprite');
this.scripts.fixMultiArgs();
}
} else if (ide) {
ide.flushBlocksCache(); // optimization: specify category if known
ide.refreshPalette();
@ -5227,6 +5235,7 @@ SpriteMorph.prototype.inheritAttribute = function (aName) {
};
SpriteMorph.prototype.refreshInheritedAttribute = function (aName) {
var ide;
switch (aName) {
case 'x position':
case 'y position':
@ -5241,6 +5250,19 @@ SpriteMorph.prototype.refreshInheritedAttribute = function (aName) {
case 'costume #':
this.doSwitchToCostume(this.getCostumeIdx(), true);
break;
case 'scripts':
this.scripts = this.exemplar.scripts;
ide = this.parentThatIsA(IDE_Morph);
if (ide && (contains(ide.currentSprite.allExemplars(), this))) {
ide.createSpriteEditor();
ide.fixLayout('selectSprite');
}
this.specimens().forEach(function (sprite) {
if (sprite.inheritsAttribute('scripts')) {
sprite.refreshInheritedAttribute('scripts');
}
});
break;
default:
nop();
}

Wyświetl plik

@ -61,7 +61,7 @@ normalizeCanvas, contains*/
// Global stuff ////////////////////////////////////////////////////////
modules.store = '2017-May-05';
modules.store = '2017-May-31';
// XML_Serializer ///////////////////////////////////////////////////////
@ -494,6 +494,9 @@ SnapSerializer.prototype.rawLoadProjectModel = function (xmlNode) {
sprite.nestingScale = +(sprite.nestingInfo.scale || sprite.scale);
delete sprite.nestingInfo;
}
if (sprite.inheritsAttribute('scripts')) {
sprite.refreshInheritedAttribute('scripts');
}
});
/* Global Variables */
@ -735,6 +738,13 @@ SnapSerializer.prototype.loadObject = function (object, model) {
}
this.populateCustomBlocks(object, blocks);
this.loadVariables(object.variables, model.require('variables'), object);
// loads scripts unless they're inherited
if (object.inheritanceInfo &&
(object.inheritanceInfo.delegated instanceof Array) &&
contains(object.inheritanceInfo.delegated, 'scripts')) {
return;
}
this.loadScripts(object, object.scripts, model.require('scripts'));
// note: the dispatches cache isn't cleared until after
@ -1603,7 +1613,8 @@ StageMorph.prototype.toXML = function (serializer) {
SpriteMorph.prototype.toXML = function (serializer) {
var stage = this.parentThatIsA(StageMorph),
ide = stage ? stage.parentThatIsA(IDE_Morph) : null,
idx = ide ? ide.sprites.asArray().indexOf(this) + 1 : 0;
idx = ide ? ide.sprites.asArray().indexOf(this) + 1 : 0,
noScripts = this.inheritsAttribute('scripts');
return serializer.format(
'<sprite name="@" idx="@" x="@" y="@"' +
@ -1620,7 +1631,7 @@ SpriteMorph.prototype.toXML = function (serializer) {
'<blocks>%</blocks>' +
'<variables>%</variables>' +
(this.exemplar ? '<dispatches>%</dispatches>' : '%') +
'<scripts>%</scripts>' +
(noScripts ? '%' : '<scripts>%</scripts>') +
'</sprite>',
this.name,
idx,
@ -1669,7 +1680,7 @@ SpriteMorph.prototype.toXML = function (serializer) {
serializer.store(this.variables),
this.exemplar ?
serializer.store(this.inheritedMethods()) : '',
serializer.store(this.scripts)
noScripts ? '' : serializer.store(this.scripts)
);
};