79 lines
3.3 KiB
JavaScript
79 lines
3.3 KiB
JavaScript
|
import { Container } from '@pixi/display';
|
||
|
import { Graphics } from 'pixi.js';
|
||
|
import { signalConsts, SignalColorEnum } from '../bjRtss/Signal.js';
|
||
|
|
||
|
const lampConsts = {
|
||
|
lampLineWidth: 1,
|
||
|
lampBadColor: '0xFF0000',
|
||
|
badStart: 10,
|
||
|
badEnd: 15,
|
||
|
};
|
||
|
class Lamp extends Container {
|
||
|
circleLamp = new Graphics();
|
||
|
logicMode = new Graphics();
|
||
|
radiusX = 0;
|
||
|
radiusY = 0;
|
||
|
constructor(hasLogic) {
|
||
|
super();
|
||
|
this.addChild(this.circleLamp);
|
||
|
if (hasLogic) {
|
||
|
this.addChild(this.logicMode);
|
||
|
}
|
||
|
}
|
||
|
paint(radiusX, radiusY) {
|
||
|
this.radiusX = radiusX;
|
||
|
this.radiusY = radiusY;
|
||
|
this.createLamp();
|
||
|
}
|
||
|
createLampBad() {
|
||
|
this.circleLamp.lineStyle(lampConsts.lampLineWidth, lampConsts.lampBadColor);
|
||
|
this.circleLamp.moveTo(this.radiusX + lampConsts.badStart, this.radiusY);
|
||
|
this.circleLamp.lineTo(this.radiusX + lampConsts.badEnd, this.radiusY);
|
||
|
this.circleLamp.moveTo(this.radiusX - lampConsts.badStart, this.radiusY);
|
||
|
this.circleLamp.lineTo(this.radiusX - lampConsts.badEnd, this.radiusY);
|
||
|
this.circleLamp.moveTo(this.radiusX, this.radiusY + lampConsts.badStart);
|
||
|
this.circleLamp.lineTo(this.radiusX, this.radiusY + lampConsts.badEnd);
|
||
|
this.circleLamp.moveTo(this.radiusX, this.radiusY - lampConsts.badStart);
|
||
|
this.circleLamp.lineTo(this.radiusX, this.radiusY - lampConsts.badEnd);
|
||
|
const xieStart = Math.sin(Math.PI / 4) * lampConsts.badStart;
|
||
|
const xieEnd = Math.sin(Math.PI / 4) * lampConsts.badEnd;
|
||
|
this.circleLamp.moveTo(this.radiusX + xieStart, this.radiusY + xieStart);
|
||
|
this.circleLamp.lineTo(this.radiusX + xieEnd, this.radiusY + xieEnd);
|
||
|
this.circleLamp.moveTo(this.radiusX + xieStart, this.radiusY - xieStart);
|
||
|
this.circleLamp.lineTo(this.radiusX + xieEnd, this.radiusY - xieEnd);
|
||
|
this.circleLamp.moveTo(this.radiusX - xieStart, this.radiusY - xieStart);
|
||
|
this.circleLamp.lineTo(this.radiusX - xieEnd, this.radiusY - xieEnd);
|
||
|
this.circleLamp.moveTo(this.radiusX - xieStart, this.radiusY + xieStart);
|
||
|
this.circleLamp.lineTo(this.radiusX - xieEnd, this.radiusY + xieEnd);
|
||
|
}
|
||
|
createLamp(color) {
|
||
|
this.circleLamp.clear();
|
||
|
this.circleLamp.lineStyle(signalConsts.lampLineWidth, SignalColorEnum.lampLineColor);
|
||
|
if (!color) {
|
||
|
this.circleLamp.beginFill('0XFFFFFF', 0);
|
||
|
}
|
||
|
else {
|
||
|
this.circleLamp.beginFill(color, 1);
|
||
|
}
|
||
|
this.circleLamp.drawCircle(this.radiusX, this.radiusY, signalConsts.lampRadius);
|
||
|
this.circleLamp.endFill();
|
||
|
}
|
||
|
createLogicMode() {
|
||
|
this.logicMode
|
||
|
.clear()
|
||
|
.lineStyle(signalConsts.logicModeLineWidth, SignalColorEnum.logicModeColor)
|
||
|
.moveTo(this.radiusX - signalConsts.logicModeDistance, this.radiusY + signalConsts.logicModeDistance)
|
||
|
.lineTo(this.radiusX + signalConsts.logicModeDistance, this.radiusY - signalConsts.logicModeDistance)
|
||
|
.moveTo(this.radiusX - signalConsts.logicModeDistance, this.radiusY - signalConsts.logicModeDistance)
|
||
|
.lineTo(this.radiusX + signalConsts.logicModeDistance, this.radiusY + signalConsts.logicModeDistance);
|
||
|
}
|
||
|
logicModeClear() {
|
||
|
this.logicMode.clear();
|
||
|
}
|
||
|
lampClear() {
|
||
|
this.circleLamp.clear();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export { Lamp };
|