Skip to content

Commit

Permalink
feat(settings): add "delete current instrument" button
Browse files Browse the repository at this point in the history
  • Loading branch information
domi7777 committed Nov 7, 2024
1 parent 59a22ba commit 58a8c5e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/scenes/EmptyScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'});
Expand Down
20 changes: 16 additions & 4 deletions src/scenes/LoopTracksScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -240,6 +249,9 @@ export class LoopTracksScene extends Phaser.Scene {
track.controlIcon.setText('')
.setColor(controlColors.idle);
}
} else {
track.controlIcon.setText('')
.setColor(controlColors.idle);
}
});
}
Expand Down
6 changes: 4 additions & 2 deletions src/settings/TweakPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 58a8c5e

Please sign in to comment.