2023-01-18 18:11:54 +00:00
|
|
|
import { Ref } from 'vue';
|
2023-01-16 19:37:39 +00:00
|
|
|
import { HousePlannerCanvas } from './canvas';
|
2023-01-18 18:11:54 +00:00
|
|
|
import { Layer, Vec2 } from './interfaces';
|
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,
|
|
|
|
canvasPos: Ref<Vec2>,
|
|
|
|
canvasZoom = 1,
|
|
|
|
editable = true
|
|
|
|
) {
|
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,
|
|
|
|
canvasZoom
|
|
|
|
);
|
2023-01-16 19:37:39 +00:00
|
|
|
this.manager.layers = initialData;
|
|
|
|
this.manager.tools.selectLayer(
|
|
|
|
initialData[initialData.findIndex((layer) => layer.active)]
|
|
|
|
);
|
2023-01-18 17:00:51 +00:00
|
|
|
this.manager.tools.setInitialSelection();
|
|
|
|
this.manager.tools.setTool('move');
|
2023-01-16 19:37:39 +00:00
|
|
|
this.manager.draw();
|
|
|
|
return () => this.cleanUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanUp() {
|
|
|
|
this.manager?.cleanUp();
|
|
|
|
}
|
|
|
|
}
|