From b59d9586043a4c1c7f1eec5cf9cbd948996323c2 Mon Sep 17 00:00:00 2001 From: Yuan Date: Thu, 4 Jan 2024 15:14:25 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=AE=E5=BD=95=E7=BB=93=E6=9E=84=E5=8F=8A?= =?UTF-8?q?=E5=BC=95=E7=94=A8=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/AxleCounting/AxleCounting.js | 94 ------- components/Section/bjrtss/Section.js | 15 -- components/Section/common/Section.js | 230 ------------------ components/Section/common/SectionGraphic.js | 51 ---- components/common/common.d.ts | 6 +- components/common/common.js | 6 +- .../packages/AxleCounting/AxleCounting.d.ts | 2 +- .../packages/AxleCounting/AxleCounting.js | 87 ++++++- .../packages/Section/common/Section.d.ts | 2 +- components/packages/Section/common/Section.js | 4 +- .../packages/Station/StationConfig.d.ts | 14 +- package.json | 1 + rollup.config.cjs | 4 + src/common/common.ts | 6 +- src/packages/AxleCounting/AxleCounting.ts | 6 +- src/packages/Section/common/Section.ts | 6 +- src/packages/Station/StationConfig.ts | 2 +- tsconfig.json | 5 +- yarn.lock | 12 + 19 files changed, 121 insertions(+), 432 deletions(-) delete mode 100644 components/AxleCounting/AxleCounting.js delete mode 100644 components/Section/bjrtss/Section.js delete mode 100644 components/Section/common/Section.js delete mode 100644 components/Section/common/SectionGraphic.js diff --git a/components/AxleCounting/AxleCounting.js b/components/AxleCounting/AxleCounting.js deleted file mode 100644 index cd6bd74..0000000 --- a/components/AxleCounting/AxleCounting.js +++ /dev/null @@ -1,94 +0,0 @@ -import { JlGraphic, GraphicRelationParam, JlGraphicTemplate } from 'jl-graphic'; -import { protoPort2Data } from '../common/common.js'; -import { Container, Graphics, Color } from 'pixi.js'; - -var TypeDetectionPoint; -(function (TypeDetectionPoint) { - TypeDetectionPoint[TypeDetectionPoint["AxleCounting"] = 0] = "AxleCounting"; - TypeDetectionPoint[TypeDetectionPoint["SectionBoundary"] = 1] = "SectionBoundary"; -})(TypeDetectionPoint || (TypeDetectionPoint = {})); -const AxleCountingConsts = { - radius: 6, - borderWidth: 1, - circleColorBlue: '0x08F80D', - circleColorRed: '0xff0000', -}; -class TwoCircleGraphic extends Container { - circleA = new Graphics(); - circleB = new Graphics(); - line = new Graphics(); - constructor() { - super(); - this.addChild(this.circleA); - this.addChild(this.circleB); - this.addChild(this.line); - } - draw(data) { - this.drawCircle(this.circleA, data); - this.drawCircle(this.circleB, data); - this.circleA.position.set(-12, 0); - this.circleB.position.set(12, 0); - const color = data.type == 1 - ? AxleCountingConsts.circleColorRed - : AxleCountingConsts.circleColorBlue; - this.line - .clear() - .lineStyle(1, new Color(color)) - .moveTo(-24, 0) - .lineTo(24, 0); - } - drawCircle(circle, data) { - const color = data.type == 1 - ? AxleCountingConsts.circleColorRed - : AxleCountingConsts.circleColorBlue; - circle - .clear() - .lineStyle(AxleCountingConsts.borderWidth, new Color(color)) - .beginFill(color, 1) - .drawCircle(0, 0, AxleCountingConsts.radius).endFill; - } - clear() { - this.circleA.clear(); - this.circleB.clear(); - } -} -class AxleCounting extends JlGraphic { - static Type = 'AxleCounting'; - twoCircle = new TwoCircleGraphic(); - direction; - constructor(direction) { - super(AxleCounting.Type); - this.addChild(this.twoCircle); - this.direction = direction; - } - get datas() { - return this.getDatas(); - } - doRepaint() { - this.twoCircle.draw(this.datas); - } - buildRelation() { - this.loadRelations(); - } - loadRelations() { - if (this.datas.axleCountingRef.length) { - this.datas.axleCountingRef.forEach((device) => { - this.relationManage.addRelation(new GraphicRelationParam(this, 'A'), new GraphicRelationParam(this.queryStore.queryById(device.id), protoPort2Data(device.devicePort))); - }); - } - } -} -class AxleCountingTemplate extends JlGraphicTemplate { - constructor(dataTemplate) { - super(AxleCounting.Type, { - dataTemplate, - }); - } - new() { - const axleCounting = new AxleCounting(1); - axleCounting.loadData(this.datas); - return axleCounting; - } -} - -export { AxleCounting, AxleCountingConsts, AxleCountingTemplate }; diff --git a/components/Section/bjrtss/Section.js b/components/Section/bjrtss/Section.js deleted file mode 100644 index 110d4e4..0000000 --- a/components/Section/bjrtss/Section.js +++ /dev/null @@ -1,15 +0,0 @@ -import { Section as Section$1 } from '../common/Section.js'; - -const displayConfig = { - lineColor: '#5578b6', - occupiedColor: '#f00', - lineWidth: 5 -}; -class Section extends Section$1 { - constructor() { - super(); - this.setDisplayConfig(displayConfig); - } -} - -export { Section }; diff --git a/components/Section/common/Section.js b/components/Section/common/Section.js deleted file mode 100644 index 52da100..0000000 --- a/components/Section/common/Section.js +++ /dev/null @@ -1,230 +0,0 @@ -import { JlGraphic, VectorText, convertToBezierParams, Vector2, splitLineEvenly, distance2, GraphicRelationParam, JlGraphicTemplate } from 'jl-graphic'; -import { SectionGraphic } from './SectionGraphic.js'; -import { DevicePort, IRelatedRef } from '../../common/common.js'; -import { Turnout } from '../../Turnout/Turnout.js'; -import { AxleCounting } from '../../AxleCounting/AxleCounting.js'; - -const tolerance = 0.01; -var SectionType; -(function (SectionType) { - SectionType[SectionType["Physical"] = 0] = "Physical"; - SectionType[SectionType["Logic"] = 1] = "Logic"; - SectionType[SectionType["TurnoutPhysical"] = 2] = "TurnoutPhysical"; - SectionType[SectionType["Track"] = 4] = "Track"; - SectionType[SectionType["TrackLogic"] = 5] = "TrackLogic"; -})(SectionType || (SectionType = {})); -const defaultDisplayConfig = { - lineColor: '#5578b6', - occupiedColor: '#f00', - lineWidth: 5, -}; -let Section$1 = class Section extends JlGraphic { - static Type = 'Section'; - lineGraphic; - labelGraphic; - displayConfig = defaultDisplayConfig; - constructor() { - super(Section.Type); - this.lineGraphic = new SectionGraphic(); - this.labelGraphic = new VectorText(''); - this.labelGraphic.setVectorFontSize(14); - this.labelGraphic.anchor.set(0.5); - this.labelGraphic.style.fill = '#0f0'; - this.labelGraphic.transformSave = true; - this.labelGraphic.name = 'label'; - this.transformSave = true; - this.addChild(this.lineGraphic); - this.addChild(this.labelGraphic); - } - setDisplayConfig(config) { - this.displayConfig = config; - } - getVerticesList() { - if (this.datas.isCurve) { - return [ - this.datas.points[0], - ...convertToBezierParams(this.datas.points).map((param) => param.p2), - ]; - } - else { - return this.datas.points; - } - } - getStartPoint() { - return this.datas.points[0]; - } - getEndPoint() { - return this.datas.points[this.datas.points.length - 1]; - } - doRepaint() { - this.lineGraphic.clear(); - if (this.datas.sectionType === SectionType.TurnoutPhysical) { - return; - } - this.lineGraphic.isCurve = this.datas.isCurve; - if (this.lineGraphic.isCurve) { - this.lineGraphic.segmentsCount = this.datas.segmentsCount; - } - this.lineGraphic.points = this.datas.points; - this.lineGraphic.lineStyle(this.displayConfig.lineWidth, this.states.occupied - ? this.displayConfig.occupiedColor - : this.displayConfig.lineColor); - this.labelGraphic.text = this.datas.code; - const labelPosition = this.datas.childTransforms?.find((t) => t.name === this.labelGraphic.name)?.transform.position; - if (labelPosition) { - this.labelGraphic.position.set(labelPosition.x, labelPosition.y); - } - else { - this.labelGraphic.position.set(this.datas.points[0].x, this.datas.points[0].y + 20); - } - } - get datas() { - return this.getDatas(); - } - get states() { - return this.getStates(); - } - get linePoints() { - return this.datas.points; - } - set linePoints(points) { - const old = this.datas.clone(); - old.points = points; - this.updateData(old); - } - getConnectElement(port) { - const relation = this.relationManage - .getRelationsOfGraphic(this) - .find((relation) => relation.getRelationParam(this).getParam() === port && - (relation.getOtherGraphic(this) instanceof Section || - relation.getOtherGraphic(this) instanceof Turnout)); - if (!relation) { - return; - } - return { - g: relation?.getOtherGraphic(this), - port: relation?.getOtherRelationParam(this).getParam(), - }; - } - /** 获取拆分逻辑区段数据 */ - getSplitPoints(count) { - if (this.datas.points.length !== 2) { - let totalLen = 0; - const lengths = []; - for (let i = 1; i < this.datas.points.length; i++) { - const { x: x1, y: y1 } = this.datas.points[i - 1], { x: x2, y: y2 } = this.datas.points[i]; - const len = new Vector2([x2 - x1, y2 - y1]).length(); - totalLen += len; - lengths.push(len); - } - const counts = lengths.map((length) => Math.round((count * length) / totalLen)); - if (counts.reduce((p, c) => p + c, 0) !== count) { - const intersection = counts.reduce((p, c) => p + c, 0) - count; - let maxCountIndex = 0, maxCount = 0; - counts.forEach((c, i) => { - if (c > maxCount) { - maxCount = c; - maxCountIndex = i; - } - }); - counts[maxCountIndex] + intersection; - } - return counts - .map((count, i) => { - return splitLineEvenly(this.localToCanvasPoint(this.datas.points[i]), this.localToCanvasPoint(this.datas.points[i + 1]), count); - }) - .flat(); - } - else { - return splitLineEvenly(this.localToCanvasPoint(this.datas.points[0]), this.localToCanvasPoint(this.datas.points[this.datas.points.length - 1]), count); - } - } - buildRelation() { - this.relationManage.deleteRelationOfGraphicAndOtherType(this, Section.Type); - if (this.datas.sectionType === SectionType.Physical) { - this.queryStore.queryByType(Section.Type).forEach((section) => { - if (section.id === this.id) - return; - let param = []; - if (distance2(this.localToCanvasPoint(this.getStartPoint()), section.localToCanvasPoint(section.getStartPoint())) <= tolerance) { - param = [DevicePort.A, DevicePort.A]; - } - if (distance2(this.localToCanvasPoint(this.getEndPoint()), section.localToCanvasPoint(section.getStartPoint())) <= tolerance) { - param = [DevicePort.B, DevicePort.A]; - } - if (distance2(this.localToCanvasPoint(this.getStartPoint()), section.localToCanvasPoint(section.getEndPoint())) <= tolerance) { - param = [DevicePort.A, DevicePort.B]; - } - if (distance2(this.localToCanvasPoint(this.getEndPoint()), section.localToCanvasPoint(section.getEndPoint())) <= tolerance) { - param = [DevicePort.B, DevicePort.B]; - } - if (param.length) { - this.relationManage.addRelation(new GraphicRelationParam(this, param[0]), new GraphicRelationParam(section, param[1])); - } - }); - } - } - saveRelations() { - const paRelation = this.relationManage - .getRelationsOfGraphic(this) - .find((relation) => relation.getRelationParam(this).param === DevicePort.A && - (relation.getOtherGraphic(this) instanceof Section || - relation.getOtherGraphic(this) instanceof Turnout)); - const paDevice = paRelation?.getOtherGraphic(this); - if (paDevice) { - this.datas.paRef = IRelatedRef.create(paDevice.type, paDevice.id, paRelation.getOtherRelationParam(this).getParam()); - } - else { - this.datas.paRef = undefined; - } - const pbRelation = this.relationManage - .getRelationsOfGraphic(this) - .find((relation) => relation.getRelationParam(this).param === DevicePort.B && - (relation.getOtherGraphic(this) instanceof Section || - relation.getOtherGraphic(this) instanceof Turnout)); - const pbDevice = pbRelation?.getOtherGraphic(this); - if (pbDevice) { - this.datas.pbRef = IRelatedRef.create(pbDevice.type, pbDevice.id, pbRelation?.getOtherRelationParam(this).param); - } - else { - this.datas.pbRef = undefined; - } - this.datas.axleCountings = this.relationManage - .getRelationsOfGraphicAndOtherType(this, AxleCounting.Type) - .map((relation) => relation.getOtherGraphic(this).datas.id); - } - loadRelations() { - if (this.datas?.paRef?.id) { - this.relationManage.addRelation(new GraphicRelationParam(this, DevicePort.A), new GraphicRelationParam(this.queryStore.queryById(this.datas.paRef.id), DevicePort[this.datas.paRef.devicePort])); - } - if (this.datas?.pbRef?.id) { - this.relationManage.addRelation(new GraphicRelationParam(this, DevicePort.B), new GraphicRelationParam(this.queryStore.queryById(this.datas.pbRef.id), DevicePort[this.datas.pbRef.devicePort])); - } - if (this.datas.trackSectionId) { - this.relationManage.addRelation(this, this.queryStore.queryById(this.datas.trackSectionId)); - } - if (this.datas.sectionType === SectionType.TurnoutPhysical) { - if (this.datas.axleCountings) { - this.datas.axleCountings.forEach((id) => { - this.relationManage.addRelation(this, this.queryStore.queryById(id)); - }); - } - } - } -}; -class SectionTemplate extends JlGraphicTemplate { - constructor(dataTemplate, stateTemplate) { - super(Section$1.Type, { - dataTemplate, - stateTemplate, - }); - } - new() { - const section = new Section$1(); - section.loadData(this.datas); - section.loadState(this.states); - return section; - } -} - -export { Section$1 as Section, SectionTemplate, SectionType }; diff --git a/components/Section/common/SectionGraphic.js b/components/Section/common/SectionGraphic.js deleted file mode 100644 index 730aff3..0000000 --- a/components/Section/common/SectionGraphic.js +++ /dev/null @@ -1,51 +0,0 @@ -import { Graphics } from 'pixi.js'; -import { assertBezierPoints, convertToBezierParams } from 'jl-graphic'; - -class SectionGraphic extends Graphics { - static Type = 'SectionGraphic'; - _points = []; - get points() { - return this._points; - } - set points(value) { - if (!this.isCurve) { - if (value.length < 2) { - throw Error('Polyline must have at least 2 points'); - } - } - else { - assertBezierPoints(value); - } - this._points = value; - } - _segmentsCount = 10; - get segmentsCount() { - return this._segmentsCount; - } - set segmentsCount(value) { - if (value < 1) { - throw Error('segmentsCount must be at least 1'); - } - this._segmentsCount = value; - } - isCurve = false; - constructor() { - super(); - } - paint() { - if (this.isCurve) { - const bps = convertToBezierParams(this.points); - bps.forEach((bp) => { - this.drawBezierCurve(bp.p1, bp.p2, bp.cp1, bp.cp2, this.segmentsCount); - }); - } - else { - this.moveTo(this.points[0].x, this.points[0].y); - for (let i = 1; i < this.points.length; i++) { - this.lineTo(this.points[i].x, this.points[i].y); - } - } - } -} - -export { SectionGraphic }; diff --git a/components/common/common.d.ts b/components/common/common.d.ts index fcf7ed8..290b9c8 100644 --- a/components/common/common.d.ts +++ b/components/common/common.d.ts @@ -1,7 +1,7 @@ export declare enum DevicePort { - A = 0, - B = 1, - C = 2 + A = "A", + B = "B", + C = "C" } export declare enum DeviceType { Section = 0, diff --git a/components/common/common.js b/components/common/common.js index 8c980bd..efc5767 100644 --- a/components/common/common.js +++ b/components/common/common.js @@ -1,8 +1,8 @@ var DevicePort; (function (DevicePort) { - DevicePort[DevicePort["A"] = 0] = "A"; - DevicePort[DevicePort["B"] = 1] = "B"; - DevicePort[DevicePort["C"] = 2] = "C"; + DevicePort["A"] = "A"; + DevicePort["B"] = "B"; + DevicePort["C"] = "C"; })(DevicePort || (DevicePort = {})); var DeviceType; (function (DeviceType) { diff --git a/components/packages/AxleCounting/AxleCounting.d.ts b/components/packages/AxleCounting/AxleCounting.d.ts index 325dcc9..37495e7 100644 --- a/components/packages/AxleCounting/AxleCounting.d.ts +++ b/components/packages/AxleCounting/AxleCounting.d.ts @@ -1,5 +1,5 @@ import { GraphicData, JlGraphic, JlGraphicTemplate } from 'jl-graphic'; -import { IRelatedRef, KilometerSystem } from 'src/common/common'; +import { IRelatedRef, KilometerSystem } from 'common/common'; import { Container, Graphics } from 'pixi.js'; declare enum TypeDetectionPoint { AxleCounting = 0, diff --git a/components/packages/AxleCounting/AxleCounting.js b/components/packages/AxleCounting/AxleCounting.js index 4f410f2..ebb0806 100644 --- a/components/packages/AxleCounting/AxleCounting.js +++ b/components/packages/AxleCounting/AxleCounting.js @@ -1,19 +1,94 @@ -import { JlGraphic } from 'jl-graphic'; +import { JlGraphic, GraphicRelationParam, JlGraphicTemplate } from 'jl-graphic'; +import { protoPort2Data } from '../../common/common.js'; +import { Container, Graphics, Color } from 'pixi.js'; var TypeDetectionPoint; (function (TypeDetectionPoint) { TypeDetectionPoint[TypeDetectionPoint["AxleCounting"] = 0] = "AxleCounting"; TypeDetectionPoint[TypeDetectionPoint["SectionBoundary"] = 1] = "SectionBoundary"; })(TypeDetectionPoint || (TypeDetectionPoint = {})); -class AxleCounting extends JlGraphic { - static Type = 'axleCounting'; +const AxleCountingConsts = { + radius: 6, + borderWidth: 1, + circleColorBlue: '0x08F80D', + circleColorRed: '0xff0000', +}; +class TwoCircleGraphic extends Container { + circleA = new Graphics(); + circleB = new Graphics(); + line = new Graphics(); constructor() { - super(AxleCounting.Type); + super(); + this.addChild(this.circleA); + this.addChild(this.circleB); + this.addChild(this.line); + } + draw(data) { + this.drawCircle(this.circleA, data); + this.drawCircle(this.circleB, data); + this.circleA.position.set(-12, 0); + this.circleB.position.set(12, 0); + const color = data.type == 1 + ? AxleCountingConsts.circleColorRed + : AxleCountingConsts.circleColorBlue; + this.line + .clear() + .lineStyle(1, new Color(color)) + .moveTo(-24, 0) + .lineTo(24, 0); + } + drawCircle(circle, data) { + const color = data.type == 1 + ? AxleCountingConsts.circleColorRed + : AxleCountingConsts.circleColorBlue; + circle + .clear() + .lineStyle(AxleCountingConsts.borderWidth, new Color(color)) + .beginFill(color, 1) + .drawCircle(0, 0, AxleCountingConsts.radius).endFill; + } + clear() { + this.circleA.clear(); + this.circleB.clear(); + } +} +class AxleCounting extends JlGraphic { + static Type = 'AxleCounting'; + twoCircle = new TwoCircleGraphic(); + direction; + constructor(direction) { + super(AxleCounting.Type); + this.addChild(this.twoCircle); + this.direction = direction; } - doRepaint() { } get datas() { return this.getDatas(); } + doRepaint() { + this.twoCircle.draw(this.datas); + } + buildRelation() { + this.loadRelations(); + } + loadRelations() { + if (this.datas.axleCountingRef.length) { + this.datas.axleCountingRef.forEach((device) => { + this.relationManage.addRelation(new GraphicRelationParam(this, 'A'), new GraphicRelationParam(this.queryStore.queryById(device.id), protoPort2Data(device.devicePort))); + }); + } + } +} +class AxleCountingTemplate extends JlGraphicTemplate { + constructor(dataTemplate) { + super(AxleCounting.Type, { + dataTemplate, + }); + } + new() { + const axleCounting = new AxleCounting(1); + axleCounting.loadData(this.datas); + return axleCounting; + } } -export { AxleCounting }; +export { AxleCounting, AxleCountingConsts, AxleCountingTemplate }; diff --git a/components/packages/Section/common/Section.d.ts b/components/packages/Section/common/Section.d.ts index fc338df..26ab829 100644 --- a/components/packages/Section/common/Section.d.ts +++ b/components/packages/Section/common/Section.d.ts @@ -1,7 +1,7 @@ import { GraphicData, GraphicState, JlGraphic, JlGraphicTemplate, VectorText } from 'jl-graphic'; import { IPointData } from 'pixi.js'; import { SectionGraphic } from './SectionGraphic'; -import { DevicePort, IRelatedRef } from 'src/common/common'; +import { DevicePort, IRelatedRef } from 'common/common'; import { Turnout } from 'src/packages/Turnout/Turnout'; export interface ISectionData extends GraphicData { code: string; diff --git a/components/packages/Section/common/Section.js b/components/packages/Section/common/Section.js index 8041d5d..9648a88 100644 --- a/components/packages/Section/common/Section.js +++ b/components/packages/Section/common/Section.js @@ -195,10 +195,10 @@ let Section$1 = class Section extends JlGraphic { } loadRelations() { if (this.datas?.paRef?.id) { - this.relationManage.addRelation(new GraphicRelationParam(this, DevicePort.A), new GraphicRelationParam(this.queryStore.queryById(this.datas.paRef.id), DevicePort[this.datas.paRef.devicePort])); + this.relationManage.addRelation(new GraphicRelationParam(this, DevicePort.A), new GraphicRelationParam(this.queryStore.queryById(this.datas.paRef.id), this.datas.paRef.devicePort)); } if (this.datas?.pbRef?.id) { - this.relationManage.addRelation(new GraphicRelationParam(this, DevicePort.B), new GraphicRelationParam(this.queryStore.queryById(this.datas.pbRef.id), DevicePort[this.datas.pbRef.devicePort])); + this.relationManage.addRelation(new GraphicRelationParam(this, DevicePort.B), new GraphicRelationParam(this.queryStore.queryById(this.datas.pbRef.id), this.datas.pbRef.devicePort)); } if (this.datas.trackSectionId) { this.relationManage.addRelation(this, this.queryStore.queryById(this.datas.trackSectionId)); diff --git a/components/packages/Station/StationConfig.d.ts b/components/packages/Station/StationConfig.d.ts index ac61b20..b8677d5 100644 --- a/components/packages/Station/StationConfig.d.ts +++ b/components/packages/Station/StationConfig.d.ts @@ -1,6 +1,6 @@ import { GraphicData } from 'jl-graphic'; import { CategoryType } from '../Platform/PlatformConfig'; -import { KilometerSystem } from 'src/common/common'; +import { KilometerSystem } from 'common/common'; export interface StationConstsConfig { codeColor: string; codeFontSize: number; @@ -94,15 +94,3 @@ export interface IStationData extends GraphicData { copyFrom(data: IStationData): void; eq(other: IStationData): boolean; } -export interface KilometerSystem { - get coordinateSystem(): string; - set coordinateSystem(v: string); - get kilometer(): number; - set kilometer(v: number); - get direction(): Direction; - set direction(v: Direction); -} -export declare enum Direction { - LEFT = 0, - RIGHT = 1 -} diff --git a/package.json b/package.json index 635ced8..130cac2 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "jl-graphic": "git+https://git.code.tencent.com/jl-framework/graphic-pixi.git#v0.1.3" }, "devDependencies": { + "@rollup/plugin-alias": "^5.1.0", "@rollup/plugin-typescript": "^11.1.5", "@types/node": "^20.10.5", "eslint": "^8.56.0", diff --git a/rollup.config.cjs b/rollup.config.cjs index 11f0858..5607116 100644 --- a/rollup.config.cjs +++ b/rollup.config.cjs @@ -1,6 +1,7 @@ const { resolve, relative, extname } = require('path'); const { readdirSync } = require('fs'); const typescript = require('@rollup/plugin-typescript'); +const { default: alias } = require('@rollup/plugin-alias'); /** * @type {import('rollup').RollupOptions} @@ -14,6 +15,9 @@ const config = { preserveModules: true, }, plugins: [ + alias({ + entries: [{ find: 'common', replacement: 'src/common' }], + }), typescript({ tsconfig: './tsconfig.json', compilerOptions: { diff --git a/src/common/common.ts b/src/common/common.ts index 8be5791..a8af3ba 100644 --- a/src/common/common.ts +++ b/src/common/common.ts @@ -1,7 +1,7 @@ export enum DevicePort { - A = 0, - B = 1, - C = 2, + A = 'A', + B = 'B', + C = 'C', } export enum DeviceType { diff --git a/src/packages/AxleCounting/AxleCounting.ts b/src/packages/AxleCounting/AxleCounting.ts index 6f3be8f..b61792c 100644 --- a/src/packages/AxleCounting/AxleCounting.ts +++ b/src/packages/AxleCounting/AxleCounting.ts @@ -4,11 +4,7 @@ import { JlGraphic, JlGraphicTemplate, } from 'jl-graphic'; -import { - IRelatedRef, - KilometerSystem, - protoPort2Data, -} from 'src/common/common'; +import { IRelatedRef, KilometerSystem, protoPort2Data } from 'common/common'; import { Container, Graphics, Color } from 'pixi.js'; enum TypeDetectionPoint { diff --git a/src/packages/Section/common/Section.ts b/src/packages/Section/common/Section.ts index 33341e2..7a2f8d2 100644 --- a/src/packages/Section/common/Section.ts +++ b/src/packages/Section/common/Section.ts @@ -12,7 +12,7 @@ import { } from 'jl-graphic'; import { IPointData } from 'pixi.js'; import { SectionGraphic } from './SectionGraphic'; -import { DevicePort, DeviceType, IRelatedRef } from 'src/common/common'; +import { DevicePort, DeviceType, IRelatedRef } from 'common/common'; import { Turnout } from 'src/packages/Turnout/Turnout'; import { AxleCounting } from 'src/packages/AxleCounting/AxleCounting'; @@ -307,7 +307,7 @@ export class Section extends JlGraphic { new GraphicRelationParam(this, DevicePort.A), new GraphicRelationParam( this.queryStore.queryById(this.datas.paRef.id), - DevicePort[this.datas.paRef.devicePort], + this.datas.paRef.devicePort, ), ); } @@ -316,7 +316,7 @@ export class Section extends JlGraphic { new GraphicRelationParam(this, DevicePort.B), new GraphicRelationParam( this.queryStore.queryById(this.datas.pbRef.id), - DevicePort[this.datas.pbRef.devicePort], + this.datas.pbRef.devicePort, ), ); } diff --git a/src/packages/Station/StationConfig.ts b/src/packages/Station/StationConfig.ts index 1cbe4e9..4136341 100644 --- a/src/packages/Station/StationConfig.ts +++ b/src/packages/Station/StationConfig.ts @@ -1,6 +1,6 @@ import { GraphicData } from 'jl-graphic'; import { CategoryType } from '../Platform/PlatformConfig'; -import { KilometerSystem } from 'src/common/common'; +import { IRelatedRef, KilometerSystem } from 'common/common'; export interface StationConstsConfig { codeColor: string; diff --git a/tsconfig.json b/tsconfig.json index 6305c54..407d618 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,10 @@ "moduleResolution": "Node", "strict": true, "isolatedModules": true, - "lib": ["ESNext", "DOM"] + "lib": ["ESNext", "DOM"], + "paths": { + "common/*": ["src/common/*"] + } }, "include": ["src/**/*.ts"], "exclude": ["node_modules", "components"] diff --git a/yarn.lock b/yarn.lock index 11f95ea..3855e4c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -323,6 +323,13 @@ picocolors "^1.0.0" tslib "^2.6.0" +"@rollup/plugin-alias@^5.1.0": + version "5.1.0" + resolved "https://registry.npmmirror.com/@rollup/plugin-alias/-/plugin-alias-5.1.0.tgz#99a94accc4ff9a3483be5baeedd5d7da3b597e93" + integrity sha512-lpA3RZ9PdIG7qqhEfv79tBffNaoDuukFDrmhLqg9ifv99u/ehn+lOg30x2zmhf8AQqQUZaMk/B9fZraQ6/acDQ== + dependencies: + slash "^4.0.0" + "@rollup/plugin-typescript@^11.1.5": version "11.1.5" resolved "https://registry.npmmirror.com/@rollup/plugin-typescript/-/plugin-typescript-11.1.5.tgz#039c763bf943a5921f3f42be255895e75764cb91" @@ -1691,6 +1698,11 @@ signal-exit@^3.0.3, signal-exit@^3.0.7: resolved "https://registry.npmmirror.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9" integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ== +slash@^4.0.0: + version "4.0.0" + resolved "https://registry.npmmirror.com/slash/-/slash-4.0.0.tgz#2422372176c4c6c5addb5e2ada885af984b396a7" + integrity sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew== + split2@^4.2.0: version "4.2.0" resolved "https://registry.npmmirror.com/split2/-/split2-4.2.0.tgz#c9c5920904d148bab0b9f67145f245a86aadbfa4"