Skip to content
Snippets Groups Projects
Unverified Commit 30ed3a6c authored by Paul Kaplan's avatar Paul Kaplan Committed by GitHub
Browse files

Merge pull request #3614 from paulkaplan/drag-code-to-sprites

Allow code to be dragged directly to sprite tiles
parents 2038b128 9a6e2e0d
No related branches found
No related tags found
No related merge requests found
...@@ -57,7 +57,8 @@ const SpriteList = function (props) { ...@@ -57,7 +57,8 @@ const SpriteList = function (props) {
DragConstants.COSTUME, DragConstants.COSTUME,
DragConstants.SOUND, DragConstants.SOUND,
DragConstants.BACKPACK_COSTUME, DragConstants.BACKPACK_COSTUME,
DragConstants.BACKPACK_SOUND].includes(draggingType); DragConstants.BACKPACK_SOUND,
DragConstants.BACKPACK_CODE].includes(draggingType);
return ( return (
<SortableAsset <SortableAsset
......
...@@ -12,6 +12,7 @@ import DragConstants from '../lib/drag-constants'; ...@@ -12,6 +12,7 @@ import DragConstants from '../lib/drag-constants';
import DropAreaHOC from '../lib/drop-area-hoc.jsx'; import DropAreaHOC from '../lib/drop-area-hoc.jsx';
import {emptyCostume} from '../lib/empty-assets'; import {emptyCostume} from '../lib/empty-assets';
import sharedMessages from '../lib/shared-messages'; import sharedMessages from '../lib/shared-messages';
import {fetchCode} from '../lib/backpack-api';
import StageSelectorComponent from '../components/stage-selector/stage-selector.jsx'; import StageSelectorComponent from '../components/stage-selector/stage-selector.jsx';
...@@ -22,7 +23,8 @@ const dragTypes = [ ...@@ -22,7 +23,8 @@ const dragTypes = [
DragConstants.COSTUME, DragConstants.COSTUME,
DragConstants.SOUND, DragConstants.SOUND,
DragConstants.BACKPACK_COSTUME, DragConstants.BACKPACK_COSTUME,
DragConstants.BACKPACK_SOUND DragConstants.BACKPACK_SOUND,
DragConstants.BACKPACK_CODE
]; ];
const DroppableStage = DropAreaHOC(dragTypes)(StageSelectorComponent); const DroppableStage = DropAreaHOC(dragTypes)(StageSelectorComponent);
...@@ -99,6 +101,12 @@ class StageSelector extends React.Component { ...@@ -99,6 +101,12 @@ class StageSelector extends React.Component {
md5: dragInfo.payload.body, md5: dragInfo.payload.body,
name: dragInfo.payload.name name: dragInfo.payload.name
}, this.props.id); }, this.props.id);
} else if (dragInfo.dragType === DragConstants.BACKPACK_CODE) {
fetchCode(dragInfo.payload.bodyUrl)
.then(blocks => {
this.props.vm.shareBlocksToTarget(blocks, this.props.id);
this.props.vm.refreshWorkspace();
});
} }
} }
setFileInput (input) { setFileInput (input) {
......
...@@ -19,6 +19,7 @@ import {handleFileUpload, spriteUpload} from '../lib/file-uploader.js'; ...@@ -19,6 +19,7 @@ import {handleFileUpload, spriteUpload} from '../lib/file-uploader.js';
import sharedMessages from '../lib/shared-messages'; import sharedMessages from '../lib/shared-messages';
import {emptySprite} from '../lib/empty-assets'; import {emptySprite} from '../lib/empty-assets';
import {highlightTarget} from '../reducers/targets'; import {highlightTarget} from '../reducers/targets';
import {fetchSprite, fetchCode} from '../lib/backpack-api';
class TargetPane extends React.Component { class TargetPane extends React.Component {
constructor (props) { constructor (props) {
...@@ -166,8 +167,7 @@ class TargetPane extends React.Component { ...@@ -166,8 +167,7 @@ class TargetPane extends React.Component {
} else if (dragInfo.dragType === DragConstants.BACKPACK_SPRITE) { } else if (dragInfo.dragType === DragConstants.BACKPACK_SPRITE) {
// TODO storage does not have a way of loading zips right now, and may never need it. // TODO storage does not have a way of loading zips right now, and may never need it.
// So for now just grab the zip manually. // So for now just grab the zip manually.
fetch(dragInfo.payload.bodyUrl) fetchSprite(dragInfo.payload.bodyUrl)
.then(response => response.arrayBuffer())
.then(sprite3Zip => this.props.vm.addSprite(sprite3Zip)); .then(sprite3Zip => this.props.vm.addSprite(sprite3Zip));
} else if (targetId) { } else if (targetId) {
// Something is being dragged over one of the sprite tiles or the backdrop. // Something is being dragged over one of the sprite tiles or the backdrop.
...@@ -192,6 +192,12 @@ class TargetPane extends React.Component { ...@@ -192,6 +192,12 @@ class TargetPane extends React.Component {
md5: dragInfo.payload.body, md5: dragInfo.payload.body,
name: dragInfo.payload.name name: dragInfo.payload.name
}, targetId); }, targetId);
} else if (dragInfo.dragType === DragConstants.BACKPACK_CODE) {
fetchCode(dragInfo.payload.bodyUrl)
.then(blocks => {
this.props.vm.shareBlocksToTarget(blocks, targetId);
this.props.vm.refreshWorkspace();
});
} }
} }
} }
......
...@@ -73,6 +73,22 @@ const deleteBackpackObject = ({ ...@@ -73,6 +73,22 @@ const deleteBackpackObject = ({
}); });
}); });
// Two types of backpack items are not retreivable through storage
// code, as json and sprite3 as arraybuffer zips.
const fetchAs = (responseType, uri) => new Promise((resolve, reject) => {
xhr({uri, responseType}, (error, response) => {
if (error || response.statusCode !== 200) {
return reject();
}
return resolve(response.body);
});
});
// These two helpers allow easy fetching of backpack code and sprite zips
// Use the curried fetchAs here so the consumer does not worry about XHR responseTypes
const fetchCode = fetchAs.bind(null, 'json');
const fetchSprite = fetchAs.bind(null, 'arraybuffer');
export { export {
getBackpackContents, getBackpackContents,
saveBackpackObject, saveBackpackObject,
...@@ -80,5 +96,7 @@ export { ...@@ -80,5 +96,7 @@ export {
costumePayload, costumePayload,
soundPayload, soundPayload,
spritePayload, spritePayload,
codePayload codePayload,
fetchCode,
fetchSprite
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment