276 lines
9.6 KiB
JavaScript
276 lines
9.6 KiB
JavaScript
|
import { JlGraphic, calculateMirrorPoint } from 'jl-graphic';
|
||
|
import { Graphics, Point } from 'pixi.js';
|
||
|
import { SignalCode } from '../common/SignalCode.js';
|
||
|
import { LampMainBody } from './LampMainBody.js';
|
||
|
|
||
|
/** 信号机类型 */
|
||
|
var Model;
|
||
|
(function (Model) {
|
||
|
Model[Model["HL"] = 0] = "HL";
|
||
|
Model[Model["HLU_FU"] = 1] = "HLU_FU";
|
||
|
Model[Model["HLU_DU_YY"] = 2] = "HLU_DU_YY";
|
||
|
Model[Model["HLU_YY"] = 3] = "HLU_YY";
|
||
|
Model[Model["HLU_FL_DU_YY"] = 4] = "HLU_FL_DU_YY";
|
||
|
Model[Model["HLU_DU"] = 5] = "HLU_DU";
|
||
|
Model[Model["AB"] = 6] = "AB";
|
||
|
Model[Model["HBU_DU"] = 7] = "HBU_DU";
|
||
|
})(Model || (Model = {}));
|
||
|
/** 信号机颜色 */
|
||
|
var SignalColorEnum;
|
||
|
(function (SignalColorEnum) {
|
||
|
SignalColorEnum["humanControlColor"] = "0xffff00";
|
||
|
SignalColorEnum["fleetModeColor"] = "0x00ff00";
|
||
|
SignalColorEnum["blockedColor"] = "0XFF0000";
|
||
|
SignalColorEnum["defaultCodeColor"] = "0XFFFFFF";
|
||
|
SignalColorEnum["lampPostColor"] = "0xFFFFFF";
|
||
|
SignalColorEnum["redLamp"] = "0XFF0000";
|
||
|
SignalColorEnum["greenLamp"] = "0X00FF00";
|
||
|
SignalColorEnum["yellowLamp"] = "0XFFFF00";
|
||
|
SignalColorEnum["whiteLamp"] = "0XFFFFFF";
|
||
|
SignalColorEnum["blueLamp"] = "0X0033FF";
|
||
|
SignalColorEnum["closeLamp"] = "0X000000";
|
||
|
SignalColorEnum["logicModeColor"] = "0x000000";
|
||
|
SignalColorEnum["lampLineColor"] = "0x3149c3";
|
||
|
})(SignalColorEnum || (SignalColorEnum = {}));
|
||
|
/** 信号机常量 */
|
||
|
const signalConsts = {
|
||
|
fleetModeLength: 24,
|
||
|
fleetModeRadius: 8,
|
||
|
fleetModeLineWidth: 6,
|
||
|
humanControlRadius: 8,
|
||
|
codeOffset: 20,
|
||
|
codeFontSize: 11,
|
||
|
blockedLineWidth: 1,
|
||
|
verticalLampPostLength: 16,
|
||
|
levelLampPostLength: 4,
|
||
|
postLineWidth: 3,
|
||
|
lampRadius: 8,
|
||
|
logicModeLineWidth: 2,
|
||
|
logicModeDistance: 5,
|
||
|
lampLineWidth: 1,
|
||
|
};
|
||
|
/** 动画 */
|
||
|
const anmiationNameConst = {
|
||
|
signaRedFlash: 'signal_red_flash',
|
||
|
signalGreenFlash: 'signal_green_flash',
|
||
|
signalYellowFlash: 'signal_yellow_flash',
|
||
|
signalWhiteFlash: 'signal_white_flash',
|
||
|
signalBlueFlash: 'signal_blue_flash',
|
||
|
};
|
||
|
class Signal extends JlGraphic {
|
||
|
static Type = 'signal';
|
||
|
datas;
|
||
|
signalCode = new SignalCode();
|
||
|
humanControl = new Graphics();
|
||
|
fleetMode = new Graphics();
|
||
|
lampMainBody = new LampMainBody();
|
||
|
blockedMode = new Graphics();
|
||
|
constructor(datas) {
|
||
|
super(Signal.Type);
|
||
|
this.datas = datas;
|
||
|
this.addChild(this.humanControl);
|
||
|
this.addChild(this.fleetMode);
|
||
|
this.addChild(this.lampMainBody);
|
||
|
this.addChild(this.signalCode);
|
||
|
this.signalCode.name = 'signalCode';
|
||
|
}
|
||
|
doRepaint() {
|
||
|
const mirror = this.datas.mirror;
|
||
|
this.lampMainBody.paint(this.datas.mt, mirror);
|
||
|
this.signalCode.paint(this.datas);
|
||
|
const codeTransform = this.datas?.childTransforms?.find((item) => item.name === 'signalCode');
|
||
|
if (codeTransform) {
|
||
|
const position = codeTransform?.transform.position;
|
||
|
const rotation = codeTransform?.transform?.rotation;
|
||
|
this.signalCode.position.set(position?.x, position?.y);
|
||
|
this.signalCode.rotation = rotation || 0;
|
||
|
}
|
||
|
else {
|
||
|
this.signalCode.position.set(0, signalConsts.codeOffset);
|
||
|
}
|
||
|
}
|
||
|
stopAnmiation() {
|
||
|
const redFlashA = this.animation(anmiationNameConst.signaRedFlash);
|
||
|
const greenFlashA = this.animation(anmiationNameConst.signalGreenFlash);
|
||
|
const blueFlashA = this.animation(anmiationNameConst.signalBlueFlash);
|
||
|
const yellowFlashA = this.animation(anmiationNameConst.signalYellowFlash);
|
||
|
const whiteFlashA = this.animation(anmiationNameConst.signalWhiteFlash);
|
||
|
if (redFlashA) {
|
||
|
redFlashA.pause();
|
||
|
}
|
||
|
if (greenFlashA) {
|
||
|
greenFlashA.pause();
|
||
|
}
|
||
|
if (blueFlashA) {
|
||
|
blueFlashA.pause();
|
||
|
}
|
||
|
if (yellowFlashA) {
|
||
|
yellowFlashA.pause();
|
||
|
}
|
||
|
if (whiteFlashA) {
|
||
|
whiteFlashA.pause();
|
||
|
}
|
||
|
}
|
||
|
/** 设置状态自动进路 */
|
||
|
setStateFleetMode() {
|
||
|
const mirror = this.datas.mirror;
|
||
|
this.fleetMode.beginFill(SignalColorEnum.fleetModeColor, 1);
|
||
|
let lmp = new Point(this.lampMainBody.width + signalConsts.fleetModeLength, 0);
|
||
|
if (mirror) {
|
||
|
lmp = calculateMirrorPoint(new Point(0, 0), lmp);
|
||
|
}
|
||
|
drawArrow(this.fleetMode, lmp.x, 0, signalConsts.fleetModeLength, signalConsts.fleetModeRadius, signalConsts.fleetModeLineWidth, mirror);
|
||
|
this.fleetMode.endFill();
|
||
|
}
|
||
|
/** 设置状态人工控 */
|
||
|
setStateHumanControl() {
|
||
|
const mirror = this.datas.mirror;
|
||
|
this.humanControl.beginFill(SignalColorEnum.humanControlColor, 1);
|
||
|
if (this.humanControl.drawRegularPolygon) {
|
||
|
let hmp = new Point(-signalConsts.humanControlRadius, 0);
|
||
|
if (mirror) {
|
||
|
hmp = calculateMirrorPoint(new Point(0, 0), hmp);
|
||
|
}
|
||
|
this.humanControl.drawRegularPolygon(hmp.x, hmp.y, signalConsts.humanControlRadius, 3, (Math.PI / 2) * (mirror ? -1 : 1));
|
||
|
}
|
||
|
this.humanControl.endFill();
|
||
|
}
|
||
|
/** 设置状态封锁 */
|
||
|
setStateBlocked() {
|
||
|
this.signalCode.createBlockedMode();
|
||
|
}
|
||
|
/** 设置状态蓝显 */
|
||
|
setStateBlueShow() {
|
||
|
this.lampMainBody.setStateBlueShow();
|
||
|
}
|
||
|
/** 设置状态信号机损坏 */
|
||
|
setStateSignalBad() {
|
||
|
this.lampMainBody.setStateLampBad();
|
||
|
}
|
||
|
/** 设置状态逻辑点灯 */
|
||
|
setStateLogic() {
|
||
|
this.lampMainBody.setStateLogic();
|
||
|
}
|
||
|
/** 设置状态红灯 */
|
||
|
setStateH() {
|
||
|
this.lampMainBody.setStateH();
|
||
|
}
|
||
|
/** 设置状态绿灯 */
|
||
|
setStateL() {
|
||
|
this.lampMainBody.setStateL();
|
||
|
}
|
||
|
/** 设置状态黄灯 */
|
||
|
setStateU() {
|
||
|
this.lampMainBody.setStateU();
|
||
|
}
|
||
|
/** 设置状态红黄灯 */
|
||
|
setStateHu() {
|
||
|
this.lampMainBody.setStateHu();
|
||
|
}
|
||
|
/** 设置状态白灯 */
|
||
|
setStateA() {
|
||
|
this.lampMainBody.setStateA();
|
||
|
}
|
||
|
/** 设置状态蓝灯 */
|
||
|
setStateB() {
|
||
|
this.lampMainBody.setStateB();
|
||
|
}
|
||
|
/** 设置状态灯位关闭 */
|
||
|
setStateOff() {
|
||
|
this.lampMainBody.setStateOff();
|
||
|
}
|
||
|
/** 设置状态红闪 */
|
||
|
setStateRedFlash() {
|
||
|
let redFlashA = this.animation(anmiationNameConst.signaRedFlash);
|
||
|
if (!redFlashA) {
|
||
|
redFlashA = this.lampMainBody.createFlashAnmiation(anmiationNameConst.signaRedFlash, SignalColorEnum.redLamp, 0);
|
||
|
}
|
||
|
this.addAnimation(redFlashA);
|
||
|
redFlashA.resume();
|
||
|
}
|
||
|
/** 设置状态绿闪 */
|
||
|
setStateGreenFlash() {
|
||
|
let greenFlashA = this.animation(anmiationNameConst.signalGreenFlash);
|
||
|
if (!greenFlashA) {
|
||
|
greenFlashA = this.lampMainBody.createFlashAnmiation(anmiationNameConst.signalGreenFlash, SignalColorEnum.greenLamp, 1);
|
||
|
}
|
||
|
this.addAnimation(greenFlashA);
|
||
|
greenFlashA.resume();
|
||
|
}
|
||
|
/** 设置状态黄闪 */
|
||
|
setStateYellowFlash() {
|
||
|
let yellowFlashA = this.animation(anmiationNameConst.signalYellowFlash);
|
||
|
if (!yellowFlashA) {
|
||
|
yellowFlashA = this.lampMainBody.createFlashAnmiation(anmiationNameConst.signalYellowFlash, SignalColorEnum.yellowLamp, 2);
|
||
|
}
|
||
|
this.addAnimation(yellowFlashA);
|
||
|
yellowFlashA.resume();
|
||
|
}
|
||
|
/** 设置状态蓝闪 */
|
||
|
setStateBlueFlash() {
|
||
|
let blueFlashA = this.animation(anmiationNameConst.signalBlueFlash);
|
||
|
if (!blueFlashA) {
|
||
|
blueFlashA = this.lampMainBody.createFlashAnmiation(anmiationNameConst.signalBlueFlash, SignalColorEnum.blueLamp, 0);
|
||
|
}
|
||
|
this.addAnimation(blueFlashA);
|
||
|
blueFlashA.resume();
|
||
|
}
|
||
|
/** 设置状态白闪 */
|
||
|
setStateWhiteFlash() {
|
||
|
let whiteFlashA = this.animation(anmiationNameConst.signalWhiteFlash);
|
||
|
if (!whiteFlashA) {
|
||
|
whiteFlashA = this.lampMainBody.createFlashAnmiation(anmiationNameConst.signalWhiteFlash, SignalColorEnum.whiteLamp, 0);
|
||
|
}
|
||
|
this.addAnimation(whiteFlashA);
|
||
|
whiteFlashA.resume();
|
||
|
}
|
||
|
}
|
||
|
/**
|
||
|
*
|
||
|
* @param polygon
|
||
|
* @param x 箭头顶点x坐标
|
||
|
* @param y 箭头顶点y坐标
|
||
|
* @param length 箭头长度
|
||
|
* @param radius 箭头三角半径
|
||
|
* @param lineWidth 箭头线宽
|
||
|
* @param mirror 是否镜像翻转 (基于箭头顶点)
|
||
|
*/
|
||
|
function drawArrow(polygon, x, y, length, radius, lineWidth, mirror) {
|
||
|
const trianglAcme = { x, y };
|
||
|
let triangleP1 = {
|
||
|
x: x - radius - Math.sin(Math.PI / 6),
|
||
|
y: y + Math.cos(Math.PI / 6) * radius,
|
||
|
};
|
||
|
let triangleP2 = {
|
||
|
x: x - radius - Math.sin(Math.PI / 6),
|
||
|
y: y - Math.cos(Math.PI / 6) * radius,
|
||
|
};
|
||
|
let lineP1 = {
|
||
|
x: x - radius - Math.sin(Math.PI / 6),
|
||
|
y: y + lineWidth / 2,
|
||
|
};
|
||
|
let lineP2 = {
|
||
|
x: x - length,
|
||
|
y: y + lineWidth / 2,
|
||
|
};
|
||
|
let lineP3 = {
|
||
|
x: x - length,
|
||
|
y: y - lineWidth / 2,
|
||
|
};
|
||
|
let lineP4 = {
|
||
|
x: x - radius - Math.sin(Math.PI / 6),
|
||
|
y: y - lineWidth / 2,
|
||
|
};
|
||
|
if (mirror) {
|
||
|
triangleP1 = calculateMirrorPoint(trianglAcme, triangleP1);
|
||
|
triangleP2 = calculateMirrorPoint(trianglAcme, triangleP2);
|
||
|
lineP1 = calculateMirrorPoint(trianglAcme, lineP1);
|
||
|
lineP2 = calculateMirrorPoint(trianglAcme, lineP2);
|
||
|
lineP3 = calculateMirrorPoint(trianglAcme, lineP3);
|
||
|
lineP4 = calculateMirrorPoint(trianglAcme, lineP4);
|
||
|
}
|
||
|
polygon.drawPolygon(trianglAcme.x, trianglAcme.y, triangleP1.x, triangleP1.y, lineP1.x, lineP1.y, lineP2.x, lineP2.y, lineP3.x, lineP3.y, lineP4.x, lineP4.y, triangleP2.x, triangleP2.y);
|
||
|
}
|
||
|
|
||
|
export { Model, Signal, SignalColorEnum, drawArrow, signalConsts };
|