summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gui.js7
-rwxr-xr-xhistory.txt1
-rw-r--r--objects.js62
3 files changed, 44 insertions, 26 deletions
diff --git a/gui.js b/gui.js
index 7e38095..7e98549 100644
--- a/gui.js
+++ b/gui.js
@@ -69,7 +69,7 @@ SpeechBubbleMorph*/
// Global stuff ////////////////////////////////////////////////////////
-modules.gui = '2014-July-25';
+modules.gui = '2014-July-29';
// Declarations
@@ -1824,12 +1824,9 @@ IDE_Morph.prototype.paintNewSprite = function () {
IDE_Morph.prototype.duplicateSprite = function (sprite) {
var duplicate = sprite.fullCopy();
- duplicate.name = this.newSpriteName(sprite.name);
duplicate.setPosition(this.world().hand.position());
- this.stage.add(duplicate);
+ duplicate.appearIn(this);
duplicate.keepWithin(this.stage);
- this.sprites.add(duplicate);
- this.corral.addSprite(duplicate);
this.selectSprite(duplicate);
};
diff --git a/history.txt b/history.txt
index ea6616b..0938517 100755
--- a/history.txt
+++ b/history.txt
@@ -2242,3 +2242,4 @@ ______
140729
------
* fixed #526, thanks, Bernat, for reporting it!
+* Objects, GUI: duplicate and clone nested sprites
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();