Add public method placeChairsOnSelectedTables() and update ID generation to use crypto.randomUUID()

This commit is contained in:
2026-06-22 21:12:07 +00:00
parent 8381d916d2
commit ce33001b1e
@@ -52,7 +52,7 @@ class AutoChairPlacementTool extends Tool {
// Top side
this.yjsDoc.createElement({
id: Date.now().toString() + '_chair_top_' + i,
id: crypto.randomUUID() + '_chair_top_' + i,
type: 'chair',
layerId: 'default',
x: x + positionRatio * width - chairWidth / 2,
@@ -64,7 +64,7 @@ class AutoChairPlacementTool extends Tool {
// Bottom side
this.yjsDoc.createElement({
id: Date.now().toString() + '_chair_bottom_' + i,
id: crypto.randomUUID() + '_chair_bottom_' + i,
type: 'chair',
layerId: 'default',
x: x + positionRatio * width - chairWidth / 2,
@@ -81,7 +81,7 @@ class AutoChairPlacementTool extends Tool {
// Left side
this.yjsDoc.createElement({
id: Date.now().toString() + '_chair_left_' + i,
id: crypto.randomUUID() + '_chair_left_' + i,
type: 'chair',
layerId: 'default',
x: x - this.chairSpacing - chairWidth,
@@ -93,7 +93,7 @@ class AutoChairPlacementTool extends Tool {
// Right side
this.yjsDoc.createElement({
id: Date.now().toString() + '_chair_right_' + i,
id: crypto.randomUUID() + '_chair_right_' + i,
type: 'chair',
layerId: 'default',
x: x + width + this.chairSpacing,
@@ -118,7 +118,7 @@ class AutoChairPlacementTool extends Tool {
const chairY = centerY + (radius + this.chairSpacing) * Math.sin(angle) - chairHeight / 2;
this.yjsDoc.createElement({
id: Date.now().toString() + '_chair_' + i,
id: crypto.randomUUID() + '_chair_' + i,
type: 'chair',
layerId: 'default',
x: chairX,
@@ -130,6 +130,27 @@ class AutoChairPlacementTool extends Tool {
}
}
// Place chairs on selected tables
placeChairsOnSelectedTables(selectedTableIds: string[]): void {
// Get all elements from the document
const elements = this.yjsDoc.getElements();
// Filter for selected tables
const selectedTables = elements.filter(element =>
selectedTableIds.includes(element.id) &&
(element.type === 'rectangular_table' || element.type === 'round_table')
);
// Place chairs around each selected table
selectedTables.forEach(table => {
if (table.type === 'rectangular_table') {
this.placeChairsAroundRectangularTable(table);
} else if (table.type === 'round_table') {
this.placeChairsAroundRoundTable(table);
}
});
}
// Set chair spacing
setChairSpacing(spacing: number): void {
this.chairSpacing = spacing;