From 33cb3df1a183ad94f6f2863c74a2d1ee6b5cb12f Mon Sep 17 00:00:00 2001 From: DD Liu <liudi@media.mit.edu> Date: Thu, 12 Jul 2018 15:05:02 -0400 Subject: [PATCH] Choose center based on file type and pass array buffer directly to import bitmap --- src/containers/costume-library.jsx | 7 +++++-- src/containers/costume-tab.jsx | 7 +++++-- src/lib/file-uploader.js | 7 +------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/containers/costume-library.jsx b/src/containers/costume-library.jsx index 0de5fba13..c4884c169 100644 --- a/src/containers/costume-library.jsx +++ b/src/containers/costume-library.jsx @@ -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 }; diff --git a/src/containers/costume-tab.jsx b/src/containers/costume-tab.jsx index 9cd10ec8b..34b64a2ff 100644 --- a/src/containers/costume-tab.jsx +++ b/src/containers/costume-tab.jsx @@ -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 }; diff --git a/src/lib/file-uploader.js b/src/lib/file-uploader.js index 2df9f8593..785b85d43 100644 --- a/src/lib/file-uploader.js +++ b/src/lib/file-uploader.js @@ -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)); } }; -- GitLab