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

44 lines
1012 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-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,
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) {
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();
}
cleanUp() {
this.manager?.cleanUp();
}
}