import { Component, ComponentNature, sceneComponent } from '@hatiolab/things-scene' import MCSTransport from './mcs-transport' const NATURE: ComponentNature = { mutable: false, resizable: true, rotatable: true, properties: [...MCSTransport.properties] } @sceneComponent('CraneRail') export default class CraneRail extends MCSTransport { static get nature() { return NATURE } containable(component: Component) { return ['Crane', 'Node'].includes(component.state.type) } get auxColor() { return '#555' } getLegendFallback() { return (this.root as any).craneRailLegendTheme || super.getLegendFallback() } render(ctx: CanvasRenderingContext2D) { const { left, top, width, height } = this.bounds ctx.translate(left, top) ctx.beginPath() ctx.fillStyle = this.statusColor! ctx.strokeStyle = this.auxColor ctx.lineWidth = 2 ctx.setLineDash([]) ctx.fillRect(0, 0, width, height) // 양쪽 레일 (실선) if (width > height) { ctx.moveTo(0, 0) ctx.lineTo(width, 0) ctx.moveTo(0, height) ctx.lineTo(width, height) } else { ctx.moveTo(0, 0) ctx.lineTo(0, height) ctx.moveTo(width, 0) ctx.lineTo(width, height) } ctx.stroke() ctx.translate(-left, -top) } }