From b451a08812fbf1a4ae0481005a62dc1743bbe333 Mon Sep 17 00:00:00 2001 From: jmoenig Date: Tue, 29 Jul 2014 10:50:36 +0200 Subject: duplicate and clone nested sprites --- objects.js | 62 +++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 21 deletions(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index f9908ef..35a0014 100644 --- a/objects.js +++ b/objects.js @@ -125,7 +125,7 @@ PrototypeHatBlockMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.objects = '2014-July-25'; +modules.objects = '2014-July-29'; var SpriteMorph; var StageMorph; @@ -1338,6 +1338,7 @@ SpriteMorph.prototype.fullCopy = function () { var c = SpriteMorph.uber.fullCopy.call(this), myself = this, arr = [], + dp, cb; c.stopTalking(); @@ -1348,7 +1349,6 @@ SpriteMorph.prototype.fullCopy = function () { c.scripts.owner = c; c.variables = this.variables.copy(); c.variables.owner = c; - c.customBlocks = []; this.customBlocks.forEach(function (def) { cb = def.copyAndBindTo(c); @@ -1370,15 +1370,31 @@ SpriteMorph.prototype.fullCopy = function () { arr.push(sound); }); c.sounds = new List(arr); - - c.parts = []; - c.anchor = null; c.nestingScale = 1; c.rotatesWithAnchor = true; + c.anchor = null; + c.parts = []; + this.parts.forEach(function (part) { + dp = part.fullCopy(); + dp.nestingScale = part.nestingScale; + dp.rotatesWithAnchor = part.rotatesWithAnchor; + c.attachPart(dp); + }); return c; }; +SpriteMorph.prototype.appearIn = function (ide) { + // private - used in IDE_Morph.duplicateSprite() + this.name = ide.newSpriteName(this.name); + ide.stage.add(this); + ide.sprites.add(this); + ide.corral.addSprite(this); + this.parts.forEach(function (part) { + part.appearIn(ide); + }); +}; + // SpriteMorph versioning SpriteMorph.prototype.setName = function (string) { @@ -2657,25 +2673,29 @@ SpriteMorph.prototype.remove = function () { // SpriteMorph cloning (experimental) SpriteMorph.prototype.createClone = function () { - var clone, - hats, - stage = this.parentThatIsA(StageMorph); - if (stage) { - if (stage.cloneCount > 300) {return; } - stage.cloneCount += 1; - clone = this.fullCopy(); - clone.isClone = true; - clone.name = ''; - clone.cloneOriginName = this.isClone ? - this.cloneOriginName : this.name; - stage.add(clone); - hats = clone.allHatBlocksFor('__clone__init__'); - hats.forEach(function (block) { - stage.threads.startProcess(block, stage.isThreadSafe); - }); + var stage = this.parentThatIsA(StageMorph); + if (stage && stage.cloneCount <= 300) { + this.fullCopy().clonify(stage); } }; +SpriteMorph.prototype.clonify = function (stage) { + var hats; + this.parts.forEach(function (part) { + part.clonify(stage); + }); + stage.cloneCount += 1; + this.cloneOriginName = this.isClone ? + this.cloneOriginName : this.name; + this.isClone = true; + this.name = ''; + stage.add(this); + hats = this.allHatBlocksFor('__clone__init__'); + hats.forEach(function (block) { + stage.threads.startProcess(block, stage.isThreadSafe); + }); +}; + SpriteMorph.prototype.removeClone = function () { if (this.isClone) { // this.stopTalking(); -- cgit v1.3.1