From 566f92e3ba4ddef77ee2ab08754a49bae1e8d28a Mon Sep 17 00:00:00 2001
From: DD <liudi08@gmail.com>
Date: Mon, 20 Nov 2017 11:43:30 -0500
Subject: [PATCH] Recreate the toolbox with sprite-specific blocks that have
 different IDs when sprite changes

---
 src/components/monitor-list/monitor-list.jsx | 1 +
 src/containers/monitor.jsx                   | 1 +
 src/lib/monitor-adapter.js                   | 7 ++++++-
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/components/monitor-list/monitor-list.jsx b/src/components/monitor-list/monitor-list.jsx
index e28f8e098..d05ac6a3e 100644
--- a/src/components/monitor-list/monitor-list.jsx
+++ b/src/components/monitor-list/monitor-list.jsx
@@ -18,6 +18,7 @@ const MonitorList = props => (
                 key={monitorData.id}
                 opcode={monitorData.opcode}
                 params={monitorData.params}
+                spriteName={monitorData.spriteName}
                 value={monitorData.value}
                 onDragEnd={props.onMonitorChange}
             />
diff --git a/src/containers/monitor.jsx b/src/containers/monitor.jsx
index cbacffe7d..92a4304ad 100644
--- a/src/containers/monitor.jsx
+++ b/src/containers/monitor.jsx
@@ -36,6 +36,7 @@ Monitor.propTypes = {
     onDragEnd: PropTypes.func.isRequired,
     opcode: PropTypes.string.isRequired, // eslint-disable-line react/no-unused-prop-types
     params: PropTypes.object, // eslint-disable-line react/no-unused-prop-types, react/forbid-prop-types
+    spriteName: PropTypes.string, // eslint-disable-line react/no-unused-prop-types
     value: PropTypes.string.isRequired // eslint-disable-line react/no-unused-prop-types
 };
 
diff --git a/src/lib/monitor-adapter.js b/src/lib/monitor-adapter.js
index 69f362b5c..ea4a30270 100644
--- a/src/lib/monitor-adapter.js
+++ b/src/lib/monitor-adapter.js
@@ -11,6 +11,8 @@ const isUndefined = a => typeof a === 'undefined';
  * - Add missing XY position data if needed
  * @param {object} block - The monitor block
  * @param {string} block.id - The id of the monitor block
+ * @param {string} block.spriteName - Present only if the monitor applies only to the sprite
+ *     with given target ID. The name of the target sprite when the monitor was created
  * @param {number} block.index - The index of the monitor
  * @param {string} block.opcode - The opcode of the monitor
  * @param {object} block.params - Extra params to the monitor block
@@ -19,12 +21,15 @@ const isUndefined = a => typeof a === 'undefined';
  * @param {number} y - The monitor y position
  * @return {object} The adapted monitor with label and category
  */
-export default function ({id, index, opcode, params, value, x, y}) {
+export default function ({id, spriteName, index, opcode, params, value, x, y}) {
     let {label, category, labelFn} = OpcodeLabels(opcode);
 
     // Use labelFn if provided for dynamic labelling (e.g. variables)
     if (!isUndefined(labelFn)) label = labelFn(params);
 
+    if (spriteName) {
+        label = `${spriteName}: ${label}`;
+    }
     // Simple layout if x or y are undefined
     // @todo scratch2 has a more complex layout behavior we may want to adopt
     // @todo e.g. this does not work well when monitors have already been moved
-- 
GitLab