import { Container, Graphics, Point } from 'pixi.js'; import { calculateMirrorPoint, GraphicAnimation } 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; deltaTime = 0; constructor() { super(); } 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(true); 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); }); } setStateLampBad() { this.lamps.forEach(lamp => { lamp.createLampBad(); }); } 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)); } createFlashAnmiation(name, color, lampIndex) { const bgColor = '0X000000'; const flashAnmiation = GraphicAnimation.init({ name: name, run: (dt) => { this.deltaTime += dt; if (this.deltaTime > 60) { this.deltaTime = 0; this.lamps[lampIndex].createLamp(color); } else if (this.deltaTime > 30) { this.lamps.forEach((lamp) => { lamp.createLamp(bgColor); }); } }, }); return flashAnmiation; } } export { LampMainBody };