Convert to node style callback and convert to bitmap resolution 2 always

This commit is contained in:
DD Liu 2018-07-12 14:33:38 -04:00
parent 37f66cc6c5
commit 0258a7390f
2 changed files with 18 additions and 11 deletions

View file

@ -6,6 +6,7 @@
/.github /.github
/.travis.yml /.travis.yml
/.tx /.tx
-/test
# Build created files # Build created files
/playground /playground

View file

@ -52,12 +52,14 @@ const loadBitmap_ = function (costume, costumeAsset, runtime, rotationCenter) {
}; };
imageElement.addEventListener('error', onError); imageElement.addEventListener('error', onError);
imageElement.addEventListener('load', onLoad); imageElement.addEventListener('load', onLoad);
let src = costumeAsset.encodeDataURI(); const src = costumeAsset.encodeDataURI();
if (costume.bitmapResolution === 1 && !runtime.v2BitmapAdapter) { if (costume.bitmapResolution === 1 && !runtime.v2BitmapAdapter) {
log.error('No V2 bitmap adapter present; bitmaps may not render correctly.'); log.error('No V2 bitmap adapter present; bitmaps may not render correctly.');
} else if (costume.bitmapResolution === 1) { } else if (costume.bitmapResolution === 1) {
src = runtime.v2BitmapAdapter.convertResolution1Bitmap(src, dataURI => { runtime.v2BitmapAdapter.convertResolution1Bitmap(src, (error, dataURI) => {
if (dataURI) { if (error) {
log.error(error);
} else if (dataURI) {
// Put back into storage // Put back into storage
const storage = runtime.storage; const storage = runtime.storage;
costume.assetId = storage.builtinHelper.cache( costume.assetId = storage.builtinHelper.cache(
@ -66,6 +68,9 @@ const loadBitmap_ = function (costume, costumeAsset, runtime, rotationCenter) {
runtime.v2BitmapAdapter.convertDataURIToBinary(dataURI) runtime.v2BitmapAdapter.convertDataURIToBinary(dataURI)
); );
costume.md5 = `${costume.assetId}.${costume.dataFormat}`; 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) { if (rotationCenter) {
rotationCenter[0] = rotationCenter[0] * 2; rotationCenter[0] = rotationCenter[0] * 2;
rotationCenter[1] = rotationCenter[1] * 2; rotationCenter[1] = rotationCenter[1] * 2;
@ -73,8 +78,9 @@ const loadBitmap_ = function (costume, costumeAsset, runtime, rotationCenter) {
costume.rotationCenterY = rotationCenter[1]; costume.rotationCenterY = rotationCenter[1];
} }
costume.bitmapResolution = 2; costume.bitmapResolution = 2;
} // Use original src if conversion fails.
imageElement.src = dataURI ? dataURI : src; // Use original src if conversion fails // The image will appear half-sized.
imageElement.src = dataURI ? dataURI : src;
}); });
} else { } else {
imageElement.src = src; imageElement.src = src;