Create RotateSeatingGroupTool.ts to implement rotation functionality
This commit is contained in:
@@ -0,0 +1,75 @@
|
|||||||
|
import { Tool } from '../Tool';
|
||||||
|
import { YjsDocument } from '../../crdt/YjsDocument';
|
||||||
|
|
||||||
|
class RotateSeatingGroupTool extends Tool {
|
||||||
|
private selectedElementIds: string[] = [];
|
||||||
|
private rotationAngle: number = 90; // Default rotation angle in degrees
|
||||||
|
|
||||||
|
constructor(yjsDoc: YjsDocument) {
|
||||||
|
super(yjsDoc);
|
||||||
|
this.name = 'RotateSeatingGroupTool';
|
||||||
|
}
|
||||||
|
|
||||||
|
onMouseDown(event: MouseEvent): void {
|
||||||
|
// This tool works on selected elements, not on mouse clicks
|
||||||
|
// The actual rotation logic would be triggered through a UI action
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
this.selectedElementIds = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rotate selected elements
|
||||||
|
rotateSelectedElements(): void {
|
||||||
|
// Get all elements from the document
|
||||||
|
const elements = this.yjsDoc.getElements();
|
||||||
|
|
||||||
|
// Filter for selected elements
|
||||||
|
const selectedElements = elements.filter(element =>
|
||||||
|
this.selectedElementIds.includes(element.id)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Rotate each selected element
|
||||||
|
selectedElements.forEach(element => {
|
||||||
|
// Calculate new rotation (add rotation angle, wrapping at 360 degrees)
|
||||||
|
let newRotation = element.properties.rotation || 0;
|
||||||
|
newRotation = (newRotation + this.rotationAngle) % 360;
|
||||||
|
|
||||||
|
// Update element with new rotation property
|
||||||
|
this.yjsDoc.updateElement(element.id, {
|
||||||
|
properties: {
|
||||||
|
...element.properties,
|
||||||
|
rotation: newRotation
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set selected elements
|
||||||
|
setSelectedElements(elementIds: string[]): void {
|
||||||
|
this.selectedElementIds = elementIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set rotation angle
|
||||||
|
setRotationAngle(angle: number): void {
|
||||||
|
this.rotationAngle = angle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { RotateSeatingGroupTool };
|
||||||
Reference in New Issue
Block a user