Add public method placeChairsOnSelectedTables() and update ID generation to use crypto.randomUUID()
This commit is contained in:
@@ -52,7 +52,7 @@ class AutoChairPlacementTool extends Tool {
|
|||||||
|
|
||||||
// Top side
|
// Top side
|
||||||
this.yjsDoc.createElement({
|
this.yjsDoc.createElement({
|
||||||
id: Date.now().toString() + '_chair_top_' + i,
|
id: crypto.randomUUID() + '_chair_top_' + i,
|
||||||
type: 'chair',
|
type: 'chair',
|
||||||
layerId: 'default',
|
layerId: 'default',
|
||||||
x: x + positionRatio * width - chairWidth / 2,
|
x: x + positionRatio * width - chairWidth / 2,
|
||||||
@@ -64,7 +64,7 @@ class AutoChairPlacementTool extends Tool {
|
|||||||
|
|
||||||
// Bottom side
|
// Bottom side
|
||||||
this.yjsDoc.createElement({
|
this.yjsDoc.createElement({
|
||||||
id: Date.now().toString() + '_chair_bottom_' + i,
|
id: crypto.randomUUID() + '_chair_bottom_' + i,
|
||||||
type: 'chair',
|
type: 'chair',
|
||||||
layerId: 'default',
|
layerId: 'default',
|
||||||
x: x + positionRatio * width - chairWidth / 2,
|
x: x + positionRatio * width - chairWidth / 2,
|
||||||
@@ -81,7 +81,7 @@ class AutoChairPlacementTool extends Tool {
|
|||||||
|
|
||||||
// Left side
|
// Left side
|
||||||
this.yjsDoc.createElement({
|
this.yjsDoc.createElement({
|
||||||
id: Date.now().toString() + '_chair_left_' + i,
|
id: crypto.randomUUID() + '_chair_left_' + i,
|
||||||
type: 'chair',
|
type: 'chair',
|
||||||
layerId: 'default',
|
layerId: 'default',
|
||||||
x: x - this.chairSpacing - chairWidth,
|
x: x - this.chairSpacing - chairWidth,
|
||||||
@@ -93,7 +93,7 @@ class AutoChairPlacementTool extends Tool {
|
|||||||
|
|
||||||
// Right side
|
// Right side
|
||||||
this.yjsDoc.createElement({
|
this.yjsDoc.createElement({
|
||||||
id: Date.now().toString() + '_chair_right_' + i,
|
id: crypto.randomUUID() + '_chair_right_' + i,
|
||||||
type: 'chair',
|
type: 'chair',
|
||||||
layerId: 'default',
|
layerId: 'default',
|
||||||
x: x + width + this.chairSpacing,
|
x: x + width + this.chairSpacing,
|
||||||
@@ -118,7 +118,7 @@ class AutoChairPlacementTool extends Tool {
|
|||||||
const chairY = centerY + (radius + this.chairSpacing) * Math.sin(angle) - chairHeight / 2;
|
const chairY = centerY + (radius + this.chairSpacing) * Math.sin(angle) - chairHeight / 2;
|
||||||
|
|
||||||
this.yjsDoc.createElement({
|
this.yjsDoc.createElement({
|
||||||
id: Date.now().toString() + '_chair_' + i,
|
id: crypto.randomUUID() + '_chair_' + i,
|
||||||
type: 'chair',
|
type: 'chair',
|
||||||
layerId: 'default',
|
layerId: 'default',
|
||||||
x: chairX,
|
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
|
// Set chair spacing
|
||||||
setChairSpacing(spacing: number): void {
|
setChairSpacing(spacing: number): void {
|
||||||
this.chairSpacing = spacing;
|
this.chairSpacing = spacing;
|
||||||
|
|||||||
Reference in New Issue
Block a user