mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-25 17:09:50 -05:00
When serializing md5+ext, the name should reflect that. Deserializing translates this name back to what vm and other components currently expect.
This commit is contained in:
parent
24e248d4fb
commit
9d3a3fd12f
3 changed files with 53 additions and 11 deletions
|
@ -224,9 +224,16 @@ const parseScratchObject = function (object, runtime, extensions, topLevel) {
|
||||||
bitmapResolution: costumeSource.bitmapResolution || 1,
|
bitmapResolution: costumeSource.bitmapResolution || 1,
|
||||||
rotationCenterX: costumeSource.rotationCenterX,
|
rotationCenterX: costumeSource.rotationCenterX,
|
||||||
rotationCenterY: costumeSource.rotationCenterY,
|
rotationCenterY: costumeSource.rotationCenterY,
|
||||||
|
// TODO we eventually want this next property to be called
|
||||||
|
// md5ext to reflect what it actually contains, however this
|
||||||
|
// will be a very extensive change across many repositories
|
||||||
|
// and should be done carefully and altogether
|
||||||
|
md5: costumeSource.baseLayerMD5,
|
||||||
skinId: null
|
skinId: null
|
||||||
};
|
};
|
||||||
costumePromises.push(loadCostume(costumeSource.baseLayerMD5, costume, runtime));
|
// TODO need to add deserializeCostume here so that assets from
|
||||||
|
// actual .sb2s get loaded in
|
||||||
|
costumePromises.push(loadCostume(costume.md5, costume, runtime));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Sounds from JSON
|
// Sounds from JSON
|
||||||
|
@ -240,9 +247,17 @@ const parseScratchObject = function (object, runtime, extensions, topLevel) {
|
||||||
rate: soundSource.rate,
|
rate: soundSource.rate,
|
||||||
sampleCount: soundSource.sampleCount,
|
sampleCount: soundSource.sampleCount,
|
||||||
soundID: soundSource.soundID,
|
soundID: soundSource.soundID,
|
||||||
|
// TODO we eventually want this next property to be called
|
||||||
|
// md5ext to reflect what it actually contains, however this
|
||||||
|
// will be a very extensive change across many repositories
|
||||||
|
// and should be done carefully and altogether
|
||||||
|
// (for example, the audio engine currently relies on this
|
||||||
|
// property to be named 'md5')
|
||||||
md5: soundSource.md5,
|
md5: soundSource.md5,
|
||||||
data: null
|
data: null
|
||||||
};
|
};
|
||||||
|
// TODO need to add deserializeSound here so that assets from
|
||||||
|
// actual .sb2s get loaded in
|
||||||
soundPromises.push(loadSound(sound, runtime));
|
soundPromises.push(loadSound(sound, runtime));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,12 @@ const serializeCostume = function (costume) {
|
||||||
obj.assetId = costume.assetId;
|
obj.assetId = costume.assetId;
|
||||||
obj.name = costume.name;
|
obj.name = costume.name;
|
||||||
obj.bitmapResolution = costume.bitmapResolution;
|
obj.bitmapResolution = costume.bitmapResolution;
|
||||||
|
// serialize this property with the name 'md5ext' because that's
|
||||||
|
// what it's actually referring to. TODO runtime objects need to be
|
||||||
|
// updated to actually refer to this as 'md5ext' instead of 'md5'
|
||||||
|
// but that change should be made carefully since it is very
|
||||||
|
// pervasive
|
||||||
|
obj.md5ext = costume.md5;
|
||||||
obj.dataFormat = costume.dataFormat;
|
obj.dataFormat = costume.dataFormat;
|
||||||
obj.rotationCenterX = costume.rotationCenterX;
|
obj.rotationCenterX = costume.rotationCenterX;
|
||||||
obj.rotationCenterY = costume.rotationCenterY;
|
obj.rotationCenterY = costume.rotationCenterY;
|
||||||
|
@ -76,8 +82,12 @@ const serializeSound = function (sound) {
|
||||||
obj.format = sound.format;
|
obj.format = sound.format;
|
||||||
obj.rate = sound.rate;
|
obj.rate = sound.rate;
|
||||||
obj.sampleCount = sound.sampleCount;
|
obj.sampleCount = sound.sampleCount;
|
||||||
// TODO eventually want to get rid of this
|
// serialize this property with the name 'md5ext' because that's
|
||||||
obj.md5 = sound.md5;
|
// what it's actually referring to. TODO runtime objects need to be
|
||||||
|
// updated to actually refer to this as 'md5ext' instead of 'md5'
|
||||||
|
// but that change should be made carefully since it is very
|
||||||
|
// pervasive
|
||||||
|
obj.md5ext = sound.md5;
|
||||||
// TODO do we need this soundID
|
// TODO do we need this soundID
|
||||||
// (not to be confused with soundId which is a uid for sounds)
|
// (not to be confused with soundId which is a uid for sounds)
|
||||||
// obj.soundID = sound.soundID;
|
// obj.soundID = sound.soundID;
|
||||||
|
@ -176,6 +186,7 @@ const parseScratchObject = function (object, runtime, extensions, zip) {
|
||||||
const costumePromises = (object.costumes || []).map(costumeSource => {
|
const costumePromises = (object.costumes || []).map(costumeSource => {
|
||||||
// @todo: Make sure all the relevant metadata is being pulled out.
|
// @todo: Make sure all the relevant metadata is being pulled out.
|
||||||
const costume = {
|
const costume = {
|
||||||
|
assetId: costumeSource.assetId,
|
||||||
skinId: null,
|
skinId: null,
|
||||||
name: costumeSource.name,
|
name: costumeSource.name,
|
||||||
bitmapResolution: costumeSource.bitmapResolution,
|
bitmapResolution: costumeSource.bitmapResolution,
|
||||||
|
@ -186,24 +197,41 @@ const parseScratchObject = function (object, runtime, extensions, zip) {
|
||||||
costumeSource.dataFormat ||
|
costumeSource.dataFormat ||
|
||||||
(costumeSource.assetType && costumeSource.assetType.runtimeFormat) || // older format
|
(costumeSource.assetType && costumeSource.assetType.runtimeFormat) || // older format
|
||||||
'png'; // if all else fails, guess that it might be a PNG
|
'png'; // if all else fails, guess that it might be a PNG
|
||||||
const costumeMd5 = `${costumeSource.assetId}.${dataFormat}`;
|
const costumeMd5Ext = costumeSource.hasOwnProperty('md5ext') ?
|
||||||
costume.md5 = costumeMd5;
|
costumeSource.md5ext : `${costumeSource.assetId}.${dataFormat}`;
|
||||||
return deserializeCostume(costumeSource, runtime, zip)
|
costume.md5 = costumeMd5Ext;
|
||||||
.then(() => loadCostume(costumeMd5, costume, runtime));
|
costume.dataFormat = dataFormat;
|
||||||
|
// deserializeCostume should be called on the costume object we're
|
||||||
|
// creating above instead of the source costume object, because this way
|
||||||
|
// we're always loading the 'sb3' representation of the costume
|
||||||
|
// any translation that needs to happen will happen in the process
|
||||||
|
// of building up the costume object into an sb3 format
|
||||||
|
return deserializeCostume(costume, runtime, zip)
|
||||||
|
.then(() => loadCostume(costumeMd5Ext, costume, runtime));
|
||||||
// Only attempt to load the costume after the deserialization
|
// Only attempt to load the costume after the deserialization
|
||||||
// process has been completed
|
// process has been completed
|
||||||
});
|
});
|
||||||
// Sounds from JSON
|
// Sounds from JSON
|
||||||
const soundPromises = (object.sounds || []).map(soundSource => {
|
const soundPromises = (object.sounds || []).map(soundSource => {
|
||||||
const sound = {
|
const sound = {
|
||||||
|
assetId: soundSource.assetId,
|
||||||
format: soundSource.format,
|
format: soundSource.format,
|
||||||
rate: soundSource.rate,
|
rate: soundSource.rate,
|
||||||
sampleCount: soundSource.sampleCount,
|
sampleCount: soundSource.sampleCount,
|
||||||
name: soundSource.name,
|
name: soundSource.name,
|
||||||
md5: soundSource.md5,
|
// TODO we eventually want this property to be called md5ext,
|
||||||
|
// but there are many things relying on this particular name at the
|
||||||
|
// moment, so this translation is very important
|
||||||
|
md5: soundSource.md5ext,
|
||||||
|
dataFormat: soundSource.dataFormat,
|
||||||
data: null
|
data: null
|
||||||
};
|
};
|
||||||
return deserializeSound(soundSource, runtime, zip)
|
// deserializeSound should be called on the sound object we're
|
||||||
|
// creating above instead of the source sound object, because this way
|
||||||
|
// we're always loading the 'sb3' representation of the costume
|
||||||
|
// any translation that needs to happen will happen in the process
|
||||||
|
// of building up the costume object into an sb3 format
|
||||||
|
return deserializeSound(sound, runtime, zip)
|
||||||
.then(() => loadSound(sound, runtime));
|
.then(() => loadSound(sound, runtime));
|
||||||
// Only attempt to load the sound after the deserialization
|
// Only attempt to load the sound after the deserialization
|
||||||
// process has been completed.
|
// process has been completed.
|
||||||
|
|
|
@ -19,8 +19,7 @@ const serializeAssets = function (runtime, assetType) {
|
||||||
const storage = runtime.storage;
|
const storage = runtime.storage;
|
||||||
const storedAsset = storage.get(assetId);
|
const storedAsset = storage.get(assetId);
|
||||||
assetDescs.push({
|
assetDescs.push({
|
||||||
fileName: currAsset.md5 ?
|
fileName: `${assetId}.${storedAsset.dataFormat}`,
|
||||||
currAsset.md5 : `${assetId}.${storedAsset.dataFormat}`,
|
|
||||||
fileContent: storedAsset.data});
|
fileContent: storedAsset.data});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue