From ce629bc4f4bdbd1d4cb6e3575051d278df949ad6 Mon Sep 17 00:00:00 2001
From: Christopher Willis-Ford <cwillisf@media.mit.edu>
Date: Fri, 7 Sep 2018 12:18:19 -0700
Subject: [PATCH] Attempt to get monitor labels from VM

---
 src/containers/monitor.jsx | 5 ++++-
 src/lib/monitor-adapter.js | 5 +++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/containers/monitor.jsx b/src/containers/monitor.jsx
index b39358c08..2f04cb51b 100644
--- a/src/containers/monitor.jsx
+++ b/src/containers/monitor.jsx
@@ -7,6 +7,7 @@ import MonitorComponent, {monitorModes} from '../components/monitor/monitor.jsx'
 import {addMonitorRect, getInitialPosition, resizeMonitorRect, removeMonitorRect} from '../reducers/monitor-layout';
 
 import {connect} from 'react-redux';
+import VM from 'scratch-vm';
 
 const availableModes = opcode => (
     monitorModes.filter(t => {
@@ -147,12 +148,14 @@ Monitor.propTypes = {
             PropTypes.number
         ]))
     ]), // eslint-disable-line react/no-unused-prop-types
+    vm: PropTypes.instanceOf(VM),
     width: PropTypes.number,
     x: PropTypes.number,
     y: PropTypes.number
 };
 const mapStateToProps = state => ({
-    monitorLayout: state.scratchGui.monitorLayout
+    monitorLayout: state.scratchGui.monitorLayout,
+    vm: state.scratchGui.vm
 });
 const mapDispatchToProps = dispatch => ({
     addMonitorRect: (id, rect, savePosition) =>
diff --git a/src/lib/monitor-adapter.js b/src/lib/monitor-adapter.js
index d7bdd304e..3f9b199d7 100644
--- a/src/lib/monitor-adapter.js
+++ b/src/lib/monitor-adapter.js
@@ -11,10 +11,11 @@ const isUndefined = a => typeof a === 'undefined';
  * @param {string} block.opcode - The opcode of the monitor
  * @param {object} block.params - Extra params to the monitor block
  * @param {string|number|Array} block.value - The monitor value
+ * @param {VirtualMachine} block.vm - the VM instance which owns the block
  * @return {object} The adapted monitor with label and category
  */
-export default function ({id, spriteName, opcode, params, value}) {
-    let {label, category, labelFn} = OpcodeLabels(opcode);
+export default function ({id, spriteName, opcode, params, value, vm}) {
+    let {label, category, labelFn} = (vm && vm.runtime.getLabelForOpcode(opcode)) || OpcodeLabels(opcode);
 
     // Use labelFn if provided for dynamic labelling (e.g. variables)
     if (!isUndefined(labelFn)) label = labelFn(params);
-- 
GitLab