Skip to content
Snippets Groups Projects
Commit db54b64f authored by DD's avatar DD
Browse files

Implement Pauls suggestion and remove promises

parent b8891c27
No related branches found
No related tags found
No related merge requests found
...@@ -23,11 +23,7 @@ class BackdropLibrary extends React.Component { ...@@ -23,11 +23,7 @@ class BackdropLibrary extends React.Component {
bitmapResolution: item.info.length > 2 ? item.info[2] : 1, bitmapResolution: item.info.length > 2 ? item.info[2] : 1,
skinId: null skinId: null
}; };
this.props.vm.addBackdrop(item.md5, vmBackdrop).then(() => { this.props.vm.addBackdrop(item.md5, vmBackdrop);
if (this.props.onNewBackdrop) {
this.props.onNewBackdrop();
}
});
analytics.event({ analytics.event({
category: 'library', category: 'library',
action: 'Select Backdrop', action: 'Select Backdrop',
...@@ -47,7 +43,6 @@ class BackdropLibrary extends React.Component { ...@@ -47,7 +43,6 @@ class BackdropLibrary extends React.Component {
} }
BackdropLibrary.propTypes = { BackdropLibrary.propTypes = {
onNewBackdrop: PropTypes.func.isRequired,
onRequestClose: PropTypes.func, onRequestClose: PropTypes.func,
vm: PropTypes.instanceOf(VM).isRequired vm: PropTypes.instanceOf(VM).isRequired
}; };
......
...@@ -23,9 +23,7 @@ class CostumeLibrary extends React.PureComponent { ...@@ -23,9 +23,7 @@ class CostumeLibrary extends React.PureComponent {
bitmapResolution: item.info.length > 2 ? item.info[2] : 1, bitmapResolution: item.info.length > 2 ? item.info[2] : 1,
skinId: null skinId: null
}; };
this.props.vm.addCostume(item.md5, vmCostume).then(() => { this.props.vm.addCostume(item.md5, vmCostume);
this.props.onNewCostume();
});
analytics.event({ analytics.event({
category: 'library', category: 'library',
action: 'Select Costume', action: 'Select Costume',
...@@ -45,7 +43,6 @@ class CostumeLibrary extends React.PureComponent { ...@@ -45,7 +43,6 @@ class CostumeLibrary extends React.PureComponent {
} }
CostumeLibrary.propTypes = { CostumeLibrary.propTypes = {
onNewCostume: PropTypes.func.isRequired,
onRequestClose: PropTypes.func, onRequestClose: PropTypes.func,
vm: PropTypes.instanceOf(VM).isRequired vm: PropTypes.instanceOf(VM).isRequired
}; };
......
...@@ -67,7 +67,6 @@ class CostumeTab extends React.Component { ...@@ -67,7 +67,6 @@ class CostumeTab extends React.Component {
'handleSelectCostume', 'handleSelectCostume',
'handleDeleteCostume', 'handleDeleteCostume',
'handleDuplicateCostume', 'handleDuplicateCostume',
'handleNewCostume',
'handleNewBlankCostume', 'handleNewBlankCostume',
'handleSurpriseCostume', 'handleSurpriseCostume',
'handleSurpriseBackdrop' 'handleSurpriseBackdrop'
...@@ -97,24 +96,20 @@ class CostumeTab extends React.Component { ...@@ -97,24 +96,20 @@ class CostumeTab extends React.Component {
} }
if (this.props.editingTarget === editingTarget) { if (this.props.editingTarget === editingTarget) {
// Switch to a newly added costume if there is one // If costumes have been added or removed, change costumes to the editing target's
// current costume.
const oldTarget = this.props.sprites[editingTarget] ? const oldTarget = this.props.sprites[editingTarget] ?
this.props.sprites[editingTarget] : this.props.stage; this.props.sprites[editingTarget] : this.props.stage;
// @todo: Check that the costume is actually new by making sure it doesn't // @todo: Find and switch to the index of the costume that is new. This is blocked by
// exist in the old costume list. This is blocked by
// https://github.com/LLK/scratch-vm/issues/967 // https://github.com/LLK/scratch-vm/issues/967
if (oldTarget.costumeCount < target.costumeCount) { // Right now, you can land on the wrong costume if a costume changing script is running.
if (oldTarget.costumeCount !== target.costumeCount) {
this.setState({selectedCostumeIndex: target.currentCostume}); this.setState({selectedCostumeIndex: target.currentCostume});
} }
} else { } else {
// If switching editing targets, update the costume index // If switching editing targets, update the costume index
this.setState({selectedCostumeIndex: target.currentCostume}); this.setState({selectedCostumeIndex: target.currentCostume});
} }
// In case of deleted costumes
if (this.state.selectedCostumeIndex > target.costumes.length - 1) {
this.setState({selectedCostumeIndex: target.costumes.length - 1});
}
} }
handleSelectCostume (costumeIndex) { handleSelectCostume (costumeIndex) {
this.props.vm.editingTarget.setCostume(costumeIndex); this.props.vm.editingTarget.setCostume(costumeIndex);
...@@ -124,14 +119,7 @@ class CostumeTab extends React.Component { ...@@ -124,14 +119,7 @@ class CostumeTab extends React.Component {
this.props.vm.deleteCostume(costumeIndex); this.props.vm.deleteCostume(costumeIndex);
} }
handleDuplicateCostume (costumeIndex) { handleDuplicateCostume (costumeIndex) {
this.props.vm.duplicateCostume(costumeIndex).then(() => { this.props.vm.duplicateCostume(costumeIndex);
this.setState({selectedCostumeIndex: costumeIndex + 1});
});
}
handleNewCostume () {
if (!this.props.vm.editingTarget) return;
const costumes = this.props.vm.editingTarget.getCostumes() || [];
this.setState({selectedCostumeIndex: Math.max(costumes.length - 1, 0)});
} }
handleNewBlankCostume () { handleNewBlankCostume () {
const emptyItem = costumeLibraryContent.find(item => ( const emptyItem = costumeLibraryContent.find(item => (
...@@ -146,9 +134,7 @@ class CostumeTab extends React.Component { ...@@ -146,9 +134,7 @@ class CostumeTab extends React.Component {
skinId: null skinId: null
}; };
this.props.vm.addCostume(emptyItem.md5, vmCostume).then(() => { this.props.vm.addCostume(emptyItem.md5, vmCostume);
this.handleNewCostume();
});
} }
handleSurpriseCostume () { handleSurpriseCostume () {
const item = costumeLibraryContent[Math.floor(Math.random() * costumeLibraryContent.length)]; const item = costumeLibraryContent[Math.floor(Math.random() * costumeLibraryContent.length)];
...@@ -159,9 +145,7 @@ class CostumeTab extends React.Component { ...@@ -159,9 +145,7 @@ class CostumeTab extends React.Component {
bitmapResolution: item.info.length > 2 ? item.info[2] : 1, bitmapResolution: item.info.length > 2 ? item.info[2] : 1,
skinId: null skinId: null
}; };
this.props.vm.addCostume(item.md5, vmCostume).then(() => { this.props.vm.addCostume(item.md5, vmCostume);
this.handleNewCostume();
});
} }
handleSurpriseBackdrop () { handleSurpriseBackdrop () {
const item = backdropLibraryContent[Math.floor(Math.random() * backdropLibraryContent.length)]; const item = backdropLibraryContent[Math.floor(Math.random() * backdropLibraryContent.length)];
...@@ -172,9 +156,7 @@ class CostumeTab extends React.Component { ...@@ -172,9 +156,7 @@ class CostumeTab extends React.Component {
bitmapResolution: item.info.length > 2 ? item.info[2] : 1, bitmapResolution: item.info.length > 2 ? item.info[2] : 1,
skinId: null skinId: null
}; };
this.props.vm.addCostume(item.md5, vmCostume).then(() => { this.props.vm.addCostume(item.md5, vmCostume);
this.handleNewCostume();
});
} }
render () { render () {
// For paint wrapper // For paint wrapper
...@@ -249,14 +231,12 @@ class CostumeTab extends React.Component { ...@@ -249,14 +231,12 @@ class CostumeTab extends React.Component {
{costumeLibraryVisible ? ( {costumeLibraryVisible ? (
<CostumeLibrary <CostumeLibrary
vm={vm} vm={vm}
onNewCostume={this.handleNewCostume}
onRequestClose={onRequestCloseCostumeLibrary} onRequestClose={onRequestCloseCostumeLibrary}
/> />
) : null} ) : null}
{backdropLibraryVisible ? ( {backdropLibraryVisible ? (
<BackdropLibrary <BackdropLibrary
vm={vm} vm={vm}
onNewBackdrop={this.handleNewCostume}
onRequestClose={onRequestCloseBackdropLibrary} onRequestClose={onRequestCloseBackdropLibrary}
/> />
) : null} ) : null}
......
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