Merge pull request #373 from paulkaplan/updating-block-numbers
Update shadow block values when sprite moves
This commit is contained in:
commit
7d905c2ea0
2 files changed
+23
-1
No files matched your search
@@ -39,6 +39,7 @@
|
||||
"gh-pages": "^1.0.0",
|
||||
"html-webpack-plugin": "2.28.0",
|
||||
"lodash.bindall": "4.4.0",
|
||||
"lodash.debounce": "4.0.8",
|
||||
"lodash.defaultsdeep": "4.6.0",
|
||||
"lodash.isequal": "4.5.0",
|
||||
"lodash.omit": "4.5.0",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
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) {
|
||||
|
||||
Reference in new issue
Block a user