import * as PIXI from 'pixi.js'; import { DEVICE_TYPE, POINT_ROUTE_DIRECTION } from "./constants"; export default class PointRoute extends PIXI.Graphics { startSprite; endSprite; direction; type; no; constructor(direction) { super(); this.direction = direction ? direction : POINT_ROUTE_DIRECTION.OUT_OF_ORDER; // this.data = { // type: DEVICE_TYPE.ROUTE // }; this.type = DEVICE_TYPE.ROUTE; } style() { const scale = 1; this.clear(); this.lineStyle(1.5, 0x2d3436); this.moveTo(this.startSprite.x * scale, this.startSprite.y * scale); this.lineTo(this.endSprite.x * scale, this.endSprite.y * scale); } setPoint(startSprite, endSprite) { this.startSprite = startSprite; this.endSprite = endSprite; // this.data.no = this.startSprite?.data?.no + "-" + this.endSprite?.data?.no; this.no = this.startSprite?.data?.no + "-" + this.endSprite?.data?.no; } update(dragSprite) { const scale = 1; this.clear(); this.lineStyle(1.5, 0x2d3436); if (dragSprite === this.startSprite) { this.moveTo(dragSprite.position.x * scale, dragSprite.position.y * scale); } else { this.moveTo(this.startSprite.position.x * scale, this.startSprite.position.y * scale); } if (dragSprite === this.endSprite) { this.lineTo(dragSprite.position.x * scale, dragSprite.position.y * scale); } else { this.lineTo(this.endSprite.position.x * scale, this.endSprite.position.y * scale); } } about(sprite) { return sprite === this.startSprite || sprite === this.endSprite; } has(startSprite, endSprite) { let res = false; switch (this.direction) { case POINT_ROUTE_DIRECTION.OUT_OF_ORDER: if (startSprite === this.startSprite) { if (endSprite === this.endSprite) { res = true; } } if (startSprite === this.endSprite) { if (endSprite === this.startSprite) { res = true; } } break case POINT_ROUTE_DIRECTION.ORDER: if (startSprite === this.startSprite) { if (endSprite === this.endSprite) { res = true; } } break case POINT_ROUTE_DIRECTION.REVERSE_ORDER: if (startSprite === this.endSprite) { if (endSprite === this.startSprite) { res = true; } } break default: break } return res; } }