75 lines
2.1 KiB
TypeScript
75 lines
2.1 KiB
TypeScript
import { Tool } from '../Tool';
|
|
import { YjsDocument } from '../../crdt/YjsDocument';
|
|
|
|
class CapacityDisplayTool extends Tool {
|
|
private onCapacityUpdate: (totalCapacity: number, selectedCapacity: number) => void;
|
|
|
|
constructor(yjsDoc: YjsDocument, onCapacityUpdate?: (totalCapacity: number, selectedCapacity: number) => void) {
|
|
super(yjsDoc);
|
|
this.name = 'CapacityDisplayTool';
|
|
this.onCapacityUpdate = onCapacityUpdate || (() => {});
|
|
}
|
|
|
|
onMouseDown(event: MouseEvent): void {
|
|
// This tool doesn't create elements on mouse click
|
|
// It displays capacity information based on selected elements or entire drawing
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
// Calculate capacity for selected tables
|
|
calculateSelectedCapacity(): number {
|
|
// In a real implementation, this would get selected tables from the canvas
|
|
// For now, we'll count all chair elements as selected capacity
|
|
const elements = this.yjsDoc.getElements();
|
|
let count = 0;
|
|
elements.forEach(element => {
|
|
if (element.type === 'chair') {
|
|
count++;
|
|
}
|
|
});
|
|
return count;
|
|
}
|
|
|
|
// Calculate capacity for entire drawing
|
|
calculateTotalCapacity(): number {
|
|
// Iterate through all elements in the Yjs document
|
|
// and count chairs
|
|
const elements = this.yjsDoc.getElements();
|
|
let count = 0;
|
|
elements.forEach(element => {
|
|
if (element.type === 'chair') {
|
|
count++;
|
|
}
|
|
});
|
|
return count;
|
|
}
|
|
|
|
// Display capacity information
|
|
displayCapacity(): void {
|
|
const totalCapacity = this.calculateTotalCapacity();
|
|
const selectedCapacity = this.calculateSelectedCapacity();
|
|
|
|
// Update the UI through the callback
|
|
this.onCapacityUpdate(totalCapacity, selectedCapacity);
|
|
}
|
|
}
|
|
|
|
export { CapacityDisplayTool }; |