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