update?
This commit is contained in:
@@ -1,8 +1,59 @@
|
||||
export enum BeatUnitType {
|
||||
Normal,
|
||||
GhostNote,
|
||||
}
|
||||
|
||||
|
||||
export default class BeatUnit {
|
||||
constructor() {
|
||||
private on: boolean = false;
|
||||
private type: BeatUnitType = BeatUnitType.Normal;
|
||||
private onUpdateCallbacks: ((on: boolean, type: BeatUnitType) => void)[] = [];
|
||||
|
||||
constructor(on: boolean = false) {
|
||||
this.on = on;
|
||||
}
|
||||
|
||||
stringify(): string {
|
||||
return "U";
|
||||
if (!this.on) {
|
||||
return "O";
|
||||
}
|
||||
if (this.type === BeatUnitType.GhostNote) {
|
||||
return "G";
|
||||
} else {
|
||||
return "#";
|
||||
}
|
||||
}
|
||||
|
||||
toggle(): void {
|
||||
this.on = !this.on;
|
||||
this.notify();
|
||||
}
|
||||
|
||||
setOn(on: boolean): void {
|
||||
this.on = on;
|
||||
this.notify();
|
||||
}
|
||||
|
||||
setType(type: BeatUnitType) {
|
||||
this.type = type;
|
||||
this.notify();
|
||||
}
|
||||
|
||||
getType(): BeatUnitType {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
isOn(): boolean {
|
||||
return this.on;
|
||||
}
|
||||
|
||||
onUpdate(callback: (on: boolean, type: BeatUnitType) => void) {
|
||||
this.onUpdateCallbacks.push(callback);
|
||||
}
|
||||
|
||||
notify(): void {
|
||||
for (const cb of this.onUpdateCallbacks) {
|
||||
cb(this.on, this.type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user