66 lines
2.2 KiB
JavaScript
66 lines
2.2 KiB
JavaScript
import { Graphics, Color } from 'pixi.js';
|
|
import { JlGraphic } from 'jl-graphic';
|
|
import { getSeparatorConsts, separatorTypeEnum } from './SeparatorConfig.js';
|
|
|
|
/**
|
|
* 分隔符
|
|
* @param {UpdateSeparatorConsts}常量数据
|
|
*
|
|
*/
|
|
class Separator extends JlGraphic {
|
|
static Type = 'Separator';
|
|
rectGraphic = new Graphics();
|
|
circleGraphic = new Graphics();
|
|
constDatas;
|
|
constructor(data) {
|
|
super(Separator.Type);
|
|
this.addChild(this.rectGraphic);
|
|
this.addChild(this.circleGraphic);
|
|
this.constDatas = getSeparatorConsts();
|
|
if (data) {
|
|
Object.assign(this.constDatas, data);
|
|
}
|
|
}
|
|
get datas() {
|
|
return this.getDatas();
|
|
}
|
|
clear() {
|
|
this.rectGraphic.clear();
|
|
this.circleGraphic.clear();
|
|
}
|
|
doRepaint() {
|
|
this.clear();
|
|
const rectGraphic = this.rectGraphic;
|
|
if (!this.datas.separatorType) {
|
|
this.datas.separatorType = separatorTypeEnum.endA;
|
|
}
|
|
const typeArr = ['section', 'turnout'];
|
|
if (typeArr.includes(this.datas.separatorType)) {
|
|
rectGraphic.lineStyle(this.constDatas.lineWidth, new Color(this.constDatas.lineColor));
|
|
rectGraphic.moveTo(0, -this.constDatas.height / 2);
|
|
rectGraphic.lineTo(0, this.constDatas.height / 2);
|
|
if (this.datas.separatorType == 'turnout') {
|
|
this.circleGraphic.lineStyle(1, this.constDatas.circleColor);
|
|
this.circleGraphic.drawCircle(0, 0, this.constDatas.radius);
|
|
}
|
|
}
|
|
const endTypeArr = ['endA', 'endB'];
|
|
if (endTypeArr.includes(this.datas.separatorType)) {
|
|
let d = this.constDatas.radius;
|
|
if (this.datas.separatorType == 'endB') {
|
|
d = -d;
|
|
}
|
|
rectGraphic.lineStyle(this.constDatas.lineWidth, new Color(this.constDatas.lineColor));
|
|
rectGraphic.moveTo(0, 0);
|
|
rectGraphic.lineTo(-d, 0);
|
|
rectGraphic.lineTo(-d, -d);
|
|
rectGraphic.lineTo(-d * 3, -d);
|
|
rectGraphic.moveTo(-d, 0);
|
|
rectGraphic.lineTo(-d, d);
|
|
rectGraphic.lineTo(-d * 3, d);
|
|
}
|
|
}
|
|
}
|
|
|
|
export { Separator };
|