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

43 lines
946 B
TypeScript
Raw Normal View History

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,
2023-01-18 18:47:22 +00:00
canvasPos: Vec2,
2023-01-18 18:11:54 +00:00
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,
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) {
this.manager.tools.selectLayer(
initialData[initialData.findIndex((layer) => layer.active)]
);
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();
}
}