From fcb9751417674856fe9489d86d97b65c0aaf1a43 Mon Sep 17 00:00:00 2001 From: Nathan Dinsmore Date: Mon, 16 Jun 2014 12:15:06 -0400 Subject: [PATCH 1/7] Fixed renaming sprite breaking script references to that sprite --- src/scratch/ScratchRuntime.as | 29 +++++++++++++++++++++++++++++ src/ui/parts/SpriteInfoPart.as | 6 +----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/scratch/ScratchRuntime.as b/src/scratch/ScratchRuntime.as index 47c4c23..f3107db 100644 --- a/src/scratch/ScratchRuntime.as +++ b/src/scratch/ScratchRuntime.as @@ -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 = []; diff --git a/src/ui/parts/SpriteInfoPart.as b/src/ui/parts/SpriteInfoPart.as index a625383..bff143e 100644 --- a/src/ui/parts/SpriteInfoPart.as +++ b/src/ui/parts/SpriteInfoPart.as @@ -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 { From 13c6a735a83131ec2c2d10654b4cb5281ae05a7a Mon Sep 17 00:00:00 2001 From: Nathan Dinsmore Date: Mon, 16 Jun 2014 13:38:33 -0400 Subject: [PATCH 2/7] Added a semicolon --- src/scratch/ScratchRuntime.as | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scratch/ScratchRuntime.as b/src/scratch/ScratchRuntime.as index f3107db..f16e4d6 100644 --- a/src/scratch/ScratchRuntime.as +++ b/src/scratch/ScratchRuntime.as @@ -663,7 +663,7 @@ public class ScratchRuntime { public function renameSprite(newName:String):void { var obj:ScratchObj = app.viewedObj(); - var oldName:String = obj.objName + var oldName:String = obj.objName; obj.objName = newName; for each (var lw:ListWatcher in app.viewedObj().lists) { lw.updateTitle(); From 716c06437916e4a5614b68e059cac76ce99168c8 Mon Sep 17 00:00:00 2001 From: Nathan Dinsmore Date: Mon, 16 Jun 2014 13:42:36 -0400 Subject: [PATCH 3/7] Removed a trace() statement --- src/scratch/ScratchRuntime.as | 1 - 1 file changed, 1 deletion(-) diff --git a/src/scratch/ScratchRuntime.as b/src/scratch/ScratchRuntime.as index f16e4d6..cdb3544 100644 --- a/src/scratch/ScratchRuntime.as +++ b/src/scratch/ScratchRuntime.as @@ -669,7 +669,6 @@ public class ScratchRuntime { 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(); From bf9ce4a865d29e751d630635a0e0098b53a74263 Mon Sep 17 00:00:00 2001 From: Nathan Dinsmore Date: Mon, 16 Jun 2014 13:43:18 -0400 Subject: [PATCH 4/7] Prevented duplicate sprite names --- src/scratch/ScratchRuntime.as | 2 ++ src/ui/parts/SpriteInfoPart.as | 1 + 2 files changed, 3 insertions(+) diff --git a/src/scratch/ScratchRuntime.as b/src/scratch/ScratchRuntime.as index cdb3544..5d587ff 100644 --- a/src/scratch/ScratchRuntime.as +++ b/src/scratch/ScratchRuntime.as @@ -663,6 +663,8 @@ public class ScratchRuntime { public function renameSprite(newName:String):void { var obj:ScratchObj = app.viewedObj(); + obj.objName = ''; + newName = app.stagePane.unusedSpriteName(newName); var oldName:String = obj.objName; obj.objName = newName; for each (var lw:ListWatcher in app.viewedObj().lists) { diff --git a/src/ui/parts/SpriteInfoPart.as b/src/ui/parts/SpriteInfoPart.as index bff143e..4637d0e 100644 --- a/src/ui/parts/SpriteInfoPart.as +++ b/src/ui/parts/SpriteInfoPart.as @@ -341,6 +341,7 @@ public class SpriteInfoPart extends UIPart implements DragClient { private function nameChanged():void { app.runtime.renameSprite(spriteName.contents()); + spriteName.setContents(app.viewedObj().objName); } public function updateThumbnail():void { From 7a201faa47e893430ccc82fa9427c4cf6f0118f4 Mon Sep 17 00:00:00 2001 From: Nathan Dinsmore Date: Tue, 17 Jun 2014 12:09:29 -0400 Subject: [PATCH 5/7] Removed a trace() statement --- src/scratch/ScratchRuntime.as | 1 - 1 file changed, 1 deletion(-) diff --git a/src/scratch/ScratchRuntime.as b/src/scratch/ScratchRuntime.as index 5d587ff..a339b97 100644 --- a/src/scratch/ScratchRuntime.as +++ b/src/scratch/ScratchRuntime.as @@ -739,7 +739,6 @@ public class ScratchRuntime { // 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); } }); From f364eaaab4f59a304370033c350b8dfa060d2cd9 Mon Sep 17 00:00:00 2001 From: Nathan Dinsmore Date: Tue, 24 Jun 2014 18:01:03 -0400 Subject: [PATCH 6/7] Made empty sprite name turn into Sprite instead of --- src/scratch/ScratchRuntime.as | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scratch/ScratchRuntime.as b/src/scratch/ScratchRuntime.as index a339b97..ac2552f 100644 --- a/src/scratch/ScratchRuntime.as +++ b/src/scratch/ScratchRuntime.as @@ -664,7 +664,7 @@ public class ScratchRuntime { public function renameSprite(newName:String):void { var obj:ScratchObj = app.viewedObj(); obj.objName = ''; - newName = app.stagePane.unusedSpriteName(newName); + newName = app.stagePane.unusedSpriteName(newName || 'Sprite1'); var oldName:String = obj.objName; obj.objName = newName; for each (var lw:ListWatcher in app.viewedObj().lists) { From d58074ff4f90584c86b32e233e10aa6afc896796 Mon Sep 17 00:00:00 2001 From: Nathan Dinsmore Date: Tue, 24 Jun 2014 18:13:13 -0400 Subject: [PATCH 7/7] Fixed updating references --- src/scratch/ScratchRuntime.as | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scratch/ScratchRuntime.as b/src/scratch/ScratchRuntime.as index ac2552f..d2b41db 100644 --- a/src/scratch/ScratchRuntime.as +++ b/src/scratch/ScratchRuntime.as @@ -663,9 +663,9 @@ public class ScratchRuntime { public function renameSprite(newName:String):void { var obj:ScratchObj = app.viewedObj(); + var oldName:String = obj.objName; obj.objName = ''; newName = app.stagePane.unusedSpriteName(newName || 'Sprite1'); - var oldName:String = obj.objName; obj.objName = newName; for each (var lw:ListWatcher in app.viewedObj().lists) { lw.updateTitle();