diff options
| author | jmoenig <jens@moenig.org> | 2014-07-29 10:50:36 +0200 |
|---|---|---|
| committer | jmoenig <jens@moenig.org> | 2014-07-29 10:50:36 +0200 |
| commit | b451a08812fbf1a4ae0481005a62dc1743bbe333 (patch) | |
| tree | fa579fddb4c1587ef09c7076e16a51dcb89937b3 /objects.js | |
| parent | e572da6f654f076b91dd7cd3ca55b5326a33939e (diff) | |
| download | snap-b451a08812fbf1a4ae0481005a62dc1743bbe333.tar.gz snap-b451a08812fbf1a4ae0481005a62dc1743bbe333.zip | |
duplicate and clone nested sprites
Diffstat (limited to 'objects.js')
| -rw-r--r-- | objects.js | 62 |
1 files changed, 41 insertions, 21 deletions
@@ -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(); |
