Add AutoChairPlacementTool for automatic chair placement around tables

This commit is contained in:
2026-06-22 21:03:45 +00:00
parent d5e1daae82
commit 8d5a9f4eb9
@@ -0,0 +1,149 @@
import { Tool } from '../Tool';
import { YjsDocument } from '../../crdt/YjsDocument';
class AutoChairPlacementTool extends Tool {
private chairSpacing: number = 60; // Default spacing between chairs
private chairsPerSide: number = 2; // Default chairs per side for rectangular tables
private chairsAroundRound: number = 8; // Default chairs around round tables
constructor(yjsDoc: YjsDocument) {
super(yjsDoc);
this.name = 'AutoChairPlacementTool';
}
onMouseDown(event: MouseEvent): void {
// This tool works on selected tables, not on mouse clicks
// The actual placement logic would be triggered through a UI action
// rather than a mouse click on the canvas
}
onMouseMove(event: MouseEvent): void {
// No preview needed for this tool
}
onMouseUp(event: MouseEvent): void {
// No action needed on mouse up
}
onKeyUp(event: KeyboardEvent): void {
// Handle key up events
if (event.key === 'Escape') {
this.reset();
}
}
reset(): void {
// Reset any state if needed
}
// Place chairs around a rectangular table
placeChairsAroundRectangularTable(table: any): void {
const { x, y, width, height } = table;
const chairWidth = 45;
const chairHeight = 45;
// Calculate chairs per side based on table dimensions
const chairsOnLongSides = this.chairsPerSide;
const chairsOnShortSides = Math.max(1, Math.floor(this.chairsPerSide * (Math.min(width, height) / Math.max(width, height))));
// Place chairs on the longer sides (top and bottom)
for (let i = 0; i < chairsOnLongSides; i++) {
const positionRatio = (i + 1) / (chairsOnLongSides + 1);
// Top side
this.yjsDoc.createElement({
id: Date.now().toString() + '_chair_top_' + i,
type: 'chair',
layerId: 'default',
x: x + positionRatio * width - chairWidth / 2,
y: y - this.chairSpacing - chairHeight,
width: chairWidth,
height: chairHeight,
properties: {}
});
// Bottom side
this.yjsDoc.createElement({
id: Date.now().toString() + '_chair_bottom_' + i,
type: 'chair',
layerId: 'default',
x: x + positionRatio * width - chairWidth / 2,
y: y + height + this.chairSpacing,
width: chairWidth,
height: chairHeight,
properties: {}
});
}
// Place chairs on the shorter sides (left and right)
for (let i = 0; i < chairsOnShortSides; i++) {
const positionRatio = (i + 1) / (chairsOnShortSides + 1);
// Left side
this.yjsDoc.createElement({
id: Date.now().toString() + '_chair_left_' + i,
type: 'chair',
layerId: 'default',
x: x - this.chairSpacing - chairWidth,
y: y + positionRatio * height - chairHeight / 2,
width: chairWidth,
height: chairHeight,
properties: {}
});
// Right side
this.yjsDoc.createElement({
id: Date.now().toString() + '_chair_right_' + i,
type: 'chair',
layerId: 'default',
x: x + width + this.chairSpacing,
y: y + positionRatio * height - chairHeight / 2,
width: chairWidth,
height: chairHeight,
properties: {}
});
}
}
// Place chairs around a round table
placeChairsAroundRoundTable(table: any): void {
const { centerX, centerY, radius } = table.properties;
const chairWidth = 45;
const chairHeight = 45;
// Place chairs in a circle around the table
for (let i = 0; i < this.chairsAroundRound; i++) {
const angle = (2 * Math.PI * i) / this.chairsAroundRound;
const chairX = centerX + (radius + this.chairSpacing) * Math.cos(angle) - chairWidth / 2;
const chairY = centerY + (radius + this.chairSpacing) * Math.sin(angle) - chairHeight / 2;
this.yjsDoc.createElement({
id: Date.now().toString() + '_chair_' + i,
type: 'chair',
layerId: 'default',
x: chairX,
y: chairY,
width: chairWidth,
height: chairHeight,
properties: {}
});
}
}
// Set chair spacing
setChairSpacing(spacing: number): void {
this.chairSpacing = spacing;
}
// Set chairs per side for rectangular tables
setChairsPerSide(count: number): void {
this.chairsPerSide = count;
}
// Set chairs around round tables
setChairsAroundRound(count: number): void {
this.chairsAroundRound = count;
}
}
export { AutoChairPlacementTool };