kopia lustrzana https://github.com/backface/turtlestitch
enable type-assertion for list elements (costumes, sounds)
rodzic
4b461bb83a
commit
f7ff3074d2
|
@ -3550,6 +3550,7 @@ Fixes:
|
|||
* Threads: programmatically hide and show primitives in the palette. Thanks, Cynthia Solomon, for this idea!
|
||||
* Objects: added "pen trails" reporter primitive and stage context menu entry
|
||||
* Threads, Blocks: added 'costume' and 'sound' as first-class data types
|
||||
* Lists, Store, Objects, Threads: enable type-assertion for list elements (costumes, sounds)
|
||||
|
||||
Features:
|
||||
* polymorphic sprite-local custom blocks
|
||||
|
|
3
lists.js
3
lists.js
|
@ -62,7 +62,7 @@ CellMorph, ArrowMorph, MenuMorph, snapEquals, Morph, isNil, localize,
|
|||
MorphicPreferences, TableDialogMorph, SpriteBubbleMorph, SpeechBubbleMorph,
|
||||
TableFrameMorph, TableMorph, Variable, isSnapObject*/
|
||||
|
||||
modules.lists = '2017-April-10';
|
||||
modules.lists = '2017-July-25';
|
||||
|
||||
var List;
|
||||
var ListWatcherMorph;
|
||||
|
@ -105,6 +105,7 @@ var ListWatcherMorph;
|
|||
// List instance creation:
|
||||
|
||||
function List(array) {
|
||||
this.type = null; // for UI lists, such as costumes, sounds, sprites
|
||||
this.contents = array || [];
|
||||
this.first = null;
|
||||
this.rest = null;
|
||||
|
|
|
@ -1383,8 +1383,10 @@ SpriteMorph.prototype.init = function (globals) {
|
|||
this.scripts = new ScriptsMorph();
|
||||
this.customBlocks = [];
|
||||
this.costumes = new List();
|
||||
this.costumes.type = 'costume';
|
||||
this.costume = null;
|
||||
this.sounds = new List();
|
||||
this.sounds.type = 'sound';
|
||||
this.normalExtent = new Point(60, 60); // only for costume-less situation
|
||||
this.scale = 1;
|
||||
this.rotationStyle = 1; // 1 = full, 2 = left/right, 0 = off
|
||||
|
@ -7193,7 +7195,6 @@ StageMorph.prototype.clear = function () {
|
|||
StageMorph.prototype.userMenu = function () {
|
||||
var ide = this.parentThatIsA(IDE_Morph),
|
||||
menu = new MenuMorph(this),
|
||||
shiftClicked = this.world().currentKey === 16,
|
||||
myself = this;
|
||||
|
||||
if (ide && ide.isAppMode) {
|
||||
|
|
4
store.js
4
store.js
|
@ -61,7 +61,7 @@ normalizeCanvas, contains*/
|
|||
|
||||
// Global stuff ////////////////////////////////////////////////////////
|
||||
|
||||
modules.store = '2017-July-07';
|
||||
modules.store = '2017-July-25';
|
||||
|
||||
|
||||
// XML_Serializer ///////////////////////////////////////////////////////
|
||||
|
@ -810,6 +810,7 @@ SnapSerializer.prototype.loadCostumes = function (object, model) {
|
|||
costume;
|
||||
if (costumes) {
|
||||
object.costumes = this.loadValue(costumes.require('list'));
|
||||
object.costumes.type = 'costume';
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(
|
||||
model.attributes,
|
||||
|
@ -834,6 +835,7 @@ SnapSerializer.prototype.loadSounds = function (object, model) {
|
|||
var sounds = model.childNamed('sounds');
|
||||
if (sounds) {
|
||||
object.sounds = this.loadValue(sounds.require('list'));
|
||||
object.sounds.type = 'sound';
|
||||
}
|
||||
};
|
||||
|
||||
|
|
11
threads.js
11
threads.js
|
@ -1688,6 +1688,9 @@ Process.prototype.reportCDR = function (list) {
|
|||
|
||||
Process.prototype.doAddToList = function (element, list) {
|
||||
this.assertType(list, 'list');
|
||||
if (list.type) {
|
||||
this.assertType(element, list.type);
|
||||
}
|
||||
list.add(element);
|
||||
};
|
||||
|
||||
|
@ -1711,6 +1714,9 @@ Process.prototype.doDeleteFromList = function (index, list) {
|
|||
Process.prototype.doInsertInList = function (element, index, list) {
|
||||
var idx = index;
|
||||
this.assertType(list, 'list');
|
||||
if (list.type) {
|
||||
this.assertType(element, list.type);
|
||||
}
|
||||
if (index === '') {
|
||||
return null;
|
||||
}
|
||||
|
@ -1726,6 +1732,9 @@ Process.prototype.doInsertInList = function (element, index, list) {
|
|||
Process.prototype.doReplaceInList = function (index, list, element) {
|
||||
var idx = index;
|
||||
this.assertType(list, 'list');
|
||||
if (list.type) {
|
||||
this.assertType(element, list.type);
|
||||
}
|
||||
if (index === '') {
|
||||
return null;
|
||||
}
|
||||
|
@ -2361,7 +2370,7 @@ Process.prototype.reportIsA = function (thing, typeString) {
|
|||
Process.prototype.assertType = function (thing, typeString) {
|
||||
// make sure "thing" is a particular type or any of a number of types
|
||||
// and raise an error if not
|
||||
// unused as of now because of performance considerations
|
||||
// use responsibly wrt performance implications
|
||||
var thingType = this.reportTypeOf(thing);
|
||||
if (thingType === typeString) {return true; }
|
||||
if (typeString instanceof Array && contains(typeString, thingType)) {
|
||||
|
|
Ładowanie…
Reference in New Issue