mirror of
https://github.com/scratchfoundation/scratch-flash.git
synced 2024-12-04 21:21:06 -05:00
Fixed renaming sprite breaking script references to that sprite
This commit is contained in:
parent
5132c96eb2
commit
fcb9751417
2 changed files with 30 additions and 5 deletions
|
@ -661,6 +661,20 @@ public class ScratchRuntime {
|
|||
// Script utilities
|
||||
//------------------------------
|
||||
|
||||
public function renameSprite(newName:String):void {
|
||||
var obj:ScratchObj = app.viewedObj();
|
||||
var oldName:String = obj.objName
|
||||
obj.objName = newName;
|
||||
for each (var lw:ListWatcher in app.viewedObj().lists) {
|
||||
lw.updateTitle();
|
||||
}
|
||||
for each (var a:BlockArg in allUsesOfSprite(oldName)) {
|
||||
trace((a.parent as Block).spec, a.menuName, a.argValue);
|
||||
a.setArgValue(newName);
|
||||
}
|
||||
app.setSaveNeeded();
|
||||
}
|
||||
|
||||
public function clearRunFeedback():void {
|
||||
if(app.editMode) {
|
||||
for each (var stack:Block in allStacks()) {
|
||||
|
@ -717,6 +731,21 @@ public class ScratchRuntime {
|
|||
return false;
|
||||
}
|
||||
|
||||
public function allUsesOfSprite(spriteName:String):Array {
|
||||
var spriteMenus:Array = ["spriteOnly", "spriteOrMouse", "spriteOrStage", "touching"];
|
||||
var result:Array = [];
|
||||
for each (var stack:Block in allStacks()) {
|
||||
// for each block in stack
|
||||
stack.allBlocksDo(function (b:Block):void {
|
||||
for each (var a:BlockArg in b.args) {
|
||||
trace(a.menuName, spriteMenus.indexOf(a.menuName), a.argValue, spriteName)
|
||||
if (spriteMenus.indexOf(a.menuName) != -1 && a.argValue == spriteName) result.push(a);
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public function allUsesOfVariable(varName:String, owner:ScratchObj):Array {
|
||||
var variableBlocks:Array = [Specs.SET_VAR, Specs.CHANGE_VAR, "showVariable:", "hideVariable:"];
|
||||
var result:Array = [];
|
||||
|
|
|
@ -340,11 +340,7 @@ public class SpriteInfoPart extends UIPart implements DragClient {
|
|||
}
|
||||
|
||||
private function nameChanged():void {
|
||||
app.viewedObj().objName = spriteName.contents();
|
||||
for each (var lw:ListWatcher in app.viewedObj().lists) {
|
||||
lw.updateTitle();
|
||||
}
|
||||
app.setSaveNeeded();
|
||||
app.runtime.renameSprite(spriteName.contents());
|
||||
}
|
||||
|
||||
public function updateThumbnail():void {
|
||||
|
|
Loading…
Reference in a new issue