53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
import { HousePlannerCanvas } from './canvas';
|
|
import { Layer, Vec2, Vec2Box } from './interfaces';
|
|
import { HousePlannerCanvasTools } from './tools';
|
|
|
|
export class HousePlanner {
|
|
public canvas!: HTMLCanvasElement;
|
|
public manager?: HousePlannerCanvas;
|
|
|
|
initialize(
|
|
canvas: HTMLCanvasElement,
|
|
initialData: Layer[],
|
|
canvasDim: Vec2,
|
|
canvasPos: Vec2,
|
|
canvasZoom = 1,
|
|
editable = true,
|
|
grid = true,
|
|
headless = false,
|
|
boundingBox?: Vec2Box
|
|
): [number, Vec2] {
|
|
this.canvas = canvas;
|
|
this.manager = new HousePlannerCanvas(
|
|
canvas,
|
|
canvasDim,
|
|
canvasPos,
|
|
canvasZoom,
|
|
editable,
|
|
grid,
|
|
headless
|
|
);
|
|
this.manager.layers = initialData;
|
|
|
|
if (editable && this.manager.tools) {
|
|
const stdToolkit = this.manager.tools as HousePlannerCanvasTools;
|
|
stdToolkit.selectLayer(
|
|
initialData[initialData.findIndex((layer) => layer.active)]
|
|
);
|
|
stdToolkit.setInitialSelection();
|
|
stdToolkit.setTool('move');
|
|
}
|
|
|
|
this.manager.draw();
|
|
|
|
if (boundingBox) {
|
|
this.manager.setViewRectangle(boundingBox);
|
|
}
|
|
return [this.manager.canvasZoom, this.manager.canvasPos];
|
|
}
|
|
|
|
cleanUp() {
|
|
this.manager?.cleanUp();
|
|
}
|
|
}
|