mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-07-22 12:09:51 -04:00
Let GQM replace broken costume data but explicitly save and serialize broken costume data before finishing loading the costume.
This commit is contained in:
parent
ca67f4ef4f
commit
deadce3bc6
4 changed files with 31 additions and 7 deletions
src
|
@ -280,11 +280,25 @@ const loadCostumeFromAsset = function (costume, runtime, optVersion) {
|
|||
return loadVector_(costume, runtime, rotationCenter, optVersion)
|
||||
.catch(error => {
|
||||
log.warn(`Error loading vector image: ${error.name}: ${error.message}`);
|
||||
|
||||
// Keep track of the old assetId until we're done loading the default costume
|
||||
const oldAssetId = costume.assetId;
|
||||
const oldRotationX = costume.rotationCenterX;
|
||||
const oldRotationY = costume.rotationCenterY;
|
||||
|
||||
// Use default asset if original fails to load
|
||||
costume.assetId = runtime.storage.defaultAssetId.ImageVector;
|
||||
costume.asset = runtime.storage.get(costume.assetId);
|
||||
costume.md5 = `${costume.assetId}.${AssetType.ImageVector.runtimeFormat}`;
|
||||
return loadVector_(costume, runtime);
|
||||
return loadVector_(costume, runtime).then(loadedCostume => {
|
||||
loadedCostume.broken = {};
|
||||
loadedCostume.broken.assetId = oldAssetId;
|
||||
loadedCostume.broken.md5 = `${oldAssetId}.${AssetType.ImageVector.runtimeFormat}`;
|
||||
loadedCostume.broken.asset = runtime.storage.get(oldAssetId);
|
||||
loadedCostume.broken.rotationCenterX = oldRotationX;
|
||||
loadedCostume.broken.rotationCenterY = oldRotationY;
|
||||
return loadedCostume;
|
||||
});
|
||||
});
|
||||
}
|
||||
return loadBitmap_(costume, runtime, rotationCenter, optVersion);
|
||||
|
|
|
@ -345,7 +345,7 @@ const serializeBlocks = function (blocks) {
|
|||
*/
|
||||
const serializeCostume = function (costume) {
|
||||
const obj = Object.create(null);
|
||||
obj.assetId = costume.assetId;
|
||||
obj.assetId = (costume.broken && costume.broken.assetId) || costume.assetId;
|
||||
obj.name = costume.name;
|
||||
obj.bitmapResolution = costume.bitmapResolution;
|
||||
// serialize this property with the name 'md5ext' because that's
|
||||
|
@ -353,10 +353,11 @@ const serializeCostume = function (costume) {
|
|||
// 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.md5ext = (costume.broken && costume.broken.md5) || costume.md5;
|
||||
obj.dataFormat = costume.dataFormat.toLowerCase();
|
||||
obj.rotationCenterX = costume.rotationCenterX;
|
||||
obj.rotationCenterY = costume.rotationCenterY;
|
||||
// TODO: WATCH OUT FOR ZEROs HERE
|
||||
obj.rotationCenterX = (costume.broken && costume.broken.rotationCenterX) || costume.rotationCenterX;
|
||||
obj.rotationCenterY = (costume.broken && costume.broken.rotationCenterY) || costume.rotationCenterY;
|
||||
return obj;
|
||||
};
|
||||
|
||||
|
|
|
@ -16,10 +16,18 @@ const serializeAssets = function (runtime, assetType, optTargetId) {
|
|||
const currAssets = currTarget.sprite[assetType];
|
||||
for (let j = 0; j < currAssets.length; j++) {
|
||||
const currAsset = currAssets[j];
|
||||
const asset = currAsset.asset;
|
||||
let asset = currAsset.asset;
|
||||
if (currAsset.broken) {
|
||||
if (currAsset.broken.asset) {
|
||||
asset = currAsset.broken.asset;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
assetDescs.push({
|
||||
fileName: `${asset.assetId}.${asset.dataFormat}`,
|
||||
fileContent: asset.data});
|
||||
fileContent: asset.data
|
||||
});
|
||||
}
|
||||
}
|
||||
return assetDescs;
|
||||
|
|
|
@ -932,6 +932,7 @@ class VirtualMachine extends EventEmitter {
|
|||
*/
|
||||
updateSvg (costumeIndex, svg, rotationCenterX, rotationCenterY) {
|
||||
const costume = this.editingTarget.getCostumes()[costumeIndex];
|
||||
if (costume && costume.broken) costume.broken = null;
|
||||
if (costume && this.runtime && this.runtime.renderer) {
|
||||
costume.rotationCenterX = rotationCenterX;
|
||||
costume.rotationCenterY = rotationCenterY;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue