mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Convert to node style callback and convert to bitmap resolution 2 always
This commit is contained in:
parent
37f66cc6c5
commit
0258a7390f
2 changed files with 18 additions and 11 deletions
|
@ -6,6 +6,7 @@
|
|||
/.github
|
||||
/.travis.yml
|
||||
/.tx
|
||||
-/test
|
||||
|
||||
# Build created files
|
||||
/playground
|
||||
|
|
|
@ -52,12 +52,14 @@ const loadBitmap_ = function (costume, costumeAsset, runtime, rotationCenter) {
|
|||
};
|
||||
imageElement.addEventListener('error', onError);
|
||||
imageElement.addEventListener('load', onLoad);
|
||||
let src = costumeAsset.encodeDataURI();
|
||||
const src = costumeAsset.encodeDataURI();
|
||||
if (costume.bitmapResolution === 1 && !runtime.v2BitmapAdapter) {
|
||||
log.error('No V2 bitmap adapter present; bitmaps may not render correctly.');
|
||||
} else if (costume.bitmapResolution === 1) {
|
||||
src = runtime.v2BitmapAdapter.convertResolution1Bitmap(src, dataURI => {
|
||||
if (dataURI) {
|
||||
runtime.v2BitmapAdapter.convertResolution1Bitmap(src, (error, dataURI) => {
|
||||
if (error) {
|
||||
log.error(error);
|
||||
} else if (dataURI) {
|
||||
// Put back into storage
|
||||
const storage = runtime.storage;
|
||||
costume.assetId = storage.builtinHelper.cache(
|
||||
|
@ -66,6 +68,9 @@ const loadBitmap_ = function (costume, costumeAsset, runtime, rotationCenter) {
|
|||
runtime.v2BitmapAdapter.convertDataURIToBinary(dataURI)
|
||||
);
|
||||
costume.md5 = `${costume.assetId}.${costume.dataFormat}`;
|
||||
}
|
||||
// Regardless of if conversion succeeds, convert it to bitmap resolution 2,
|
||||
// since all code from here on will assume that.
|
||||
if (rotationCenter) {
|
||||
rotationCenter[0] = rotationCenter[0] * 2;
|
||||
rotationCenter[1] = rotationCenter[1] * 2;
|
||||
|
@ -73,8 +78,9 @@ const loadBitmap_ = function (costume, costumeAsset, runtime, rotationCenter) {
|
|||
costume.rotationCenterY = rotationCenter[1];
|
||||
}
|
||||
costume.bitmapResolution = 2;
|
||||
}
|
||||
imageElement.src = dataURI ? dataURI : src; // Use original src if conversion fails
|
||||
// Use original src if conversion fails.
|
||||
// The image will appear half-sized.
|
||||
imageElement.src = dataURI ? dataURI : src;
|
||||
});
|
||||
} else {
|
||||
imageElement.src = src;
|
||||
|
|
Loading…
Reference in a new issue