import AppState, { AppStateEvent } from "@/AppState"; import { TrackUnitStickingTypeList, TrackUnitTypeList } from "@/TrackUnit"; import { Capsule, h, frag, Rung, RungOptions, ISubscriber } from "@djledda/ladder"; import TrackUnitView, { StickingTypeIconMap } from "../TrackUnit/TrackUnitView"; import IconView from "../Widgets/Icon/IconView"; import "./Toolbox.css"; type ToolboxOptions = RungOptions & { state: AppState, }; export default class ToolboxView extends Rung implements ISubscriber { private state: AppState; constructor(options: ToolboxOptions) { super(options); this.state = options.state; this.state.addSubscriber(this, 'appstate-tool-select'); } notify(publisher: unknown, event: AppStateEvent): void { if (event === 'appstate-tool-select') { this.redraw(); } } private SubMenuButtons = () => { switch (this.state.selectedTool) { case "track-unit-type": return
{...TrackUnitTypeList.map(type => (
this.state.selectTrackUnitTypePaint(type)}>
))}
; case "sticking": return
{...TrackUnitStickingTypeList.reduce((prev, stickingType) => { if (stickingType !== "none") { prev.push(
this.state.selectStickingTypePaint(stickingType)}> {new IconView({ iconName: StickingTypeIconMap[stickingType] })}
as HTMLButtonElement); } return prev; }, [] as HTMLElement[])}
; case "eraser": return
; } } protected build() { return
this.state.selectTool("track-unit-type")}> Track Type
this.state.selectTool("sticking")}> Sticking
this.state.selectTool("eraser")}> Eraser
as HTMLDivElement; } }