Skip to content
This repository has been archived by the owner on Sep 3, 2019. It is now read-only.

Commit

Permalink
Fixed renaming sprite breaking script references to that sprite
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan committed Jun 16, 2014
1 parent 5132c96 commit fcb9751
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
29 changes: 29 additions & 0 deletions src/scratch/ScratchRuntime.as
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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 = [];
Expand Down
6 changes: 1 addition & 5 deletions src/ui/parts/SpriteInfoPart.as
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit fcb9751

Please sign in to comment.