More code cleanup from PR review

This commit is contained in:
Karishma Chadha 2022-05-16 16:23:41 -04:00
parent fd31a777e2
commit 1dfaa02c97
2 changed files with 15 additions and 8 deletions
src/serialization
test/fixtures

View file

@ -345,20 +345,27 @@ const serializeBlocks = function (blocks) {
*/ */
const serializeCostume = function (costume) { const serializeCostume = function (costume) {
const obj = Object.create(null); const obj = Object.create(null);
obj.assetId = (costume.broken && costume.broken.assetId) || costume.assetId;
obj.name = costume.name; obj.name = costume.name;
obj.bitmapResolution = costume.bitmapResolution; obj.bitmapResolution = costume.bitmapResolution;
// serialize this property with the name 'md5ext' because that's
// what it's actually referring to. TODO runtime objects need to be
// updated to actually refer to this as 'md5ext' instead of 'md5'
// but that change should be made carefully since it is very
// pervasive
obj.md5ext = (costume.broken && costume.broken.md5) || costume.md5;
obj.dataFormat = costume.dataFormat.toLowerCase(); obj.dataFormat = costume.dataFormat.toLowerCase();
if (costume.broken) { if (costume.broken) {
obj.assetId = costume.broken.assetId;
// serialize this property with the name 'md5ext' because that's
// what it's actually referring to. TODO runtime objects need to be
// updated to actually refer to this as 'md5ext' instead of 'md5'
// but that change should be made carefully since it is very
// pervasive
obj.md5ext = (costume.broken.md5);
obj.rotationCenterX = costume.broken.rotationCenterX; obj.rotationCenterX = costume.broken.rotationCenterX;
obj.rotationCenterY = costume.broken.rotationCenterY; obj.rotationCenterY = costume.broken.rotationCenterY;
} else { } else {
obj.assetId = costume.assetId;
// See related comment above
obj.md5ext = costume.md5;
obj.rotationCenterX = costume.rotationCenterX; obj.rotationCenterX = costume.rotationCenterX;
obj.rotationCenterY = costume.rotationCenterY; obj.rotationCenterY = costume.rotationCenterY;
} }

View file

@ -7,7 +7,7 @@ module.exports = {
}, },
extractProjectJson: function (path) { extractProjectJson: function (path) {
const zip = new AdmZip(path); const zip = new AdmZip(path);
const projectEntry = zip.getEntries().filter(item => item.entryName.match(/project\.json/))[0]; const projectEntry = zip.getEntries().find(item => item.entryName.match(/project\.json/))[0];
if (projectEntry) { if (projectEntry) {
return JSON.parse(zip.readAsText(projectEntry.entryName, 'utf8')); return JSON.parse(zip.readAsText(projectEntry.entryName, 'utf8'));
} }