From 0bbf92f90bf455ea8f5b49668eca959071acf56e Mon Sep 17 00:00:00 2001
From: Karishma Chadha <kchadha@scratch.mit.edu>
Date: Thu, 3 May 2018 16:30:44 -0400
Subject: [PATCH] Update calls to addSprite2 to use new API for adding sprites.
 Cleanup sprite3 representation for uploading a new sprite from an image.

---
 src/containers/sprite-library.jsx |  2 +-
 src/containers/target-pane.jsx    |  6 +++---
 src/lib/file-uploader.js          | 32 ++++++++++++++-----------------
 3 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/src/containers/sprite-library.jsx b/src/containers/sprite-library.jsx
index 072e1714a..15d75970c 100644
--- a/src/containers/sprite-library.jsx
+++ b/src/containers/sprite-library.jsx
@@ -39,7 +39,7 @@ class SpriteLibrary extends React.PureComponent {
         clearInterval(this.intervalId);
     }
     handleItemSelect (item) {
-        this.props.vm.addSprite2(JSON.stringify(item.json));
+        this.props.vm.addSprite(JSON.stringify(item.json));
         analytics.event({
             category: 'library',
             action: 'Select Sprite',
diff --git a/src/containers/target-pane.jsx b/src/containers/target-pane.jsx
index 535e4b270..1178ed64e 100644
--- a/src/containers/target-pane.jsx
+++ b/src/containers/target-pane.jsx
@@ -72,13 +72,13 @@ class TargetPane extends React.Component {
     }
     handleSurpriseSpriteClick () {
         const item = spriteLibraryContent[Math.floor(Math.random() * spriteLibraryContent.length)];
-        this.props.vm.addSprite2(JSON.stringify(item.json));
+        this.props.vm.addSprite(JSON.stringify(item.json));
     }
     handlePaintSpriteClick () {
         // @todo this is brittle, will need to be refactored for localized libraries
         const emptyItem = spriteLibraryContent.find(item => item.name === 'Empty');
         if (emptyItem) {
-            this.props.vm.addSprite2(JSON.stringify(emptyItem.json)).then(() => {
+            this.props.vm.addSprite(JSON.stringify(emptyItem.json)).then(() => {
                 setTimeout(() => { // Wait for targets update to propagate before tab switching
                     this.props.onActivateTab(COSTUMES_TAB_INDEX);
                 });
@@ -86,7 +86,7 @@ class TargetPane extends React.Component {
         }
     }
     handleNewSprite (spriteJSONString) {
-        this.props.vm.addSprite(spriteJSONString); // TODO change all instances of addSprite2 to addSprite?
+        this.props.vm.addSprite(spriteJSONString);
     }
     handleFileUploadClick () {
         this.fileInput.click();
diff --git a/src/lib/file-uploader.js b/src/lib/file-uploader.js
index cfe54784b..a431774c5 100644
--- a/src/lib/file-uploader.js
+++ b/src/lib/file-uploader.js
@@ -189,24 +189,20 @@ const spriteUpload = function (fileData, fileType, spriteName, storage, handleSp
         // let costume = null;
         costumeUpload(fileData, fileType, `${spriteName}-costume1`, storage, (vmCostume => {
             const newSprite = {
-                targets: [{
-                    name: spriteName,
-                    isStage: false,
-                    x: 0, // what should we put here...
-                    y: 0,
-                    visible: true,
-                    size: 100,
-                    rotationStyle: 'all around',
-                    direction: 90,
-                    draggable: true,
-                    currentCostume: 0,
-                    blocks: {},
-                    variables: {},
-                    lists: {},
-                    broadcasts: {},
-                    costumes: [vmCostume],
-                    sounds: [] // TODO are all of these necessary?
-                }]
+                name: spriteName,
+                isStage: false,
+                x: 0,
+                y: 0,
+                visible: true,
+                size: 100,
+                rotationStyle: 'all around',
+                direction: 90,
+                draggable: true,
+                currentCostume: 0,
+                blocks: {},
+                variables: {},
+                costumes: [vmCostume],
+                sounds: [] // TODO are all of these necessary?
             };
             // TODO probably just want sprite upload to handle this object directly
             handleSprite(JSON.stringify(newSprite));
-- 
GitLab