Skip to content
Snippets Groups Projects
Commit 33cb3df1 authored by DD Liu's avatar DD Liu
Browse files

Choose center based on file type and pass array buffer directly to import bitmap

parent 56797b63
Branches
Tags
No related merge requests found
......@@ -26,10 +26,13 @@ class CostumeLibrary extends React.PureComponent {
]);
}
handleItemSelected (item) {
const type = item.md5.split('.')[1];
const rotationCenterX = type === 'svg' ? item.info[0] : item.info[0] / 2;
const rotationCenterY = type === 'svg' ? item.info[1] : item.info[1] / 2;
const vmCostume = {
name: item.name,
rotationCenterX: item.info[0] / 2,
rotationCenterY: item.info[1] / 2,
rotationCenterX,
rotationCenterY,
bitmapResolution: item.info.length > 2 ? item.info[2] : 1,
skinId: null
};
......
......@@ -161,11 +161,14 @@ class CostumeTab extends React.Component {
}
handleSurpriseCostume () {
const item = costumeLibraryContent[Math.floor(Math.random() * costumeLibraryContent.length)];
const type = item.md5.split('.')[1];
const rotationCenterX = type === 'svg' ? item.info[0] : item.info[0] / 2;
const rotationCenterY = type === 'svg' ? item.info[1] : item.info[1] / 2;
const vmCostume = {
name: item.name,
md5: item.md5,
rotationCenterX: item.info[0] / 2,
rotationCenterY: item.info[1] / 2,
rotationCenterX,
rotationCenterY,
bitmapResolution: item.info.length > 2 ? item.info[2] : 1,
skinId: null
};
......
......@@ -132,12 +132,7 @@ const costumeUpload = function (fileData, fileType, costumeName, storage, handle
addCostumeFromBuffer(null, new Uint8Array(fileData));
} else {
// otherwise it's a bitmap
let dataURI = fileData;
if (fileData instanceof ArrayBuffer) {
dataURI = bitmapAdapter.convertBinaryToDataURI(fileData, fileType);
}
// @todo show an error message to user on failure?
bitmapAdapter.importBitmap(dataURI).then(value => addCostumeFromBuffer(value));
bitmapAdapter.importBitmap(fileData, fileType).then(value => addCostumeFromBuffer(value));
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment