diff options
| author | jmoenig <jens@moenig.org> | 2014-07-24 11:40:36 +0200 |
|---|---|---|
| committer | jmoenig <jens@moenig.org> | 2014-07-24 11:40:36 +0200 |
| commit | 75d9adbfe26d0303f1986f3140307d2f196c73ec (patch) | |
| tree | 6c395812ce78d5a3039e2a3f125515000a6de86e /objects.js | |
| parent | 1b382458c8208cb74b51cad414e67a71be61e0e2 (diff) | |
| download | snap-yow-75d9adbfe26d0303f1986f3140307d2f196c73ec.tar.gz snap-yow-75d9adbfe26d0303f1986f3140307d2f196c73ec.zip | |
improve unique sprite- and costume names
Diffstat (limited to 'objects.js')
| -rw-r--r-- | objects.js | 27 |
1 files changed, 14 insertions, 13 deletions
@@ -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) { |
