UNPKG

scratch-gui

Version:

GraphicaL User Interface for creating and running Scratch 3.0 projects

64 lines (57 loc) 1.89 kB
import bindAll from 'lodash.bindall'; import PropTypes from 'prop-types'; import React from 'react'; import {defineMessages, injectIntl, intlShape} from 'react-intl'; import VM from 'scratch-vm'; import analytics from '../lib/analytics'; import costumeLibraryContent from '../lib/libraries/costumes.json'; import spriteTags from '../lib/libraries/sprite-tags'; import LibraryComponent from '../components/library/library.jsx'; const messages = defineMessages({ libraryTitle: { defaultMessage: 'Choose a Costume', description: 'Heading for the costume library', id: 'gui.costumeLibrary.chooseACostume' } }); class CostumeLibrary extends React.PureComponent { constructor (props) { super(props); bindAll(this, [ 'handleItemSelected' ]); } handleItemSelected (item) { const vmCostume = { name: item.name, rotationCenterX: item.info[0], rotationCenterY: item.info[1], bitmapResolution: item.info.length > 2 ? item.info[2] : 1, skinId: null }; this.props.vm.addCostume(item.md5, vmCostume); analytics.event({ category: 'library', action: 'Select Costume', label: item.name }); } render () { return ( <LibraryComponent data={costumeLibraryContent} id="costumeLibrary" tags={spriteTags} title={this.props.intl.formatMessage(messages.libraryTitle)} onItemSelected={this.handleItemSelected} onRequestClose={this.props.onRequestClose} /> ); } } CostumeLibrary.propTypes = { intl: intlShape.isRequired, onRequestClose: PropTypes.func, vm: PropTypes.instanceOf(VM).isRequired }; export default injectIntl(CostumeLibrary);