2023-12-25 16:37:59 +08:00
|
|
|
import { Graphics, Color } from 'pixi.js';
|
2024-01-02 14:36:10 +08:00
|
|
|
import { JlGraphic } from 'jl-graphic';
|
|
|
|
import { getSeparatorConsts, separatorTypeEnum } from './SeparatorConfig.js';
|
2023-12-25 16:37:59 +08:00
|
|
|
|
2024-01-02 14:36:10 +08:00
|
|
|
/**
|
|
|
|
* 分隔符
|
|
|
|
* @param {UpdateSeparatorConsts}常量数据
|
|
|
|
*
|
|
|
|
*/
|
2023-12-25 16:37:59 +08:00
|
|
|
class Separator extends JlGraphic {
|
|
|
|
static Type = 'Separator';
|
|
|
|
rectGraphic = new Graphics();
|
|
|
|
circleGraphic = new Graphics();
|
2024-01-02 14:36:10 +08:00
|
|
|
constDatas;
|
|
|
|
constructor(data) {
|
2023-12-25 16:37:59 +08:00
|
|
|
super(Separator.Type);
|
|
|
|
this.addChild(this.rectGraphic);
|
|
|
|
this.addChild(this.circleGraphic);
|
2024-01-02 14:36:10 +08:00
|
|
|
this.constDatas = getSeparatorConsts();
|
|
|
|
if (data) {
|
|
|
|
Object.assign(this.constDatas, data);
|
|
|
|
}
|
2023-12-25 16:37:59 +08:00
|
|
|
}
|
|
|
|
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)) {
|
2024-01-02 14:36:10 +08:00
|
|
|
rectGraphic.lineStyle(this.constDatas.lineWidth, new Color(this.constDatas.lineColor));
|
|
|
|
rectGraphic.moveTo(0, -this.constDatas.height / 2);
|
|
|
|
rectGraphic.lineTo(0, this.constDatas.height / 2);
|
2023-12-25 16:37:59 +08:00
|
|
|
if (this.datas.separatorType == 'turnout') {
|
2024-01-02 14:36:10 +08:00
|
|
|
this.circleGraphic.lineStyle(1, this.constDatas.circleColor);
|
|
|
|
this.circleGraphic.drawCircle(0, 0, this.constDatas.radius);
|
2023-12-25 16:37:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const endTypeArr = ['endA', 'endB'];
|
|
|
|
if (endTypeArr.includes(this.datas.separatorType)) {
|
2024-01-02 14:36:10 +08:00
|
|
|
let d = this.constDatas.radius;
|
2023-12-25 16:37:59 +08:00
|
|
|
if (this.datas.separatorType == 'endB') {
|
|
|
|
d = -d;
|
|
|
|
}
|
2024-01-02 14:36:10 +08:00
|
|
|
rectGraphic.lineStyle(this.constDatas.lineWidth, new Color(this.constDatas.lineColor));
|
2023-12-25 16:37:59 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-02 14:36:10 +08:00
|
|
|
export { Separator };
|