Skip to content
Snippets Groups Projects
Commit 7d905c2e authored by Paul Kaplan's avatar Paul Kaplan Committed by GitHub
Browse files

Merge pull request #373 from paulkaplan/updating-block-numbers

Update shadow block values when sprite moves
parents 488ba96a a5b4be08
No related branches found
No related tags found
No related merge requests found
const bindAll = require('lodash.bindall');
const debounce = require('lodash.debounce');
const defaultsDeep = require('lodash.defaultsdeep');
const PropTypes = require('prop-types');
const React = require('react');
......@@ -30,6 +31,7 @@ class Blocks extends React.Component {
'onScriptGlowOff',
'onBlockGlowOn',
'onBlockGlowOff',
'onTargetsUpdate',
'onVisualReport',
'onWorkspaceUpdate',
'onWorkspaceMetricsChange',
......@@ -40,6 +42,7 @@ class Blocks extends React.Component {
workspaceMetrics: {},
prompt: null
};
this.onTargetsUpdate = debounce(this.onTargetsUpdate, 100);
}
componentDidMount () {
const workspaceConfig = defaultsDeep({}, Blocks.defaultOptions, this.props.options);
......@@ -85,6 +88,7 @@ class Blocks extends React.Component {
this.props.vm.addListener('BLOCK_GLOW_OFF', this.onBlockGlowOff);
this.props.vm.addListener('VISUAL_REPORT', this.onVisualReport);
this.props.vm.addListener('workspaceUpdate', this.onWorkspaceUpdate);
this.props.vm.addListener('targetsUpdate', this.onTargetsUpdate);
}
detachVM () {
this.props.vm.removeListener('SCRIPT_GLOW_ON', this.onScriptGlowOn);
......@@ -93,8 +97,25 @@ class Blocks extends React.Component {
this.props.vm.removeListener('BLOCK_GLOW_OFF', this.onBlockGlowOff);
this.props.vm.removeListener('VISUAL_REPORT', this.onVisualReport);
this.props.vm.removeListener('workspaceUpdate', this.onWorkspaceUpdate);
this.props.vm.removeListener('targetsUpdate', this.onTargetsUpdate);
}
updateToolboxBlockValue (id, value) {
this.workspace
.getFlyout()
.getWorkspace()
.getBlockById(id)
.inputList[0]
.fieldRow[0]
.setValue(value);
}
onTargetsUpdate () {
if (this.props.vm.editingTarget) {
['glide', 'move', 'set'].forEach(prefix => {
this.updateToolboxBlockValue(`${prefix}x`, this.props.vm.editingTarget.x.toFixed(0));
this.updateToolboxBlockValue(`${prefix}y`, this.props.vm.editingTarget.y.toFixed(0));
});
}
}
onWorkspaceMetricsChange () {
const target = this.props.vm.editingTarget;
if (target && target.id) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment