diff options
| -rwxr-xr-x | history.txt | 1 | ||||
| -rw-r--r-- | objects.js | 14 | ||||
| -rw-r--r-- | store.js | 48 |
3 files changed, 55 insertions, 8 deletions
diff --git a/history.txt b/history.txt index 8aec5a6..d166d1d 100755 --- a/history.txt +++ b/history.txt @@ -1869,3 +1869,4 @@ ______ 130809 ------ * GUI: Nested Sprite Rotation style buttons on corral icons +* Store, Objects: Nested Sprite saving / loading @@ -1169,18 +1169,18 @@ SpriteMorph.prototype.init = function (globals) { this.isClone = false; // indicate a "temporary" Scratch-style clone this.cloneOriginName = ''; + // sprite nesting properties + this.parts = []; // not serialized, only anchor (name) + this.anchor = null; + this.nestingScale = 1; + this.rotatesWithAnchor = true; + this.blocksCache = {}; // not to be serialized (!) this.paletteCache = {}; // not to be serialized (!) this.rotationOffset = new Point(); // not to be serialized (!) this.idx = 0; // not to be serialized (!) - used for de-serialization this.wasWarped = false; // not to be serialized, used for fast-tracking - // sprite nesting properties - this.parts = []; - this.anchor = null; - this.nestingScale = 1; - this.rotatesWithAnchor = true; - SpriteMorph.uber.init.call(this); this.isDraggable = true; @@ -2126,7 +2126,7 @@ SpriteMorph.prototype.wearCostume = function (costume) { this.startWarp(); } if (x !== null) { - this.silentGotoXY(x, y); + this.silentGotoXY(x, y, true); // just me } if (this.positionTalkBubble) { // the stage doesn't talk this.positionTalkBubble(); @@ -61,7 +61,7 @@ SyntaxElementMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.store = '2013-July-08'; +modules.store = '2013-August-09'; // XML_Serializer /////////////////////////////////////////////////////// @@ -426,6 +426,26 @@ SnapSerializer.prototype.loadProjectModel = function (xmlNode) { myself.loadValue(model); }); + // restore nesting associations + myself.project.stage.children.forEach(function (sprite) { + var anchor; + if (sprite.nestingInfo) { // only sprites may have nesting info + anchor = myself.project.sprites[sprite.nestingInfo.anchor]; + if (anchor) { + anchor.attachPart(sprite); + } + sprite.rotatesWithAnchor = (sprite.nestingInfo.synch === 'true'); + } + }); + myself.project.stage.children.forEach(function (sprite) { + if (sprite.nestingInfo) { // only sprites may have nesting info + sprite.nestingScale = +(sprite.nestingInfo.scale || sprite.scale); + delete sprite.nestingInfo; + } + }); + + this.objects = {}; + /* Global Variables */ if (model.globalVariables) { @@ -618,6 +638,7 @@ SnapSerializer.prototype.loadMediaModel = function (xmlNode) { SnapSerializer.prototype.loadObject = function (object, model) { // private var blocks = model.require('blocks'); + this.loadNestingInfo(object, model); this.loadCostumes(object, model); this.loadSounds(object, model); this.loadCustomBlocks(object, blocks); @@ -626,6 +647,14 @@ SnapSerializer.prototype.loadObject = function (object, model) { this.loadScripts(object.scripts, model.require('scripts')); }; +SnapSerializer.prototype.loadNestingInfo = function (object, model) { + // private + var info = model.childNamed('nest'); + if (info) { + object.nestingInfo = info.attributes; + } +}; + SnapSerializer.prototype.loadCostumes = function (object, model) { // private var costumes = model.childNamed('costumes'), @@ -1240,6 +1269,7 @@ SnapSerializer.prototype.openProject = function (project, ide) { sprites.sort(function (x, y) { return x.idx - y.idx; }); + ide.sprites = new List(sprites); sprite = sprites[0] || project.stage; @@ -1359,6 +1389,7 @@ SpriteMorph.prototype.toXML = function (serializer) { ' draggable="@"' + '%' + ' costume="@" color="@,@,@" pen="@" ~>' + + '%' + // nesting info '<costumes>%</costumes>' + '<sounds>%</sounds>' + '<variables>%</variables>' + @@ -1379,6 +1410,21 @@ SpriteMorph.prototype.toXML = function (serializer) { this.color.g, this.color.b, this.penPoint, + + // nesting info + this.anchor + ? '<nest anchor="' + + this.anchor.name + + '" synch="' + + this.rotatesWithAnchor + + (this.scale === this.nestingScale ? '' : + '"' + + ' scale="' + + this.nestingScale) + + + '"/>' + : '', + serializer.store(this.costumes, this.name + '_cst'), serializer.store(this.sounds, this.name + '_snd'), serializer.store(this.variables), |
