diff --git a/src/scenes/EmptyScene.ts b/src/scenes/EmptyScene.ts index dbd2603..88cc94a 100644 --- a/src/scenes/EmptyScene.ts +++ b/src/scenes/EmptyScene.ts @@ -50,7 +50,7 @@ export class EmptyScene extends Phaser.Scene { this.scene.setVisible(false); }) ); - const trackSceneKey = `track_scene_${trackIndex}`; + const trackSceneKey = LoopTracksScene.getTrackSceneKey(trackIndex); drumsButton.on(Phaser.Input.Events.POINTER_UP, () => { this.scene.add(trackSceneKey, DrumsScene, true, {type: 'drums'}); diff --git a/src/scenes/LoopTracksScene.ts b/src/scenes/LoopTracksScene.ts index b96dd60..f3beb28 100644 --- a/src/scenes/LoopTracksScene.ts +++ b/src/scenes/LoopTracksScene.ts @@ -52,13 +52,22 @@ export class LoopTracksScene extends Phaser.Scene { static deleteCurrentTrack() { const track = LoopTracksScene.tracks.find(track => track.selected); if (track) { + const trackIndex = LoopTracksScene.tracks.indexOf(track); track.loop.destroy(); track.loopProgressArc.clear(); - track.loop = new Loop(LoopTracksScene.tracks.indexOf(track)); - LoopTracksScene.instance.updateControlsState(); - } else { - console.error('No track selected'); + track.loop = new Loop(trackIndex); + this.instance.updateControlsState(); + return trackIndex; } + throw new Error('No track selected'); + } + + static deleteCurrentInstrumentScene() { + const trackIndex = LoopTracksScene.deleteCurrentTrack(); + const sceneKey = LoopTracksScene.getTrackSceneKey(trackIndex); + this.instance.game.scene.remove(sceneKey); + this.instance.game.scene.start(EmptyScene.key, {index: trackIndex}); + this.instance.updateControlsState(); } public static getTrackSceneKey(index: number) { @@ -240,6 +249,9 @@ export class LoopTracksScene extends Phaser.Scene { track.controlIcon.setText('') .setColor(controlColors.idle); } + } else { + track.controlIcon.setText('') + .setColor(controlColors.idle); } }); } diff --git a/src/settings/TweakPane.ts b/src/settings/TweakPane.ts index c8d1b30..83946b4 100644 --- a/src/settings/TweakPane.ts +++ b/src/settings/TweakPane.ts @@ -14,9 +14,11 @@ export class TweakPane { expanded: false, container, }); - pane.addButton({title: 'Delete current loop'}).on('click', (e) => { + pane.addButton({title: 'Delete current loop'}).on('click', () => { LoopTracksScene.deleteCurrentTrack(); - e.native.preventDefault(); + }); + pane.addButton({title: 'Delete instrument & loop'}).on('click', () => { + LoopTracksScene.deleteCurrentInstrumentScene(); }); // test panels