From b39323858c56a5ead395c8549d9a918dba494bbe Mon Sep 17 00:00:00 2001 From: Paul Kaplan <pkaplan@media.mit.edu> Date: Tue, 31 Jul 2018 09:45:42 -0400 Subject: [PATCH] Allow backpack sounds/costumes to be dragged into sprite and stage tiles --- src/components/sprite-selector/sprite-list.jsx | 7 +++++-- src/containers/stage-selector.jsx | 17 ++++++++++++++++- src/containers/target-pane.jsx | 12 ++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/components/sprite-selector/sprite-list.jsx b/src/components/sprite-selector/sprite-list.jsx index a29912b79..df42c6c28 100644 --- a/src/components/sprite-selector/sprite-list.jsx +++ b/src/components/sprite-selector/sprite-list.jsx @@ -53,8 +53,11 @@ const SpriteList = function (props) { // Note the absence of the self-sharing check: a sprite can share assets with itself. // This is a quirk of 2.0, but seems worth leaving possible, it // allows quick (albeit unusual) duplication of assets. - isRaised = isRaised || draggingType === DragConstants.COSTUME || - draggingType === DragConstants.SOUND; + isRaised = isRaised || [ + DragConstants.COSTUME, + DragConstants.SOUND, + DragConstants.BACKPACK_COSTUME, + DragConstants.BACKPACK_SOUND].includes(draggingType); return ( <SortableAsset diff --git a/src/containers/stage-selector.jsx b/src/containers/stage-selector.jsx index aeff4f2ad..e5a86fcc0 100644 --- a/src/containers/stage-selector.jsx +++ b/src/containers/stage-selector.jsx @@ -16,7 +16,13 @@ import backdropLibraryContent from '../lib/libraries/backdrops.json'; import costumeLibraryContent from '../lib/libraries/costumes.json'; import {handleFileUpload, costumeUpload} from '../lib/file-uploader.js'; -const dragTypes = [DragConstants.COSTUME, DragConstants.SOUND]; +const dragTypes = [ + DragConstants.COSTUME, + DragConstants.SOUND, + DragConstants.BACKPACK_COSTUME, + DragConstants.BACKPACK_SOUND +]; + const DroppableStage = DropAreaHOC(dragTypes)(StageSelectorComponent); class StageSelector extends React.Component { @@ -86,6 +92,15 @@ class StageSelector extends React.Component { this.props.vm.shareCostumeToTarget(dragInfo.index, this.props.id); } else if (dragInfo.dragType === DragConstants.SOUND) { this.props.vm.shareSoundToTarget(dragInfo.index, this.props.id); + } else if (dragInfo.dragType === DragConstants.BACKPACK_COSTUME) { + this.props.vm.addCostume(dragInfo.payload.body, { + name: dragInfo.payload.name + }, this.props.id); + } else if (dragInfo.dragType === DragConstants.BACKPACK_SOUND) { + this.props.vm.addSound({ + md5: dragInfo.payload.body, + name: dragInfo.payload.name + }, this.props.id); } } setFileInput (input) { diff --git a/src/containers/target-pane.jsx b/src/containers/target-pane.jsx index a116b3c07..705957491 100644 --- a/src/containers/target-pane.jsx +++ b/src/containers/target-pane.jsx @@ -152,6 +152,18 @@ class TargetPane extends React.Component { this.props.vm.shareCostumeToTarget(dragInfo.index, targetId); } else if (targetId && dragInfo.dragType === DragConstants.SOUND) { this.props.vm.shareSoundToTarget(dragInfo.index, targetId); + } else if (dragInfo.dragType === DragConstants.BACKPACK_COSTUME) { + // In scratch 2, this only creates a new sprite from the costume. + // We may be able to handle both kinds of drops, depending on where + // the drop happens. For now, just add the costume. + this.props.vm.addCostume(dragInfo.payload.body, { + name: dragInfo.payload.name + }, targetId); + } else if (dragInfo.dragType === DragConstants.BACKPACK_SOUND) { + this.props.vm.addSound({ + md5: dragInfo.payload.body, + name: dragInfo.payload.name + }, targetId); } } } -- GitLab