mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-06-04 09:33:57 -04:00
Merge pull request #1823 from kchadha/slider-cloud-vars
Request cloud variable update in top level setVariableValue API
This commit is contained in:
commit
87f57c8c95
2 changed files with 35 additions and 0 deletions
|
@ -1410,6 +1410,11 @@ class VirtualMachine extends EventEmitter {
|
|||
const variable = target.lookupVariableById(variableId);
|
||||
if (variable) {
|
||||
variable.value = value;
|
||||
|
||||
if (variable.isCloud) {
|
||||
this.runtime.ioDevices.cloud.requestUpdateVariable(variable.name, variable.value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -667,6 +667,36 @@ test('setVariableValue', t => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
test('setVariableValue requests update for cloud variable', t => {
|
||||
const vm = new VirtualMachine();
|
||||
const spr = new Sprite(null, vm.runtime);
|
||||
const target = spr.createClone();
|
||||
target.isStage = true;
|
||||
target.createVariable('a-variable', 'a-name', Variable.SCALAR_TYPE, true /* isCloud */);
|
||||
|
||||
vm.runtime.targets = [target];
|
||||
|
||||
// Mock cloud io device requestUpdateVariable function
|
||||
let requestUpdateVarWasCalled = false;
|
||||
let varName;
|
||||
let varValue;
|
||||
vm.runtime.ioDevices.cloud.requestUpdateVariable = (name, value) => {
|
||||
requestUpdateVarWasCalled = true;
|
||||
varName = name;
|
||||
varValue = value;
|
||||
};
|
||||
|
||||
vm.setVariableValue(target.id, 'not-a-variable', 100);
|
||||
t.equal(requestUpdateVarWasCalled, false);
|
||||
|
||||
vm.setVariableValue(target.id, 'a-variable', 100);
|
||||
t.equal(requestUpdateVarWasCalled, true);
|
||||
t.equal(varName, 'a-name');
|
||||
t.equal(varValue, 100);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('getVariableValue', t => {
|
||||
const vm = new VirtualMachine();
|
||||
const spr = new Sprite(null, vm.runtime);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue