import { calculateMirrorPoint, VectorText, getRectangleCenter, JlGraphic, distance2 } from 'jl-graphic'; import { Container, Graphics, Color, Point, Rectangle } from 'pixi.js'; import { JlSection } from '../../Section/common/Section.js'; import { JlStation } from '../../Station/common/JlStation.js'; //子元素--矩形 class RectGraphic extends Container { platformConsts; rect; stateFillColor; constructor(platformConsts) { super(); this.platformConsts = platformConsts; this.rect = new Graphics(); this.addChild(this.rect); } draw() { const fillColor = this.stateFillColor || this.platformConsts.noTrainStop; this.rect .clear() .lineStyle(this.platformConsts.lineWidth, new Color(fillColor)) .beginFill(fillColor, 1) .drawRect(0, 0, this.platformConsts.width, this.platformConsts.height) .endFill; this.rect.pivot = getRectangleCenter(new Rectangle(0, 0, this.platformConsts.width, this.platformConsts.height)); } clear() { this.rect.clear(); } } //子元素--门 class DoorGraphic extends Container { platformConsts; doorGraphic; doorCloseGraphic; stateFillColor; constructor(platformConsts) { super(); this.platformConsts = platformConsts; this.doorGraphic = new Graphics(); this.doorCloseGraphic = new Graphics(); this.addChild(this.doorGraphic); this.addChild(this.doorCloseGraphic); } draw() { const doorConsts = this.platformConsts.doorGraphic; const lineColor = this.stateFillColor || doorConsts.doorGreen; this.doorGraphic .clear() .lineStyle(this.platformConsts.lineWidth, new Color(lineColor)) .moveTo(-this.platformConsts.width / 2 - this.platformConsts.lineWidth / 2, 0) .lineTo(-doorConsts.doorOpenSpacing, 0) .moveTo(doorConsts.doorOpenSpacing, 0) .lineTo(this.platformConsts.width / 2 + this.platformConsts.lineWidth / 2, 0); //屏蔽门闭合 this.doorCloseGraphic .clear() .lineStyle(this.platformConsts.lineWidth, new Color(lineColor)) .moveTo(-doorConsts.doorOpenSpacing, 0) .lineTo(doorConsts.doorOpenSpacing, 0); this.position.set(0, -this.platformConsts.height / 2 - doorConsts.doorPlatformSpacing); } changePosition() { this.position.copyFrom(calculateMirrorPoint(new Point(0, 0), this.position)); } clear() { this.doorGraphic.clear(); this.doorCloseGraphic.clear(); } } //子元素--字符 class CodeGraphic extends Container { platformConsts; character = new VectorText(''); //扣车H runLevel = new VectorText(''); //运行等级 runTime = new VectorText(''); //运行时间 stopTime = new VectorText(''); //停站时间 circle = new Graphics(); constructor(platformConsts) { super(); this.platformConsts = platformConsts; const codeConsts = platformConsts.codeGraphic; const childrenGraphics = [ this.character, this.runLevel, this.runTime, this.stopTime, ]; childrenGraphics.forEach((child) => { child.setVectorFontSize(codeConsts.besideFontSize); child.anchor.set(0.5); child.style.fill = codeConsts.whiteNumbers; this.addChild(child); }); this.addChild(this.circle); this.drawNoChange(); } draw() { this.character.visible = false; this.circle.visible = false; this.runLevel.visible = false; this.stopTime.visible = false; this.runTime.visible = false; this.position.set(0, 0); } drawNoChange() { const codeConsts = this.platformConsts.codeGraphic; this.circle .clear() .lineStyle(0.5, codeConsts.whiteCircle) .drawCircle(0, 0, codeConsts.circleRadius); this.character.text = 'H'; this.setPosition(); } setPosition() { //扣车 const platformConsts = this.platformConsts; const codeConsts = this.platformConsts.codeGraphic; this.character.position.set(-platformConsts.width / 2 - platformConsts.lineWidth / 2 - (codeConsts.besideSpacing * 2) / 3, (platformConsts.height * 3) / 4); this.circle.position.set(-platformConsts.width / 2 - platformConsts.lineWidth / 2 - (codeConsts.besideSpacing * 4) / 3, (platformConsts.height * 3) / 5); //区间运行等级状态 this.runLevel.position.set(platformConsts.width / 2 + platformConsts.lineWidth / 2 + 3 * codeConsts.besideSpacing, -codeConsts.besideSpacing); //区间运行时间 this.runTime.position.set(platformConsts.width / 2 + platformConsts.lineWidth / 2 + codeConsts.besideSpacing, -codeConsts.besideSpacing); //停站时间 this.stopTime.position.set(platformConsts.width / 2 + platformConsts.lineWidth / 2 + codeConsts.besideSpacing, codeConsts.besideSpacing); } changePosition() { const codeConsts = this.platformConsts.codeGraphic; const psChange = [ this.character, this.runLevel, this.stopTime, this.runTime, ]; psChange.forEach((g) => { if (g) { g.position.copyFrom(calculateMirrorPoint(new Point(0, 0), g.position)); } }); this.circle.position.set(this.platformConsts.width / 2 + this.platformConsts.lineWidth / 2 + (codeConsts.besideSpacing * 4) / 3, (-this.platformConsts.height * 10) / 11); } clear() { this.character.destroy(); } } //子元素--站台旁菱形图标 class LozengeGraphic extends Container { platformConsts; lozenge; constructor(platformConsts) { super(); this.platformConsts = platformConsts; this.lozenge = new Graphics(); this.addChild(this.lozenge); this.drawNoChange(); } drawNoChange() { const LozengeConsts = this.platformConsts .lozengeGraphic; this.lozenge .clear() .lineStyle(1, new Color(LozengeConsts.lozengeRed)) .beginFill(LozengeConsts.lozengeRed, 1) .drawRect(0, 0, this.platformConsts.height / 4, this.platformConsts.height / 4) .endFill(); this.lozenge.pivot = getRectangleCenter(new Rectangle(0, 0, this.platformConsts.height / 4, this.platformConsts.height / 4)); this.lozenge.rotation = Math.PI / 4; this.lozenge.visible = false; this.position.set(0, -this.platformConsts.height / 2 - LozengeConsts.doorPlatformSpacing - this.platformConsts.height / 3); } changePosition() { this.position.copyFrom(calculateMirrorPoint(new Point(0, 0), this.position)); } clear() { this.lozenge.clear(); } } class DoorCodeLozenge extends Container { platformConsts; doorGraphic; lozengeGraphic; codeGraphic; constructor(platformConsts) { super(); this.platformConsts = platformConsts; this.doorGraphic = new DoorGraphic(this.platformConsts); this.addChild(this.doorGraphic); this.lozengeGraphic = new LozengeGraphic(this.platformConsts); this.addChild(this.lozengeGraphic); this.codeGraphic = new CodeGraphic(this.platformConsts); this.addChild(this.codeGraphic); } draw(hasDoor, direction) { this.doorGraphic.clear(); if (hasDoor) { this.doorGraphic.draw(); } this.codeGraphic.draw(); if (direction == 'down') { this.doorGraphic.changePosition(); this.codeGraphic.changePosition(); this.lozengeGraphic.changePosition(); } } } class JlPlatform extends JlGraphic { static Type = 'Platform'; rectGraphic; constructor(platformConsts) { super(JlPlatform.Type); this.rectGraphic = new RectGraphic(platformConsts); this.addChild(this.rectGraphic); } get datas() { return this.getDatas(); } get code() { return this.datas.code; } draw() { this.rectGraphic.draw(); } buildCommonRelation() { const stationas = this.queryStore.queryByType(JlStation.Type); for (let i = 0; i < stationas.length; i++) { const sP = stationas[i].localBoundsToCanvasPoints(); if (this.x > sP[0].x && this.x < sP[1].x) { this.relationManage.addRelation(this, stationas[i]); break; } } const sections = this.queryStore.queryByType(JlSection.Type); const minDistanceRefSections = []; sections.forEach((section) => { const sP = section.localBoundsToCanvasPoints(); if (this.x > sP[0].x && this.x < sP[1].x) { minDistanceRefSections.push(section); } }); if (minDistanceRefSections) { const refSection = minDistanceRefSections.reduce((prev, cur) => { return distance2(prev.localToCanvasPoint(getRectangleCenter(prev.getLocalBounds())), this.position) > distance2(cur.localToCanvasPoint(getRectangleCenter(cur.getLocalBounds())), this.position) ? cur : prev; }); this.relationManage.deleteRelationOfGraphicAndOtherType(this, JlSection.Type); this.relationManage.addRelation(this, refSection); } } saveCommonRelations() { const refStation = this.relationManage .getRelationsOfGraphicAndOtherType(this, JlStation.Type) .map((relation) => relation.getOtherGraphic(this).datas.id); if (refStation.length) { this.datas.refStation = refStation[0]; } const refSection = this.relationManage .getRelationsOfGraphicAndOtherType(this, JlSection.Type) .map((relation) => relation.getOtherGraphic(this).datas.id); if (refSection.length) { this.datas.refSection = refSection[0]; } } loadCommonRelations() { if (this.datas.refStation) { this.relationManage.addRelation(this, this.queryStore.queryById(this.datas.refStation)); } if (this.datas.refSection) { this.relationManage.addRelation(this, this.queryStore.queryById(this.datas.refSection)); } } } export { CodeGraphic, DoorCodeLozenge, DoorGraphic, JlPlatform, LozengeGraphic };