mirror of
https://github.com/scratchfoundation/scratch-flash.git
synced 2024-12-04 21:21:06 -05:00
Switched to using unused names when renaming costumes and sprites
This commit is contained in:
parent
55652f899b
commit
af780f0f74
2 changed files with 2 additions and 18 deletions
|
@ -132,22 +132,6 @@ public class ScratchObj extends Sprite {
|
||||||
return currentCostumeIndex + 1;
|
return currentCostumeIndex + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isCostumeNameUsed(name:String):Boolean {
|
|
||||||
name = name.toLowerCase();
|
|
||||||
for each (var c:ScratchCostume in costumes) {
|
|
||||||
if (c.costumeName.toLowerCase() == name) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isSoundNameUsed(name:String):Boolean {
|
|
||||||
name = name.toLowerCase();
|
|
||||||
for each (var s:ScratchSound in sounds) {
|
|
||||||
if (s.soundName.toLowerCase() == name) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function unusedCostumeName(baseName:String = ''):String {
|
public function unusedCostumeName(baseName:String = ''):String {
|
||||||
// Create a unique costume name by appending a number if necessary.
|
// Create a unique costume name by appending a number if necessary.
|
||||||
if (baseName == '') baseName = Translator.map(isStage ? 'backdrop1' : 'costume1');
|
if (baseName == '') baseName = Translator.map(isStage ? 'backdrop1' : 'costume1');
|
||||||
|
|
|
@ -676,7 +676,7 @@ public class ScratchRuntime {
|
||||||
var obj:ScratchObj = app.viewedObj();
|
var obj:ScratchObj = app.viewedObj();
|
||||||
var costume:ScratchCostume = obj.currentCostume();
|
var costume:ScratchCostume = obj.currentCostume();
|
||||||
var oldName:String = costume.costumeName;
|
var oldName:String = costume.costumeName;
|
||||||
if (obj.isCostumeNameUsed(newName)) return;
|
newName = obj.unusedCostumeName(newName || 'costume1');
|
||||||
costume.costumeName = newName;
|
costume.costumeName = newName;
|
||||||
updateArgs(obj.isStage ? allUsesOfBackdrop(oldName) : allUsesOfCostume(oldName), newName);
|
updateArgs(obj.isStage ? allUsesOfBackdrop(oldName) : allUsesOfCostume(oldName), newName);
|
||||||
}
|
}
|
||||||
|
@ -703,7 +703,7 @@ public class ScratchRuntime {
|
||||||
public function renameSound(s:ScratchSound, newName:String):void {
|
public function renameSound(s:ScratchSound, newName:String):void {
|
||||||
var obj:ScratchObj = app.viewedObj();
|
var obj:ScratchObj = app.viewedObj();
|
||||||
var oldName:String = s.soundName;
|
var oldName:String = s.soundName;
|
||||||
if (obj.isSoundNameUsed(newName)) return;
|
newName = obj.unusedSoundName(newName || 'sound1');
|
||||||
s.soundName = newName;
|
s.soundName = newName;
|
||||||
allUsesOfSoundDo(oldName, function (a:BlockArg):void {
|
allUsesOfSoundDo(oldName, function (a:BlockArg):void {
|
||||||
a.setArgValue(newName);
|
a.setArgValue(newName);
|
||||||
|
|
Loading…
Reference in a new issue