rt-graphic-component/components/Signal/bjRtss/LampMainBody.js
2024-01-02 14:36:14 +08:00

101 lines
3.2 KiB
JavaScript

import { Container, Graphics, Point } from 'pixi.js';
import { calculateMirrorPoint } from 'jl-graphic';
import { Lamp } from '../common/Lamp.js';
import { Model, signalConsts, SignalColorEnum } from './Signal.js';
class LampMainBody extends Container {
static Type = 'LampMainBody';
lampNum = 1;
lampPost = new Graphics();
lamps = [];
mirror = false;
paint(mt, mirror) {
this.mirror = mirror;
if (mt === Model.HL ||
mt === Model.AB) {
this.lampNum = 2;
}
else {
this.lampNum = 3;
}
this.removeChildren(0);
this.lampPost = new Graphics();
let lpp = new Point(signalConsts.levelLampPostLength, 0);
if (mirror) {
lpp = calculateMirrorPoint(new Point(0, 0), lpp);
}
this.lampPost
.lineStyle(signalConsts.postLineWidth, SignalColorEnum.lampPostColor)
.moveTo(0, -signalConsts.verticalLampPostLength / 2)
.lineTo(0, signalConsts.verticalLampPostLength / 2)
.moveTo(0, 0)
.lineTo(lpp.x, lpp.y);
this.addChild(this.lampPost);
this.lamps = [];
for (let i = 0; i < this.lampNum; i++) {
const lamp = new Lamp(false);
this.addChild(lamp);
const radiusX = (1 + i * 2) * signalConsts.lampRadius +
signalConsts.levelLampPostLength;
let lrp = new Point(radiusX, 0);
if (mirror) {
lrp = calculateMirrorPoint(new Point(0, 0), lrp);
}
lamp.paint(lrp.x, lrp.y);
this.lamps.push(lamp);
}
}
setStateBlueShow() {
this.lamps.forEach(lamp => {
lamp.createLamp(SignalColorEnum.blueLamp);
});
}
setStateLogic() {
this.lamps.forEach(lamp => {
lamp.createLogicMode();
});
}
setStateH() {
this.lamps[0].createLamp(SignalColorEnum.redLamp);
this.lamps.forEach((lamp, index) => {
if (index !== 0) {
lamp.createLamp(SignalColorEnum.closeLamp);
}
});
}
setStateL() {
this.lamps[1].createLamp(SignalColorEnum.greenLamp);
this.lamps.forEach((lamp, index) => {
if (index !== 1) {
lamp.createLamp(SignalColorEnum.closeLamp);
}
});
}
setStateU() {
this.lamps[2].createLamp(SignalColorEnum.yellowLamp);
this.lamps.forEach((lamp, index) => {
if (index !== 2) {
lamp.createLamp(SignalColorEnum.closeLamp);
}
});
}
setStateHu() {
this.lamps[0].createLamp(SignalColorEnum.redLamp);
this.lamps[1].createLamp(SignalColorEnum.closeLamp);
this.lamps[2].createLamp(SignalColorEnum.yellowLamp);
}
setStateA() {
this.lamps[0].createLamp(SignalColorEnum.blueLamp);
this.lamps[1].createLamp(SignalColorEnum.closeLamp);
}
setStateB() {
this.lamps[0].createLamp(SignalColorEnum.whiteLamp);
this.lamps[1].createLamp(SignalColorEnum.closeLamp);
}
setStateOff() {
this.lamps.forEach((lamp) => lamp.createLamp(SignalColorEnum.closeLamp));
}
}
export { LampMainBody };