kopia lustrzana https://github.com/backface/turtlestitch
improve unique sprite- and costume names
rodzic
1b382458c8
commit
75d9adbfe2
54
gui.js
54
gui.js
|
@ -69,7 +69,7 @@ SpeechBubbleMorph*/
|
||||||
|
|
||||||
// Global stuff ////////////////////////////////////////////////////////
|
// Global stuff ////////////////////////////////////////////////////////
|
||||||
|
|
||||||
modules.gui = '2014-July-18';
|
modules.gui = '2014-July-24';
|
||||||
|
|
||||||
// Declarations
|
// Declarations
|
||||||
|
|
||||||
|
@ -1011,11 +1011,13 @@ IDE_Morph.prototype.createSpriteBar = function () {
|
||||||
this.spriteBar.add(nameField);
|
this.spriteBar.add(nameField);
|
||||||
nameField.drawNew();
|
nameField.drawNew();
|
||||||
nameField.accept = function () {
|
nameField.accept = function () {
|
||||||
myself.currentSprite.setName(nameField.getValue());
|
var newName = nameField.getValue();
|
||||||
};
|
myself.currentSprite.setName(
|
||||||
this.spriteBar.reactToEdit = function () {
|
myself.newSpriteName(newName, myself.currentSprite)
|
||||||
myself.currentSprite.setName(nameField.getValue());
|
);
|
||||||
|
nameField.setContents(myself.currentSprite.name);
|
||||||
};
|
};
|
||||||
|
this.spriteBar.reactToEdit = nameField.accept;
|
||||||
|
|
||||||
// padlock
|
// padlock
|
||||||
padlock = new ToggleMorph(
|
padlock = new ToggleMorph(
|
||||||
|
@ -1780,8 +1782,7 @@ IDE_Morph.prototype.addNewSprite = function () {
|
||||||
var sprite = new SpriteMorph(this.globalVariables),
|
var sprite = new SpriteMorph(this.globalVariables),
|
||||||
rnd = Process.prototype.reportRandom;
|
rnd = Process.prototype.reportRandom;
|
||||||
|
|
||||||
sprite.name = sprite.name
|
sprite.name = this.newSpriteName(sprite.name);
|
||||||
+ (this.corral.frame.contents.children.length + 1);
|
|
||||||
sprite.setCenter(this.stage.center());
|
sprite.setCenter(this.stage.center());
|
||||||
this.stage.add(sprite);
|
this.stage.add(sprite);
|
||||||
|
|
||||||
|
@ -1802,8 +1803,7 @@ IDE_Morph.prototype.paintNewSprite = function () {
|
||||||
cos = new Costume(),
|
cos = new Costume(),
|
||||||
myself = this;
|
myself = this;
|
||||||
|
|
||||||
sprite.name = sprite.name +
|
sprite.name = this.newSpriteName(sprite.name);
|
||||||
(this.corral.frame.contents.children.length + 1);
|
|
||||||
sprite.setCenter(this.stage.center());
|
sprite.setCenter(this.stage.center());
|
||||||
this.stage.add(sprite);
|
this.stage.add(sprite);
|
||||||
this.sprites.add(sprite);
|
this.sprites.add(sprite);
|
||||||
|
@ -1824,7 +1824,7 @@ IDE_Morph.prototype.paintNewSprite = function () {
|
||||||
IDE_Morph.prototype.duplicateSprite = function (sprite) {
|
IDE_Morph.prototype.duplicateSprite = function (sprite) {
|
||||||
var duplicate = sprite.fullCopy();
|
var duplicate = sprite.fullCopy();
|
||||||
|
|
||||||
duplicate.name = sprite.name + '(2)';
|
duplicate.name = this.newSpriteName(sprite.name);
|
||||||
duplicate.setPosition(this.world().hand.position());
|
duplicate.setPosition(this.world().hand.position());
|
||||||
this.stage.add(duplicate);
|
this.stage.add(duplicate);
|
||||||
duplicate.keepWithin(this.stage);
|
duplicate.keepWithin(this.stage);
|
||||||
|
@ -1855,6 +1855,23 @@ IDE_Morph.prototype.removeSprite = function (sprite) {
|
||||||
this.selectSprite(this.currentSprite);
|
this.selectSprite(this.currentSprite);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
IDE_Morph.prototype.newSpriteName = function (name, ignoredSprite) {
|
||||||
|
var ix = name.indexOf('('),
|
||||||
|
stem = (ix < 0) ? name : name.substring(0, ix),
|
||||||
|
count = 1,
|
||||||
|
newName = stem,
|
||||||
|
all = this.sprites.asArray().filter(
|
||||||
|
function (each) {return each !== ignoredSprite; }
|
||||||
|
).map(
|
||||||
|
function (each) {return each.name; }
|
||||||
|
);
|
||||||
|
while (contains(all, newName)) {
|
||||||
|
count += 1;
|
||||||
|
newName = stem + '(' + count + ')';
|
||||||
|
}
|
||||||
|
return newName;
|
||||||
|
};
|
||||||
|
|
||||||
// IDE_Morph menus
|
// IDE_Morph menus
|
||||||
|
|
||||||
IDE_Morph.prototype.userMenu = function () {
|
IDE_Morph.prototype.userMenu = function () {
|
||||||
|
@ -5540,7 +5557,10 @@ CostumeIconMorph.prototype.renameCostume = function () {
|
||||||
null,
|
null,
|
||||||
function (answer) {
|
function (answer) {
|
||||||
if (answer && (answer !== costume.name)) {
|
if (answer && (answer !== costume.name)) {
|
||||||
costume.name = wardrobe.sprite.newCostumeName(answer);
|
costume.name = wardrobe.sprite.newCostumeName(
|
||||||
|
answer,
|
||||||
|
costume
|
||||||
|
);
|
||||||
costume.version = Date.now();
|
costume.version = Date.now();
|
||||||
ide.hasChangedMedia = true;
|
ide.hasChangedMedia = true;
|
||||||
}
|
}
|
||||||
|
@ -5555,16 +5575,8 @@ CostumeIconMorph.prototype.renameCostume = function () {
|
||||||
CostumeIconMorph.prototype.duplicateCostume = function () {
|
CostumeIconMorph.prototype.duplicateCostume = function () {
|
||||||
var wardrobe = this.parentThatIsA(WardrobeMorph),
|
var wardrobe = this.parentThatIsA(WardrobeMorph),
|
||||||
ide = this.parentThatIsA(IDE_Morph),
|
ide = this.parentThatIsA(IDE_Morph),
|
||||||
newcos = this.object.copy(),
|
newcos = this.object.copy();
|
||||||
split = newcos.name.split(" ");
|
newcos.name = wardrobe.sprite.newCostumeName(newcos.name);
|
||||||
if (split[split.length - 1] === "copy") {
|
|
||||||
newcos.name += " 2";
|
|
||||||
} else if (isNaN(split[split.length - 1])) {
|
|
||||||
newcos.name = newcos.name + " copy";
|
|
||||||
} else {
|
|
||||||
split[split.length - 1] = Number(split[split.length - 1]) + 1;
|
|
||||||
newcos.name = split.join(" ");
|
|
||||||
}
|
|
||||||
wardrobe.sprite.addCostume(newcos);
|
wardrobe.sprite.addCostume(newcos);
|
||||||
wardrobe.updateList();
|
wardrobe.updateList();
|
||||||
if (ide) {
|
if (ide) {
|
||||||
|
|
|
@ -2226,3 +2226,4 @@ ______
|
||||||
140724
|
140724
|
||||||
------
|
------
|
||||||
* Objects: fixed “lost sprites bug” - ensure duplicated sprites keep wearing their current costume through save and re-load
|
* Objects: fixed “lost sprites bug” - ensure duplicated sprites keep wearing their current costume through save and re-load
|
||||||
|
* GUI, Objects: improve unique sprite- and costume names
|
||||||
|
|
27
objects.js
27
objects.js
|
@ -4094,20 +4094,21 @@ SpriteMorph.prototype.reactToDropOf = function (morph, hand) {
|
||||||
|
|
||||||
// SpriteMorph screenshots
|
// SpriteMorph screenshots
|
||||||
|
|
||||||
SpriteMorph.prototype.newCostumeName = function (name) {
|
SpriteMorph.prototype.newCostumeName = function (name, ignoredCostume) {
|
||||||
|
var ix = name.indexOf('('),
|
||||||
function stemOf(aName) {
|
stem = (ix < 0) ? name : name.substring(0, ix),
|
||||||
var ix = aName.indexOf('(');
|
count = 1,
|
||||||
if (ix < 0) {return aName; }
|
newName = stem,
|
||||||
return aName.substring(0, ix);
|
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 + ')';
|
||||||
}
|
}
|
||||||
|
return newName;
|
||||||
var stem = stemOf(name),
|
|
||||||
similar = this.costumes.asArray().filter(function (eachCostume) {
|
|
||||||
return stemOf(eachCostume.name) === stem;
|
|
||||||
}).length;
|
|
||||||
|
|
||||||
return stem + (similar ? '(' + (similar + 1) + ')' : '');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SpriteMorph.prototype.doScreenshot = function (imgSource, data) {
|
SpriteMorph.prototype.doScreenshot = function (imgSource, data) {
|
||||||
|
|
Ładowanie…
Reference in New Issue