diff options
| author | Gubolin <gubolin@fantasymail.de> | 2015-07-23 14:28:31 +0200 |
|---|---|---|
| committer | Gubolin <gubolin@fantasymail.de> | 2015-07-23 14:28:31 +0200 |
| commit | 29b5dba84e8f3aa95a3b9296d5a01a2609f4590d (patch) | |
| tree | 4ec090b68a695c6ba6d7bc26b6362519b485a0ba /store.js | |
| parent | 526a595c5e00f171eb814f063e58a6c18c5784d4 (diff) | |
| parent | 5aec52889d79a8257971095719195fabcbc33559 (diff) | |
| download | snap-gh-pages.tar.gz snap-gh-pages.zip | |
merge developmentgh-pages
Diffstat (limited to 'store.js')
| -rw-r--r-- | store.js | 102 |
1 files changed, 80 insertions, 22 deletions
@@ -61,7 +61,7 @@ SyntaxElementMorph, Variable*/ // Global stuff //////////////////////////////////////////////////////// -modules.store = '2015-February-28'; +modules.store = '2015-June-25'; // XML_Serializer /////////////////////////////////////////////////////// @@ -459,9 +459,17 @@ SnapSerializer.prototype.rawLoadProjectModel = function (xmlNode) { myself.loadValue(model); }); - // restore nesting associations + // restore inheritance and nesting associations myself.project.stage.children.forEach(function (sprite) { - var anchor; + var exemplar, anchor; + if (sprite.inheritanceInfo) { // only sprites can inherit + exemplar = myself.project.sprites[ + sprite.inheritanceInfo.exemplar + ]; + if (exemplar) { + sprite.setExemplar(exemplar); + } + } if (sprite.nestingInfo) { // only sprites may have nesting info anchor = myself.project.sprites[sprite.nestingInfo.anchor]; if (anchor) { @@ -471,6 +479,7 @@ SnapSerializer.prototype.rawLoadProjectModel = function (xmlNode) { } }); myself.project.stage.children.forEach(function (sprite) { + delete sprite.inheritanceInfo; if (sprite.nestingInfo) { // only sprites may have nesting info sprite.nestingScale = +(sprite.nestingInfo.scale || sprite.scale); delete sprite.nestingInfo; @@ -491,7 +500,7 @@ SnapSerializer.prototype.rawLoadProjectModel = function (xmlNode) { /* Watchers */ model.sprites.childrenNamed('watcher').forEach(function (model) { - var watcher, color, target, hidden, extX, extY; + var watcher, color, target, hidden, extX, extY, vFrame; color = myself.loadColor(model.attributes.color); target = Object.prototype.hasOwnProperty.call( @@ -512,14 +521,20 @@ SnapSerializer.prototype.rawLoadProjectModel = function (xmlNode) { model.attributes, 'var' )) { - watcher = new WatcherMorph( - model.attributes['var'], - color, - isNil(target) ? project.globalVariables - : target.variables, - model.attributes['var'], - hidden - ); + vFrame = isNil(target) ? project.globalVariables + : target.variables; + if (Object.prototype.hasOwnProperty.call( + vFrame.vars, + model.attributes['var'] + )) { + watcher = new WatcherMorph( + model.attributes['var'], + color, + vFrame, + model.attributes['var'], + hidden + ); + } } else { watcher = new WatcherMorph( localize(myself.watcherLabels[model.attributes.s]), @@ -531,8 +546,8 @@ SnapSerializer.prototype.rawLoadProjectModel = function (xmlNode) { } watcher.setStyle(model.attributes.style || 'normal'); if (watcher.style === 'slider') { - watcher.setSliderMin(model.attributes.min || '1'); - watcher.setSliderMax(model.attributes.max || '100'); + watcher.setSliderMin(model.attributes.min || '1', true); + watcher.setSliderMax(model.attributes.max || '100', true); } watcher.setPosition( project.stage.topLeft().add(new Point( @@ -550,12 +565,29 @@ SnapSerializer.prototype.rawLoadProjectModel = function (xmlNode) { if (extX) { watcher.cellMorph.contentsMorph.setWidth(+extX); } - extY = model.attributes.extY; - if (extY) { - watcher.cellMorph.contentsMorph.setHeight(+extY); + watcher.setPosition( + project.stage.topLeft().add(new Point( + +model.attributes.x || 0, + +model.attributes.y || 0 + )) + ); + project.stage.add(watcher); + watcher.onNextStep = function () {this.currentValue = null; }; + + // set watcher's contentsMorph's extent if it is showing a list + // and if its monitor dimensions are given + if (watcher.currentValue instanceof List) { + extX = model.attributes.extX; + if (extX) { + watcher.cellMorph.contentsMorph.setWidth(+extX); + } + extY = model.attributes.extY; + if (extY) { + watcher.cellMorph.contentsMorph.setHeight(+extY); + } + // adjust my contentsMorph's handle position + watcher.cellMorph.contentsMorph.handle.drawNew(); } - // adjust my contentsMorph's handle position - watcher.cellMorph.contentsMorph.handle.drawNew(); } }); this.objects = {}; @@ -639,9 +671,17 @@ SnapSerializer.prototype.loadSprites = function (xmlString, ide) { myself.loadObject(sprite, model); }); - // restore nesting associations + // restore inheritance and nesting associations project.stage.children.forEach(function (sprite) { - var anchor; + var exemplar, anchor; + if (sprite.inheritanceInfo) { // only sprites can inherit + exemplar = project.sprites[ + sprite.inheritanceInfo.exemplar + ]; + if (exemplar) { + sprite.setExemplar(exemplar); + } + } if (sprite.nestingInfo) { // only sprites may have nesting info anchor = project.sprites[sprite.nestingInfo.anchor]; if (anchor) { @@ -651,6 +691,7 @@ SnapSerializer.prototype.loadSprites = function (xmlString, ide) { } }); project.stage.children.forEach(function (sprite) { + delete sprite.inheritanceInfo; if (sprite.nestingInfo) { // only sprites may have nesting info sprite.nestingScale = +(sprite.nestingInfo.scale || sprite.scale); delete sprite.nestingInfo; @@ -690,6 +731,7 @@ SnapSerializer.prototype.loadMediaModel = function (xmlNode) { SnapSerializer.prototype.loadObject = function (object, model) { // private var blocks = model.require('blocks'); + this.loadInheritanceInfo(object, model); this.loadNestingInfo(object, model); this.loadCostumes(object, model); this.loadSounds(object, model); @@ -699,6 +741,14 @@ SnapSerializer.prototype.loadObject = function (object, model) { this.loadScripts(object.scripts, model.require('scripts')); }; +SnapSerializer.prototype.loadInheritanceInfo = function (object, model) { + // private + var info = model.childNamed('inherit'); + if (info) { + object.inheritanceInfo = info.attributes; + } +}; + SnapSerializer.prototype.loadNestingInfo = function (object, model) { // private var info = model.childNamed('nest'); @@ -782,7 +832,7 @@ SnapSerializer.prototype.loadCustomBlocks = function ( names = definition.parseSpec(definition.spec).filter( function (str) { - return str.charAt(0) === '%'; + return str.charAt(0) === '%' && str.length > 1; } ).map(function (str) { return str.substr(1); @@ -1467,6 +1517,7 @@ SpriteMorph.prototype.toXML = function (serializer) { ' draggable="@"' + '%' + ' costume="@" color="@,@,@" pen="@" ~>' + + '%' + // inheritance info '%' + // nesting info '<costumes>%</costumes>' + '<sounds>%</sounds>' + @@ -1489,6 +1540,13 @@ SpriteMorph.prototype.toXML = function (serializer) { this.color.b, this.penPoint, + // inheritance info + this.exemplar + ? '<inherit exemplar="' + + this.exemplar.name + + '"/>' + : '', + // nesting info this.anchor ? '<nest anchor="' + |
