Skip to content
Snippets Groups Projects
Commit 21943cc3 authored by Paul Kaplan's avatar Paul Kaplan Committed by GitHub
Browse files

Merge pull request #364 from paulkaplan/feature/delete-costume-sounds

Use vm functions for deleting sounds and costumes
parents 0ae48ad5 e26e55e7
No related branches found
No related tags found
No related merge requests found
...@@ -23,28 +23,25 @@ class CostumeTab extends React.Component { ...@@ -23,28 +23,25 @@ class CostumeTab extends React.Component {
this.state = {selectedCostumeIndex: 0}; this.state = {selectedCostumeIndex: 0};
} }
componentWillReceiveProps (nextProps) {
const {
editingTarget,
sprites,
stage
} = nextProps;
const target = editingTarget && sprites[editingTarget] ? sprites[editingTarget] : stage;
if (target && target.costumes && this.state.selectedCostumeIndex > target.costumes.length - 1) {
this.setState({selectedCostumeIndex: target.costumes.length - 1});
}
}
handleSelectCostume (costumeIndex) { handleSelectCostume (costumeIndex) {
this.setState({selectedCostumeIndex: costumeIndex}); this.setState({selectedCostumeIndex: costumeIndex});
} }
handleDeleteCostume (costumeIndex) { handleDeleteCostume (costumeIndex) {
// @todo the VM should handle all of this logic this.props.vm.deleteCostume(costumeIndex);
const {editingTarget} = this.props.vm;
if (costumeIndex === editingTarget.currentCostume) {
editingTarget.setCostume(costumeIndex - 1);
}
editingTarget.sprite.costumes = editingTarget.sprite.costumes
.slice(0, costumeIndex)
.concat(editingTarget.sprite.costumes.slice(costumeIndex + 1));
this.props.vm.runtime.requestTargetsUpdate(editingTarget);
// @todo not sure if this is getting redrawn correctly
this.props.vm.runtime.requestRedraw();
this.setState({
selectedCostumeIndex: this.state.selectedCostumeIndex % editingTarget.sprite.costumes.length
});
} }
render () { render () {
......
...@@ -23,6 +23,20 @@ class SoundTab extends React.Component { ...@@ -23,6 +23,20 @@ class SoundTab extends React.Component {
this.state = {selectedSoundIndex: 0}; this.state = {selectedSoundIndex: 0};
} }
componentWillReceiveProps (nextProps) {
const {
editingTarget,
sprites,
stage
} = nextProps;
const target = editingTarget && sprites[editingTarget] ? sprites[editingTarget] : stage;
if (target && target.sounds && this.state.selectedSoundIndex > target.sounds.length - 1) {
this.setState({selectedSoundIndex: target.sounds.length - 1});
}
}
handleSelectSound (soundIndex) { handleSelectSound (soundIndex) {
const sound = this.props.vm.editingTarget.sprite.sounds[soundIndex]; const sound = this.props.vm.editingTarget.sprite.sounds[soundIndex];
this.props.vm.editingTarget.audioPlayer.playSound(sound.md5); this.props.vm.editingTarget.audioPlayer.playSound(sound.md5);
...@@ -30,17 +44,7 @@ class SoundTab extends React.Component { ...@@ -30,17 +44,7 @@ class SoundTab extends React.Component {
} }
handleDeleteSound (soundIndex) { handleDeleteSound (soundIndex) {
// @todo the VM should handle all of this logic this.props.vm.deleteSound(soundIndex);
const {editingTarget} = this.props.vm;
editingTarget.sprite.sounds = editingTarget.sprite.sounds
.slice(0, soundIndex)
.concat(editingTarget.sprite.sounds.slice(soundIndex + 1));
this.props.vm.emitTargetsUpdate();
this.props.vm.runtime.requestRedraw();
this.setState({
selectedSoundIndex: this.state.selectedSoundIndex % editingTarget.sprite.sounds.length
});
} }
render () { render () {
......
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