From af780f0f74d6499e1dc943b50ed23fa8bc25e8c2 Mon Sep 17 00:00:00 2001 From: Nathan Dinsmore Date: Tue, 24 Jun 2014 19:03:49 -0400 Subject: [PATCH] Switched to using unused names when renaming costumes and sprites --- src/scratch/ScratchObj.as | 16 ---------------- src/scratch/ScratchRuntime.as | 4 ++-- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/src/scratch/ScratchObj.as b/src/scratch/ScratchObj.as index 3e99861..721c069 100644 --- a/src/scratch/ScratchObj.as +++ b/src/scratch/ScratchObj.as @@ -132,22 +132,6 @@ public class ScratchObj extends Sprite { 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 { // Create a unique costume name by appending a number if necessary. if (baseName == '') baseName = Translator.map(isStage ? 'backdrop1' : 'costume1'); diff --git a/src/scratch/ScratchRuntime.as b/src/scratch/ScratchRuntime.as index abd4231..e34b9c5 100644 --- a/src/scratch/ScratchRuntime.as +++ b/src/scratch/ScratchRuntime.as @@ -676,7 +676,7 @@ public class ScratchRuntime { var obj:ScratchObj = app.viewedObj(); var costume:ScratchCostume = obj.currentCostume(); var oldName:String = costume.costumeName; - if (obj.isCostumeNameUsed(newName)) return; + newName = obj.unusedCostumeName(newName || 'costume1'); costume.costumeName = newName; updateArgs(obj.isStage ? allUsesOfBackdrop(oldName) : allUsesOfCostume(oldName), newName); } @@ -703,7 +703,7 @@ public class ScratchRuntime { public function renameSound(s:ScratchSound, newName:String):void { var obj:ScratchObj = app.viewedObj(); var oldName:String = s.soundName; - if (obj.isSoundNameUsed(newName)) return; + newName = obj.unusedSoundName(newName || 'sound1'); s.soundName = newName; allUsesOfSoundDo(oldName, function (a:BlockArg):void { a.setArgValue(newName);