Deserialize tempo, volume, and video related state.

This commit is contained in:
Karishma Chadha 2018-04-04 18:54:05 -04:00
parent 80499c9ae5
commit 6c0d257a63

View file

@ -345,8 +345,12 @@ const serializeTarget = function (target) {
obj.currentCostume = target.currentCostume; obj.currentCostume = target.currentCostume;
obj.costumes = target.costumes.map(serializeCostume); obj.costumes = target.costumes.map(serializeCostume);
obj.sounds = target.sounds.map(serializeSound); obj.sounds = target.sounds.map(serializeSound);
if (!obj.isStage) { if (target.hasOwnProperty('volume')) obj.volume = target.volume;
// Stage does not need the following properties if (obj.isStage) { // Only the stage should have these properties
if (target.hasOwnProperty('tempo')) obj.tempo = target.tempo;
if (target.hasOwnProperty('videoTransparency')) obj.videoTransparency = target.videoTransparency;
if (target.hasOwnProperty('videoState')) obj.videoState = target.videoState;
} else { // The stage does not need the following properties, but sprites should
obj.visible = target.visible; obj.visible = target.visible;
obj.x = target.x; obj.x = target.x;
obj.y = target.y; obj.y = target.y;
@ -700,6 +704,18 @@ const parseScratchObject = function (object, runtime, extensions, zip) {
// Create the first clone, and load its run-state from JSON. // Create the first clone, and load its run-state from JSON.
const target = sprite.createClone(); const target = sprite.createClone();
// Load target properties from JSON. // Load target properties from JSON.
if (object.hasOwnProperty('tempo')) {
target.tempo = object.tempo;
}
if (object.hasOwnProperty('volume')) {
target.volume = object.volume;
}
if (object.hasOwnProperty('videoTransparency')) {
target.videoTransparency = object.videoTransparency;
}
if (object.hasOwnProperty('videoState')) {
target.videoState = object.videoState;
}
if (object.hasOwnProperty('variables')) { if (object.hasOwnProperty('variables')) {
for (const varId in object.variables) { for (const varId in object.variables) {
const variable = object.variables[varId]; const variable = object.variables[varId];