Merge pull request #890 from fsih/dropdownMonitor

Update monitor on dropdown change
This commit is contained in:
DD Liu 2018-01-11 12:09:28 -05:00 committed by GitHub
commit dfe4cc1e55
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 11 deletions

View file

@ -244,9 +244,8 @@ class Scratch3LooksBlocks {
getMonitored () {
return {
looks_size: {isSpriteSpecific: true},
looks_costumeorder: {isSpriteSpecific: true},
looks_backdroporder: {},
looks_backdropname: {}
looks_costumenumbername: {isSpriteSpecific: true},
looks_backdropnumbername: {}
};
}

View file

@ -56,7 +56,6 @@ class Scratch3SensingBlocks {
sensing_answer: {},
sensing_loudness: {},
sensing_timer: {},
sensing_of: {},
sensing_current: {}
};
}

View file

@ -3,6 +3,7 @@ const mutationAdapter = require('./mutation-adapter');
const xmlEscape = require('../util/xml-escape');
const MonitorRecord = require('./monitor-record');
const Clone = require('../util/clone');
const {Map} = require('immutable');
/**
* @fileoverview
@ -382,22 +383,38 @@ class Blocks {
block.fields[args.name].id = args.value;
}
} else {
// Changing the value in a dropdown
block.fields[args.name].value = args.value;
if (!optRuntime){
break;
}
const flyoutBlock = block.shadow && block.parent ? this._blocks[block.parent] : block;
if (flyoutBlock.isMonitored) {
optRuntime.requestUpdateMonitor(Map({
id: flyoutBlock.id,
params: this._getBlockParams(flyoutBlock)
}));
}
}
break;
case 'mutation':
block.mutation = mutationAdapter(args.value);
break;
case 'checkbox':
case 'checkbox': {
block.isMonitored = args.value;
if (optRuntime) {
const isSpriteSpecific = optRuntime.monitorBlockInfo.hasOwnProperty(block.opcode) &&
optRuntime.monitorBlockInfo[block.opcode].isSpriteSpecific;
block.targetId = isSpriteSpecific ? optRuntime.getEditingTarget().id : null;
if (!optRuntime) {
break;
}
if (optRuntime && wasMonitored && !block.isMonitored) {
const isSpriteSpecific = optRuntime.monitorBlockInfo.hasOwnProperty(block.opcode) &&
optRuntime.monitorBlockInfo[block.opcode].isSpriteSpecific;
block.targetId = isSpriteSpecific ? optRuntime.getEditingTarget().id : null;
if (wasMonitored && !block.isMonitored) {
optRuntime.requestRemoveMonitor(block.id);
} else if (optRuntime && !wasMonitored && block.isMonitored) {
} else if (!wasMonitored && block.isMonitored) {
optRuntime.requestAddMonitor(MonitorRecord({
// @todo(vm#564) this will collide if multiple sprites use same block
id: block.id,
@ -411,6 +428,7 @@ class Blocks {
}
break;
}
}
this.resetCache();
}