summaryrefslogtreecommitdiff
path: root/objects.js
diff options
context:
space:
mode:
authorjmoenig <jens@moenig.org>2014-07-24 11:40:36 +0200
committerjmoenig <jens@moenig.org>2014-07-24 11:40:36 +0200
commit75d9adbfe26d0303f1986f3140307d2f196c73ec (patch)
tree6c395812ce78d5a3039e2a3f125515000a6de86e /objects.js
parent1b382458c8208cb74b51cad414e67a71be61e0e2 (diff)
downloadsnap-yow-75d9adbfe26d0303f1986f3140307d2f196c73ec.tar.gz
snap-yow-75d9adbfe26d0303f1986f3140307d2f196c73ec.zip
improve unique sprite- and costume names
Diffstat (limited to 'objects.js')
-rw-r--r--objects.js27
1 files changed, 14 insertions, 13 deletions
diff --git a/objects.js b/objects.js
index d378b75..2b04eb4 100644
--- a/objects.js
+++ b/objects.js
@@ -4094,20 +4094,21 @@ SpriteMorph.prototype.reactToDropOf = function (morph, hand) {
// SpriteMorph screenshots
-SpriteMorph.prototype.newCostumeName = function (name) {
-
- function stemOf(aName) {
- var ix = aName.indexOf('(');
- if (ix < 0) {return aName; }
- return aName.substring(0, ix);
+SpriteMorph.prototype.newCostumeName = function (name, ignoredCostume) {
+ var ix = name.indexOf('('),
+ stem = (ix < 0) ? name : name.substring(0, ix),
+ count = 1,
+ newName = stem,
+ all = this.costumes.asArray().filter(
+ function (each) {return each !== ignoredCostume; }
+ ).map(
+ function (each) {return each.name; }
+ );
+ while (contains(all, newName)) {
+ count += 1;
+ newName = stem + '(' + count + ')';
}
-
- var stem = stemOf(name),
- similar = this.costumes.asArray().filter(function (eachCostume) {
- return stemOf(eachCostume.name) === stem;
- }).length;
-
- return stem + (similar ? '(' + (similar + 1) + ')' : '');
+ return newName;
};
SpriteMorph.prototype.doScreenshot = function (imgSource, data) {