mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-11 10:39:56 -05:00
Merge pull request #1840 from ktbee/default-asset-for-broken-svg
Use default builtin SVG asset when an SVG can't be loaded
This commit is contained in:
commit
3dcee7b1ad
1 changed files with 39 additions and 26 deletions
|
@ -2,6 +2,7 @@ const StringUtil = require('../util/string-util');
|
|||
const log = require('../util/log');
|
||||
|
||||
const loadVector_ = function (costume, runtime, rotationCenter, optVersion) {
|
||||
return new Promise(resolve => {
|
||||
let svgString = costume.asset.decodeText();
|
||||
// SVG Renderer load fixes "quirks" associated with Scratch 2 projects
|
||||
if (optVersion && optVersion === 2 && !runtime.v2SvgAdapter) {
|
||||
|
@ -27,7 +28,8 @@ const loadVector_ = function (costume, runtime, rotationCenter, optVersion) {
|
|||
costume.bitmapResolution = 1;
|
||||
}
|
||||
|
||||
return Promise.resolve(costume);
|
||||
resolve(costume);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -212,7 +214,13 @@ const loadCostumeFromAsset = function (costume, runtime, optVersion) {
|
|||
rotationCenter = [costume.rotationCenterX, costume.rotationCenterY];
|
||||
}
|
||||
if (costume.asset.assetType.runtimeFormat === AssetType.ImageVector.runtimeFormat) {
|
||||
return loadVector_(costume, runtime, rotationCenter, optVersion);
|
||||
return loadVector_(costume, runtime, rotationCenter, optVersion)
|
||||
.catch(() => {
|
||||
// Use default asset if original fails to load
|
||||
costume.assetId = runtime.storage.defaultAssetId.ImageVector;
|
||||
costume.asset = runtime.storage.get(costume.assetId);
|
||||
return loadVector_(costume, runtime);
|
||||
});
|
||||
}
|
||||
return loadBitmap_(costume, runtime, rotationCenter, optVersion);
|
||||
};
|
||||
|
@ -248,6 +256,11 @@ const loadCostume = function (md5ext, costume, runtime, optVersion) {
|
|||
return Promise.resolve(costume);
|
||||
}
|
||||
|
||||
if (!runtime.storage.defaultAssetId) {
|
||||
log.error(`No default assets found`);
|
||||
return Promise.resolve(costume);
|
||||
}
|
||||
|
||||
const AssetType = runtime.storage.AssetType;
|
||||
const assetType = (ext === 'svg') ? AssetType.ImageVector : AssetType.ImageBitmap;
|
||||
|
||||
|
|
Loading…
Reference in a new issue