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

@@ -2,8 +2,10 @@ import Track, { TrackEvents } from "@/Track";
import TrackUnitView from "@/ui/TrackUnit/TrackUnitView";
import "./Track.css";
import { Capsule, h, ISubscriber, ISubscription, Rung, RungOptions } from "@djledda/ladder";
import AppState from "@/AppState";
export type TrackUINodeOptions = RungOptions & {
state: AppState,
track: Track,
};
@@ -24,11 +26,13 @@ export default class TrackView extends Rung implements ISubscriber<EventTypeSubs
private trackUnitViewBlock: HTMLElement | null = null;
private lastHoveredTrackUnitView: TrackUnitView | null = null;
private sub: ISubscription | null = null;
private state: AppState;
static deselectingUnits = false;
static selectingUnits = false;
constructor(options: TrackUINodeOptions) {
super(options);
this.state = options.state;
this.title = <h3></h3> as HTMLHeadingElement;
this.setTrack(options.track);
}
@@ -89,16 +93,24 @@ export default class TrackView extends Rung implements ISubscriber<EventTypeSubs
TrackView.selectingUnits = true;
} else if (button === 2) {
TrackView.deselectingUnits = true;
this.track.getUnitByIndex(index)?.setOn(false);
}
}
private onTrackUnitViewHover(trackUnitView: TrackUnitView) {
this.lastHoveredTrackUnitView = trackUnitView;
if (TrackView.selectingUnits) {
this.lastHoveredTrackUnitView.turnOn();
if (this.state.selectedTool === 'sticking') {
this.lastHoveredTrackUnitView.setStickingType(this.state.activeStickingType);
} else if (this.state.selectedTool === 'track-unit-type') {
this.lastHoveredTrackUnitView.turnOn();
this.lastHoveredTrackUnitView.setType(this.state.activeTrackUnitType);
}
} else if (TrackView.deselectingUnits) {
this.lastHoveredTrackUnitView.turnOff();
if (this.state.selectedTool === 'sticking') {
this.lastHoveredTrackUnitView.setStickingType("none");
} else if (this.state.selectedTool === 'track-unit-type') {
this.lastHoveredTrackUnitView.turnOff();
}
}
}