-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathplaceTap.ts
More file actions
45 lines (36 loc) · 1.03 KB
/
placeTap.ts
File metadata and controls
45 lines (36 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import assert from "assert";
import { Beat, KeyIndex } from "../../charting";
import { Tap } from "../../charting/objects";
import { RootStore } from "../../store";
import { Action } from "../action";
/**
* Arguments for the PlaceTapAction.
*/
export interface PlaceTapArgs {
beat: Beat;
key: KeyIndex;
}
/**
* Action for placing a tap note.
*/
export class PlaceTapAction implements Action {
args: PlaceTapArgs;
store: RootStore;
constructor(store: RootStore, args: PlaceTapArgs) {
const { chart } = store.notefield.data;
assert(args.key.value < chart.keyCount.value, "key index is out of range");
this.args = args;
this.store = store;
}
run(): void {
const { chart } = this.store.notefield.data;
const args = this.args;
chart.placeObject(new Tap(args.beat, args.key), {
removeIfExists: true,
});
}
undo(): void {
// FIXME: This won't work correctly if placing a note gets rid of a hold.
this.run();
}
}