mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-11 10:39:56 -05:00
Why do our lint rules require such weird formatting
This commit is contained in:
parent
998c5a186e
commit
2bd468950f
2 changed files with 42 additions and 44 deletions
|
@ -86,8 +86,7 @@ const fetchBitmapCanvas_ = function (costume, rotationCenter) {
|
||||||
loadedOne = true;
|
loadedOne = true;
|
||||||
}
|
}
|
||||||
baseImageElement.src = costume.asset.encodeDataURI();
|
baseImageElement.src = costume.asset.encodeDataURI();
|
||||||
})
|
}).then(imageElements => {
|
||||||
.then(imageElements => {
|
|
||||||
const [baseImageElement, textImageElement] = imageElements;
|
const [baseImageElement, textImageElement] = imageElements;
|
||||||
|
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
|
@ -118,12 +117,12 @@ const fetchBitmapCanvas_ = function (costume, rotationCenter) {
|
||||||
assetMatchesBase: scale !== 1 || textImageElement.src
|
assetMatchesBase: scale !== 1 || textImageElement.src
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.catch(e => Promise.reject(e))
|
.catch(e => Promise.reject(e))
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
// Clean up the costume object
|
// Clean up the costume object
|
||||||
delete costume.textLayerMD5;
|
delete costume.textLayerMD5;
|
||||||
delete costume.textLayerAsset;
|
delete costume.textLayerAsset;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadBitmap_ = function (costume, runtime, rotationCenter) {
|
const loadBitmap_ = function (costume, runtime, rotationCenter) {
|
||||||
|
@ -148,22 +147,22 @@ const loadBitmap_ = function (costume, runtime, rotationCenter) {
|
||||||
}
|
}
|
||||||
resolve(fetched.canvas);
|
resolve(fetched.canvas);
|
||||||
}))
|
}))
|
||||||
.catch(e => Promise.reject(e))
|
.catch(e => Promise.reject(e))
|
||||||
.then(canvas => {
|
.then(canvas => {
|
||||||
// createBitmapSkin does the right thing if costume.bitmapResolution or rotationCenter are undefined...
|
// createBitmapSkin does the right thing if costume.bitmapResolution or rotationCenter are undefined...
|
||||||
costume.skinId = runtime.renderer.createBitmapSkin(canvas, costume.bitmapResolution, rotationCenter);
|
costume.skinId = runtime.renderer.createBitmapSkin(canvas, costume.bitmapResolution, rotationCenter);
|
||||||
const renderSize = runtime.renderer.getSkinSize(costume.skinId);
|
const renderSize = runtime.renderer.getSkinSize(costume.skinId);
|
||||||
costume.size = [renderSize[0] * 2, renderSize[1] * 2]; // Actual size, since all bitmaps are resolution 2
|
costume.size = [renderSize[0] * 2, renderSize[1] * 2]; // Actual size, since all bitmaps are resolution 2
|
||||||
|
|
||||||
if (!rotationCenter) {
|
if (!rotationCenter) {
|
||||||
rotationCenter = runtime.renderer.getSkinRotationCenter(costume.skinId);
|
rotationCenter = runtime.renderer.getSkinRotationCenter(costume.skinId);
|
||||||
// Actual rotation center, since all bitmaps are resolution 2
|
// Actual rotation center, since all bitmaps are resolution 2
|
||||||
costume.rotationCenterX = rotationCenter[0] * 2;
|
costume.rotationCenterX = rotationCenter[0] * 2;
|
||||||
costume.rotationCenterY = rotationCenter[1] * 2;
|
costume.rotationCenterY = rotationCenter[1] * 2;
|
||||||
costume.bitmapResolution = 2;
|
costume.bitmapResolution = 2;
|
||||||
}
|
}
|
||||||
return costume;
|
return costume;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -81,8 +81,7 @@ const deserializeCostume = function (costume, runtime, zip, assetFileName, textL
|
||||||
costume.asset.dataFormat,
|
costume.asset.dataFormat,
|
||||||
new Uint8Array(Object.keys(costume.asset.data).map(key => costume.asset.data[key])),
|
new Uint8Array(Object.keys(costume.asset.data).map(key => costume.asset.data[key])),
|
||||||
costume.asset.assetId
|
costume.asset.assetId
|
||||||
))
|
)).then(asset => {
|
||||||
.then(asset => {
|
|
||||||
costume.asset = asset;
|
costume.asset = asset;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -123,31 +122,31 @@ const deserializeCostume = function (costume, runtime, zip, assetFileName, textL
|
||||||
return Promise.resolve(null);
|
return Promise.resolve(null);
|
||||||
}
|
}
|
||||||
textLayerFilePromise = textLayerFile.async('uint8array')
|
textLayerFilePromise = textLayerFile.async('uint8array')
|
||||||
.then(data => storage.createAsset(
|
.then(data => storage.createAsset(
|
||||||
storage.AssetType.ImageBitmap,
|
storage.AssetType.ImageBitmap,
|
||||||
'png',
|
'png',
|
||||||
data,
|
data,
|
||||||
costume.textLayerMD5
|
costume.textLayerMD5
|
||||||
))
|
))
|
||||||
.then(asset => {
|
.then(asset => {
|
||||||
costume.textLayerAsset = asset;
|
costume.textLayerAsset = asset;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
textLayerFilePromise = Promise.resolve(null);
|
textLayerFilePromise = Promise.resolve(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.all([textLayerFilePromise,
|
return Promise.all([textLayerFilePromise,
|
||||||
costumeFile.async('uint8array')
|
costumeFile.async('uint8array')
|
||||||
.then(data => storage.createAsset(
|
.then(data => storage.createAsset(
|
||||||
assetType,
|
assetType,
|
||||||
// TODO eventually we want to map non-png's to their actual file types?
|
// TODO eventually we want to map non-png's to their actual file types?
|
||||||
costumeFormat,
|
costumeFormat,
|
||||||
data,
|
data,
|
||||||
assetId
|
assetId
|
||||||
))
|
))
|
||||||
.then(asset => {
|
.then(asset => {
|
||||||
costume.asset = asset;
|
costume.asset = asset;
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue