diff --git a/src/components/library/library.jsx b/src/components/library/library.jsx index 1272cb4a17659f0649c5495b005c6e1b255fac36..3cbc9805da0ca5971f938337937057115640a8da 100644 --- a/src/components/library/library.jsx +++ b/src/components/library/library.jsx @@ -217,9 +217,9 @@ class LibraryComponent extends React.Component { extensionId={dataItem.extensionId} featured={dataItem.featured} hidden={dataItem.hidden} - iconMd5={dataItem.md5} + iconMd5={dataItem.type === 'sprite' ? dataItem.costumes[0].md5ext : dataItem.md5ext} iconRawURL={dataItem.rawURL} - icons={dataItem.json && dataItem.json.costumes} + icons={dataItem.costumes} id={index} insetIconURL={dataItem.insetIconURL} internetConnectionRequired={dataItem.internetConnectionRequired} diff --git a/src/containers/backdrop-library.jsx b/src/containers/backdrop-library.jsx index 9d6b559c56c15ce1843a84964e286a7cecf9f5c8..31aaec926a9b1694a89676adf042f31a1cfc6c6e 100644 --- a/src/containers/backdrop-library.jsx +++ b/src/containers/backdrop-library.jsx @@ -27,13 +27,13 @@ class BackdropLibrary extends React.Component { handleItemSelect (item) { const vmBackdrop = { name: item.name, - rotationCenterX: item.info[0] && item.info[0] / 2, - rotationCenterY: item.info[1] && item.info[1] / 2, - bitmapResolution: item.info.length > 2 ? item.info[2] : 1, + rotationCenterX: item.rotationCenterX, + rotationCenterY: item.rotationCenterY, + bitmapResolution: item.bitmapResolution, skinId: null }; // Do not switch to stage, just add the backdrop - this.props.vm.addBackdrop(item.md5, vmBackdrop); + this.props.vm.addBackdrop(item.md5ext, vmBackdrop); } render () { return ( diff --git a/src/containers/costume-library.jsx b/src/containers/costume-library.jsx index 1e3dac3d78fdc7269703b2b6d9f3c5ae1dc6edb8..2686c840827bbbcfc91e4fe594d3df9f69db22ef 100644 --- a/src/containers/costume-library.jsx +++ b/src/containers/costume-library.jsx @@ -25,18 +25,16 @@ class CostumeLibrary extends React.PureComponent { ]); } handleItemSelected (item) { - const split = item.md5.split('.'); - const type = split.length > 1 ? split[1] : null; - const rotationCenterX = type === 'svg' ? item.info[0] : item.info[0] / 2; - const rotationCenterY = type === 'svg' ? item.info[1] : item.info[1] / 2; + const rotationCenterX = item.dataFormat === 'svg' ? item.rotationCenterX : item.rotationCenterX / 2; + const rotationCenterY = item.dataFormat === 'svg' ? item.rotationCenterY : item.rotationCenterY / 2; const vmCostume = { name: item.name, rotationCenterX, rotationCenterY, - bitmapResolution: item.info.length > 2 ? item.info[2] : 1, + bitmapResolution: item.bitmapResolution, skinId: null }; - this.props.vm.addCostumeFromLibrary(item.md5, vmCostume); + this.props.vm.addCostumeFromLibrary(item.md5ext, vmCostume); } render () { return ( diff --git a/src/containers/costume-tab.jsx b/src/containers/costume-tab.jsx index c201efb8f982382c505e95347be33b56626d6f60..5f99f8f23de51c1c51b99980bfd0bb82c20a5fd8 100644 --- a/src/containers/costume-tab.jsx +++ b/src/containers/costume-tab.jsx @@ -179,16 +179,14 @@ class CostumeTab extends React.Component { } handleSurpriseCostume () { const item = costumeLibraryContent[Math.floor(Math.random() * costumeLibraryContent.length)]; - const split = item.md5.split('.'); - const type = split.length > 1 ? split[1] : null; - const rotationCenterX = type === 'svg' ? item.info[0] : item.info[0] / 2; - const rotationCenterY = type === 'svg' ? item.info[1] : item.info[1] / 2; + const rotationCenterX = item.dataFormat === 'svg' ? item.rotationCenterX : item.rotationCenterX / 2; + const rotationCenterY = item.dataFormat === 'svg' ? item.rotationCenterY : item.rotationCenterY / 2; const vmCostume = { name: item.name, - md5: item.md5, - rotationCenterX, - rotationCenterY, - bitmapResolution: item.info.length > 2 ? item.info[2] : 1, + md5: item.md5ext, + rotationCenterX: rotationCenterX, + rotationCenterY: rotationCenterY, + bitmapResolution: item.bitmapResolution, skinId: null }; this.handleNewCostume(vmCostume, true /* fromCostumeLibrary */); @@ -197,10 +195,10 @@ class CostumeTab extends React.Component { const item = backdropLibraryContent[Math.floor(Math.random() * backdropLibraryContent.length)]; const vmCostume = { name: item.name, - md5: item.md5, - rotationCenterX: item.info[0] && item.info[0] / 2, - rotationCenterY: item.info[1] && item.info[1] / 2, - bitmapResolution: item.info.length > 2 ? item.info[2] : 1, + md5: item.md5ext, + rotationCenterX: item.rotationCenterX, + rotationCenterY: item.rotationCenterY, + bitmapResolution: item.bitmapResolution, skinId: null }; this.handleNewCostume(vmCostume); diff --git a/src/containers/sound-library.jsx b/src/containers/sound-library.jsx index cdb5c7c6a1f4fdaa693d4c756710e5149027128c..973bee104570fbcf973efab759b046b1254357ea 100644 --- a/src/containers/sound-library.jsx +++ b/src/containers/sound-library.jsx @@ -149,11 +149,11 @@ class SoundLibrary extends React.PureComponent { // @todo need to use this hack to avoid library using md5 for image const soundLibraryThumbnailData = soundLibraryContent.map(sound => { const { - md5, + md5ext, ...otherData } = sound; return { - _md5: md5, + _md5: md5ext, rawURL: this.props.isRtl ? soundIconRtl : soundIcon, ...otherData }; diff --git a/src/containers/sound-tab.jsx b/src/containers/sound-tab.jsx index 8d42e8e910cd0cdf78b9b04567706c3e78235b38..75ac672361e8497dfbeb962242360ba3b5f318c7 100644 --- a/src/containers/sound-tab.jsx +++ b/src/containers/sound-tab.jsx @@ -113,8 +113,8 @@ class SoundTab extends React.Component { handleSurpriseSound () { const soundItem = soundLibraryContent[Math.floor(Math.random() * soundLibraryContent.length)]; const vmSound = { - format: soundItem.format, - md5: soundItem.md5, + format: soundItem.dataFormat, + md5: soundItem.md5ext, rate: soundItem.rate, sampleCount: soundItem.sampleCount, name: soundItem.name diff --git a/src/containers/sprite-library.jsx b/src/containers/sprite-library.jsx index 013ce4f774003f5cea15f07ccbae0baf39cf1203..9fe0604c98484566ab19f8a0cb58366316ce52b9 100644 --- a/src/containers/sprite-library.jsx +++ b/src/containers/sprite-library.jsx @@ -28,7 +28,7 @@ class SpriteLibrary extends React.PureComponent { handleItemSelect (item) { // Randomize position of library sprite randomizeSpritePosition(item); - this.props.vm.addSprite(JSON.stringify(item.json)).then(() => { + this.props.vm.addSprite(JSON.stringify(item)).then(() => { this.props.onActivateBlocksTab(); }); } diff --git a/src/containers/stage-selector.jsx b/src/containers/stage-selector.jsx index 94d1d6c00ff73fbadf4e3a1c67855915b07cff04..66b1cb5e5dffa49a4481eb412a464b219616f1e4 100644 --- a/src/containers/stage-selector.jsx +++ b/src/containers/stage-selector.jsx @@ -69,10 +69,10 @@ class StageSelector extends React.Component { addBackdropFromLibraryItem (item, shouldActivateTab = true) { const vmBackdrop = { name: item.name, - md5: item.md5, - rotationCenterX: item.info[0] && item.info[0] / 2, - rotationCenterY: item.info[1] && item.info[1] / 2, - bitmapResolution: item.info.length > 2 ? item.info[2] : 1, + md5: item.md5ext, + rotationCenterX: item.rotationCenterX, + rotationCenterY: item.rotationCenterY, + bitmapResolution: item.bitmapResolution, skinId: null }; this.handleNewBackdrop(vmBackdrop, shouldActivateTab); diff --git a/src/containers/target-pane.jsx b/src/containers/target-pane.jsx index b5af39b16ddfaa6d66597c4ea7ce79e96009ad96..55ddaffaf8f33d916c27f029140848c7941895ea 100644 --- a/src/containers/target-pane.jsx +++ b/src/containers/target-pane.jsx @@ -111,7 +111,7 @@ class TargetPane extends React.Component { ); const item = surpriseSprites[Math.floor(Math.random() * surpriseSprites.length)]; randomizeSpritePosition(item); - this.props.vm.addSprite(JSON.stringify(item.json)) + this.props.vm.addSprite(JSON.stringify(item)) .then(this.handleActivateBlocksTab); } handlePaintSpriteClick () { diff --git a/src/lib/randomize-sprite-position.js b/src/lib/randomize-sprite-position.js index dbb92b9ade4b81c11e14e089ae996dc6598406cd..9d29980c63e412e83ce1de8a22f7494385a7f07b 100644 --- a/src/lib/randomize-sprite-position.js +++ b/src/lib/randomize-sprite-position.js @@ -1,16 +1,7 @@ const randomizeSpritePosition = spriteObject => { // https://github.com/LLK/scratch-flash/blob/689f3c79a7e8b2e98f5be80056d877f303a8d8ba/src/Scratch.as#L1385 - const randomX = Math.floor((200 * Math.random()) - 100); - const randomY = Math.floor((100 * Math.random()) - 50); - if (spriteObject.hasOwnProperty('json')) { - // Library sprite object - spriteObject.json.x = randomX; - spriteObject.json.y = randomY; - } else if (spriteObject.hasOwnProperty('x') && spriteObject.hasOwnProperty('y')) { - // Scratch 3 sprite object - spriteObject.x = randomX; - spriteObject.y = randomY; - } + spriteObject.x = Math.floor((200 * Math.random()) - 100); + spriteObject.y = Math.floor((100 * Math.random()) - 50); }; export default randomizeSpritePosition;