class FloorManager { constructor(canvasManager) { this.canvasManager = canvasManager; } // Create a floor element (4-sided rectangle) createFloorElement(startX, startY, endX, endY, material, color) { const floor = { id: 'floor-' + Date.now(), type: 'floor', startX: Math.min(startX, endX), startY: Math.min(startY, endY), endX: Math.max(startX, endX), endY: Math.max(startY, endY), width: Math.abs(endX - startX), height: Math.abs(endY - startY), color: color || '#D2B48C', // Default tan/wood color material: material || 'wood', opacity: 0.7 // Slightly transparent so you can see walls on top }; console.log('Floor created:', floor); return floor; } // Draw a floor element drawFloor(floor) { const ctx = this.canvasManager.ctx; // Save context state ctx.save(); // Set opacity ctx.globalAlpha = floor.opacity || 0.7; // Fill the floor ctx.fillStyle = floor.color; ctx.fillRect(floor.startX, floor.startY, floor.width, floor.height); // Draw border ctx.strokeStyle = this.darkenColor(floor.color, 20); ctx.lineWidth = 2; ctx.strokeRect(floor.startX, floor.startY, floor.width, floor.height); // Draw texture pattern (optional - makes it look more like flooring) this.drawFloorPattern(floor); // Restore context state ctx.restore(); } // Draw floor preview while dragging drawFloorPreview(startX, startY, currentX, currentY) { const ctx = this.canvasManager.ctx; const width = currentX - startX; const height = currentY - startY; ctx.save(); ctx.globalAlpha = 0.5; ctx.fillStyle = '#D2B48C'; ctx.fillRect(startX, startY, width, height); ctx.strokeStyle = '#8B7355'; ctx.lineWidth = 2; ctx.setLineDash([5, 5]); ctx.strokeRect(startX, startY, width, height); ctx.setLineDash([]); ctx.restore(); } // Draw floor area measurement drawFloorArea(startX, startY, currentX, currentY) { const width = Math.abs(currentX - startX); const height = Math.abs(currentY - startY); const area = width * height; const centerX = (startX + currentX) / 2; const centerY = (startY + currentY) / 2; const ctx = this.canvasManager.ctx; ctx.save(); ctx.fillStyle = 'rgba(0, 0, 0, 0.7)'; ctx.font = '12px Arial'; ctx.textAlign = 'center'; ctx.fillText(`${width.toFixed(0)} × ${height.toFixed(0)}`, centerX, centerY - 10); ctx.fillText(`Area: ${area.toFixed(0)} sq px`, centerX, centerY + 10); ctx.restore(); } // Draw a pattern on the floor to make it look more realistic drawFloorPattern(floor) { const ctx = this.canvasManager.ctx; const material = floor.material || 'wood'; ctx.save(); ctx.strokeStyle = this.darkenColor(floor.color, 10); ctx.lineWidth = 1; ctx.globalAlpha = 0.3; if (material === 'wood' || material === 'tile') { // Draw planks or tiles const spacing = material === 'wood' ? 40 : 30; // Horizontal lines for (let y = floor.startY + spacing; y < floor.startY + floor.height; y += spacing) { ctx.beginPath(); ctx.moveTo(floor.startX, y); ctx.lineTo(floor.startX + floor.width, y); ctx.stroke(); } // Vertical lines (for tiles, not wood planks) if (material === 'tile') { for (let x = floor.startX + spacing; x < floor.startX + floor.width; x += spacing) { ctx.beginPath(); ctx.moveTo(x, floor.startY); ctx.lineTo(x, floor.startY + floor.height); ctx.stroke(); } } } else if (material === 'carpet') { // Draw a subtle texture for carpet ctx.globalAlpha = 0.1; for (let i = 0; i < 50; i++) { const x = floor.startX + Math.random() * floor.width; const y = floor.startY + Math.random() * floor.height; ctx.fillStyle = this.darkenColor(floor.color, Math.random() * 20); ctx.fillRect(x, y, 2, 2); } } ctx.restore(); } // Check if a point is inside a floor isPointInFloor(x, y, floor) { return x >= floor.startX && x <= floor.startX + floor.width && y >= floor.startY && y <= floor.startY + floor.height; } // Helper function to darken a color darkenColor(color, percent) { // Convert hex to RGB let r = parseInt(color.slice(1, 3), 16); let g = parseInt(color.slice(3, 5), 16); let b = parseInt(color.slice(5, 7), 16); // Darken r = Math.max(0, r - percent); g = Math.max(0, g - percent); b = Math.max(0, b - percent); // Convert back to hex return '#' + r.toString(16).padStart(2, '0') + g.toString(16).padStart(2, '0') + b.toString(16).padStart(2, '0'); } // Get floor material options getFloorMaterials() { return [ { value: 'wood', label: 'Wood', color: '#D2B48C' }, { value: 'tile', label: 'Tile', color: '#E8E8E8' }, { value: 'carpet', label: 'Carpet', color: '#8B7D6B' }, { value: 'concrete', label: 'Concrete', color: '#A9A9A9' }, { value: 'marble', label: 'Marble', color: '#F5F5F5' }, { value: 'laminate', label: 'Laminate', color: '#C19A6B' } ]; } }