From aa200e6df331a83a3a2d58cd5ff28f7c680cdc4d Mon Sep 17 00:00:00 2001 From: Karishma Chadha <kchadha@media.mit.edu> Date: Mon, 29 Oct 2018 00:59:06 -0400 Subject: [PATCH] Set the cloud provider and request updates to the cloud var when updating the variable through blocks. --- src/blocks/scratch3_data.js | 11 ++++++++++- src/virtual-machine.js | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/blocks/scratch3_data.js b/src/blocks/scratch3_data.js index 9ebd3712c..78191c5dd 100644 --- a/src/blocks/scratch3_data.js +++ b/src/blocks/scratch3_data.js @@ -45,6 +45,10 @@ class Scratch3DataBlocks { const variable = util.target.lookupOrCreateVariable( args.VARIABLE.id, args.VARIABLE.name); variable.value = args.VALUE; + + if (variable.isCloud) { + util.ioQuery('cloud', 'requestUpdateVariable', [variable.name, args.VALUE]); + } } changeVariableBy (args, util) { @@ -52,7 +56,12 @@ class Scratch3DataBlocks { args.VARIABLE.id, args.VARIABLE.name); const castedValue = Cast.toNumber(variable.value); const dValue = Cast.toNumber(args.VALUE); - variable.value = castedValue + dValue; + const newValue = castedValue + dValue; + variable.value = newValue; + + if (variable.isCloud) { + util.ioQuery('cloud', 'requestUpdateVariable', [variable.name, newValue]); + } } changeMonitorVisibility (id, visible) { diff --git a/src/virtual-machine.js b/src/virtual-machine.js index 96ab30411..b5f16c654 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -218,6 +218,10 @@ class VirtualMachine extends EventEmitter { this.runtime.ioDevices.video.setProvider(videoProvider); } + setCloudProvider (cloudProvider) { + this.runtime.ioDevices.cloud.setProvider(cloudProvider); + } + /** * Tell the specified extension to scan for a peripheral. * @param {string} extensionId - the id of the extension. @@ -463,6 +467,7 @@ class VirtualMachine extends EventEmitter { this.emitTargetsUpdate(); this.emitWorkspaceUpdate(); this.runtime.setEditingTarget(this.editingTarget); + this.runtime.ioDevices.cloud.setStage(this.runtime.getTargetForStage()); }); }