homemanager-fe/src/modules/house-planner/index.ts

49 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-01-16 19:37:39 +00:00
import { HousePlannerCanvas } from './canvas';
2023-01-20 16:43:32 +00:00
import { Layer, Vec2, Vec2Box } from './interfaces';
2023-01-18 21:20:06 +00:00
import { HousePlannerCanvasTools } from './tools';
2023-01-16 19:37:39 +00:00
export class HousePlanner {
public canvas!: HTMLCanvasElement;
public manager?: HousePlannerCanvas;
2023-01-18 18:11:54 +00:00
initialize(
canvas: HTMLCanvasElement,
initialData: Layer[],
canvasDim: Vec2,
2023-01-18 18:47:22 +00:00
canvasPos: Vec2,
2023-01-18 18:11:54 +00:00
canvasZoom = 1,
2023-01-20 16:43:32 +00:00
editable = true,
boundingBox?: Vec2Box
): [number, Vec2] {
2023-01-16 19:37:39 +00:00
this.canvas = canvas;
2023-01-18 18:11:54 +00:00
this.manager = new HousePlannerCanvas(
canvas,
canvasDim,
canvasPos,
2023-01-18 18:47:22 +00:00
canvasZoom,
editable
2023-01-18 18:11:54 +00:00
);
2023-01-16 19:37:39 +00:00
this.manager.layers = initialData;
2023-01-18 18:47:22 +00:00
if (editable && this.manager.tools) {
2023-01-18 21:20:06 +00:00
const stdToolkit = this.manager.tools as HousePlannerCanvasTools;
stdToolkit.selectLayer(
2023-01-18 18:47:22 +00:00
initialData[initialData.findIndex((layer) => layer.active)]
);
2023-01-18 21:20:06 +00:00
stdToolkit.setInitialSelection();
stdToolkit.setTool('move');
2023-01-18 18:47:22 +00:00
}
2023-01-16 19:37:39 +00:00
this.manager.draw();
2023-01-20 16:43:32 +00:00
if (boundingBox) {
this.manager.initViewport(boundingBox);
}
return [this.manager.canvasZoom, this.manager.canvasPos];
2023-01-16 19:37:39 +00:00
}
cleanUp() {
this.manager?.cleanUp();
}
}