adding new states/tools

This commit is contained in:
Daniel Ledda
2023-01-03 14:03:37 +01:00
parent fdd59cdf56
commit bcdebd3372
7 changed files with 124 additions and 29 deletions

View File

@@ -1,4 +1,4 @@
import TrackUnit, { TrackUnitEvent, TrackUnitType } from "@/TrackUnit";
import TrackUnit, { TrackUnitEvent, TrackUnitStickingType, TrackUnitType } from "@/TrackUnit";
import "./TrackUnit.css";
import { h, IPublisher, ISubscriber, ISubscription, Publisher, Rung, RungOptions } from "@djledda/ladder";
@@ -57,8 +57,7 @@ export default class TrackUnitView extends Rung<HTMLElement> implements ISubscri
private handleMouseDown(ev: MouseEvent): void {
if (ev.button === 1) {
this.trackUnit.rotateType();
} else if (ev.button === 0) {
this.toggle();
} else {
this.rotationTimeout = this.rotationTimeout || setTimeout(() => {
this.trackUnit.rotateType();
this.blockNextMouseUp = true;
@@ -103,6 +102,14 @@ export default class TrackUnitView extends Rung<HTMLElement> implements ISubscri
this.trackUnit.toggle();
}
setStickingType(type: TrackUnitStickingType): void {
this.trackUnit.setStickingType(type);
}
setType(type: TrackUnitType): void {
this.trackUnit.setType(type);
}
turnOn(): void {
this.trackUnit.setOn(true);
}
@@ -120,24 +127,39 @@ export default class TrackUnitView extends Rung<HTMLElement> implements ISubscri
this.render().classList.remove("track-unit-on");
break;
case TrackUnitEvent.TypeChange:
switch (this.trackUnit.getType()) {
case TrackUnitType.Normal:
this.render().classList.remove("track-unit-ghost");
this.render().classList.remove("track-unit-accent");
break;
case TrackUnitType.GhostNote:
this.render().classList.add("track-unit-ghost");
this.render().classList.remove("track-unit-accent");
break;
case TrackUnitType.Accent:
this.render().classList.remove("track-unit-ghost");
this.render().classList.add("track-unit-accent");
break;
case TrackUnitType.GhostNoteAccent:
this.render().classList.add("track-unit-ghost");
this.render().classList.add("track-unit-accent");
break;
}
this.syncTrackUnitType();
this.syncStickingType(this.trackUnit.getStickingType());
}
}
private syncStickingType(type: TrackUnitStickingType) {
const node = this.render();
node.classList.remove("track-unit-lh");
node.classList.remove("track-unit-rh");
node.classList.remove("track-unit-lf");
node.classList.remove("track-unit-rf");
if (type !== "none") {
node.classList.add(`track-unit-${ type }`);
}
}
private syncTrackUnitType() {
switch (this.trackUnit.getType()) {
case TrackUnitType.Normal:
this.render().classList.remove("track-unit-ghost");
this.render().classList.remove("track-unit-accent");
break;
case TrackUnitType.GhostNote:
this.render().classList.add("track-unit-ghost");
this.render().classList.remove("track-unit-accent");
break;
case TrackUnitType.Accent:
this.render().classList.remove("track-unit-ghost");
this.render().classList.add("track-unit-accent");
break;
case TrackUnitType.GhostNoteAccent:
this.render().classList.add("track-unit-ghost");
this.render().classList.add("track-unit-accent");
break;
}
}