Skip to content
Snippets Groups Projects
Commit 74cba7be authored by Ray Schamp's avatar Ray Schamp
Browse files

Revert "Script libraries to process SVG costumes"

This reverts commit 321839ca.
parent 321839ca
Branches
Tags
No related merge requests found
const bindAll = require('lodash.bindall');
const PropTypes = require('prop-types');
const React = require('react');
const Renderer = require('scratch-render');
const Storage = require('../lib/storage');
const VM = require('scratch-vm');
const costumeLibraryContent = require('../lib/libraries/costumes.json');
const LibraryComponent = require('../components/library/library.jsx');
function download (content, contentType, filename) {
const blob = new Blob([content], {type: contentType});
const link = document.createElement('a');
link.download = filename;
link.href = window.URL.createObjectURL(blob);
link.onclick = function () {
setTimeout(() => window.URL.revokeObjectURL(this.href), 10);
};
link.click();
link.remove();
}
class CostumeLibrary extends React.PureComponent {
constructor (props) {
......@@ -27,33 +14,6 @@ class CostumeLibrary extends React.PureComponent {
'handleItemSelected'
]);
}
componentDidMount () {
const storage = new Storage();
Promise.all(costumeLibraryContent.map(costume => {
const [md5, ext] = costume.md5.split('.');
if (ext !== 'svg') return Promise.resolve(costume);
return storage.load(storage.AssetType.ImageVector, md5)
.then(costumeAsset =>
new Promise(resolveSVG => {
const svgRenderer = new Renderer.SVGRenderer();
svgRenderer.fromString(costumeAsset.decodeText(), () => {
resolveSVG(svgRenderer._toString());
});
})
)
.then(svgContents => {
const newMd5 = storage.builtinHelper.cache(
storage.AssetType.ImageVector,
storage.DataFormat.SVG,
svgContents
);
// download(svgContents, 'image/svg+xml', `${newMd5}.svg`);
costume.md5 = `${newMd5}.svg`;
return costume;
});
}))
.then(costumes => download(JSON.stringify(costumes, null, 4), 'application/json', 'costumes.json'));
}
handleItemSelected (item) {
const vmCostume = {
name: item.name,
......
......@@ -2,26 +2,11 @@ const bindAll = require('lodash.bindall');
const PropTypes = require('prop-types');
const React = require('react');
const VM = require('scratch-vm');
const Renderer = require('scratch-render');
const Storage = require('../lib/storage');
const xhr = require('xhr');
const spriteLibraryContent = require('../lib/libraries/sprites.json');
const LibraryComponent = require('../components/library/library.jsx');
function download (content, contentType, filename) {
const blob = new Blob([content], {type: contentType});
const link = document.createElement('a');
link.download = filename;
link.href = window.URL.createObjectURL(blob);
link.onclick = function () {
setTimeout(() => window.URL.revokeObjectURL(this.href), 10);
};
link.click();
link.remove();
}
class SpriteLibrary extends React.PureComponent {
constructor (props) {
super(props);
......@@ -39,40 +24,6 @@ class SpriteLibrary extends React.PureComponent {
sprites: spriteLibraryContent
};
}
componentDidMount () {
const storage = new Storage();
Promise.all(spriteLibraryContent.map(sprite =>
Promise.all(sprite.json.costumes.map(costume => {
const [md5, ext] = costume.baseLayerMD5.split('.');
if (ext !== 'svg') return Promise.resolve(costume);
return storage.load(storage.AssetType.ImageVector, md5)
.then(costumeAsset =>
new Promise(resolveSVG => {
const svgRenderer = new Renderer.SVGRenderer();
svgRenderer.fromString(costumeAsset.decodeText(), () => {
resolveSVG(svgRenderer._toString());
});
})
)
.then(svgContents => {
const newMd5 = storage.builtinHelper.cache(
storage.AssetType.ImageVector,
storage.DataFormat.SVG,
svgContents
);
// download(svgContents, 'image/svg+xml', `${newMd5}.svg`);
costume.baseLayerMD5 = `${newMd5}.svg`;
return costume;
});
}))
.then(costumes => {
sprite.json.costumes = costumes;
if (costumes[0].baseLayerMD5.split('.')[1] === 'svg') sprite.md5 = costumes[0].baseLayerMD5;
return sprite;
})
))
.then(sprites => download(JSON.stringify(sprites, null, 4), 'application/json', 'sprites.json'));
}
componentWillReceiveProps (newProps) {
if (!newProps.visible) clearInterval(this.intervalId);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment