scratch-gui / src /containers /costume-library.jsx
soiz1's picture
Upload folder using huggingface_hub
8fd7a1d verified
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 {getCostumeLibrary} from '../lib/libraries/tw-async-libraries';
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'
]);
this.state = {
data: getCostumeLibrary()
};
}
componentDidMount () {
if (this.state.data.then) {
this.state.data.then(data => this.setState({
data
}));
}
}
handleItemSelected (item) {
const vmCostume = {
name: item.name,
rotationCenterX: item.rotationCenterX,
rotationCenterY: item.rotationCenterY,
bitmapResolution: item.bitmapResolution,
skinId: null
};
this.props.vm.addCostumeFromLibrary(item.md5ext, vmCostume);
}
render () {
return (
<LibraryComponent
data={this.state.data.then ? null : this.state.data}
id="costumeLibrary"
tags={spriteTags}
title={this.props.intl.formatMessage(messages.libraryTitle)}
removedTrademarks
onItemSelected={this.handleItemSelected}
onRequestClose={this.props.onRequestClose}
/>
);
}
}
CostumeLibrary.propTypes = {
intl: intlShape.isRequired,
onRequestClose: PropTypes.func,
vm: PropTypes.instanceOf(VM).isRequired
};
export default injectIntl(CostumeLibrary);