diff --git a/src/packages/CategoryType.ts b/src/packages/CategoryType.ts new file mode 100644 index 0000000..2018476 --- /dev/null +++ b/src/packages/CategoryType.ts @@ -0,0 +1,5 @@ +export enum CategoryType { + JK = 'JK', // 交控(11) + TH = 'TH', // 通号(12) + ZDWX = 'ZDWX', // 浙大网新 +} diff --git a/src/packages/separator/Separator.ts b/src/packages/separator/Separator.ts new file mode 100644 index 0000000..a27bd6e --- /dev/null +++ b/src/packages/separator/Separator.ts @@ -0,0 +1,94 @@ +import { Color, Graphics } from 'pixi.js'; +import { JlGraphic, JlGraphicTemplate } from 'jl-graphic'; +import { ISeparatorData, SeparatorConstsMap, separatorTypeEnum } from './SeparatorConfig'; +import { CategoryType } from '../CategoryType'; + +let SeparatorConsts = { + height: 12, + lineWidth: 2, + lineColor: '0xFFFFFF', + circleColor: '0xEF0200', + radius: 5, +} + +export class Separator extends JlGraphic { + static Type = 'Separator'; + rectGraphic: Graphics = new Graphics(); + circleGraphic: Graphics = new Graphics(); + private categoryType: CategoryType + constructor(categoryType: CategoryType) { + super(Separator.Type); + this.addChild(this.rectGraphic); + this.addChild(this.circleGraphic); + this.categoryType = categoryType + this.getConstDatas(); + } + get datas(): ISeparatorData { + return this.getDatas(); + } + + getConstDatas():void { + const constData = SeparatorConstsMap.get(this.categoryType) + if (constData) { + SeparatorConsts =constData + } + } + + clear() { + this.rectGraphic.clear(); + this.circleGraphic.clear(); + } + doRepaint(): void { + this.clear(); + const rectGraphic = this.rectGraphic; + if (!this.datas.separatorType) { + this.datas.separatorType = separatorTypeEnum.endA; + } + const typeArr = ['section', 'turnout']; + if (typeArr.includes(this.datas.separatorType)) { + rectGraphic.lineStyle( + SeparatorConsts.lineWidth, + new Color(SeparatorConsts.lineColor) + ); + rectGraphic.moveTo(0, -SeparatorConsts.height / 2); + rectGraphic.lineTo(0, SeparatorConsts.height / 2); + if (this.datas.separatorType == 'turnout') { + this.circleGraphic.lineStyle(1, SeparatorConsts.circleColor); + this.circleGraphic.drawCircle(0, 0, SeparatorConsts.radius); + } + } + const endTypeArr = ['endA', 'endB']; + if (endTypeArr.includes(this.datas.separatorType)) { + let d = SeparatorConsts.radius; + if (this.datas.separatorType == 'endB') { + d = -d; + } + rectGraphic.lineStyle( + SeparatorConsts.lineWidth, + new Color(SeparatorConsts.lineColor) + ); + rectGraphic.moveTo(0, 0); + rectGraphic.lineTo(-d, 0); + rectGraphic.lineTo(-d, -d); + rectGraphic.lineTo(-d * 3, -d); + rectGraphic.moveTo(-d, 0); + rectGraphic.lineTo(-d, d); + rectGraphic.lineTo(-d * 3, d); + } + } +} + +export class SeparatorTemplate extends JlGraphicTemplate { + categoryType:CategoryType; + constructor(dataTemplate: ISeparatorData,gategoryConsts: CategoryType) { + super(Separator.Type, { + dataTemplate, + }); + this.categoryType = gategoryConsts; + } + new(): Separator { + const separator = new Separator(this.categoryType); + separator.loadData(this.datas); + return separator; + } +} diff --git a/src/packages/separator/SeparatorConfig.ts b/src/packages/separator/SeparatorConfig.ts new file mode 100644 index 0000000..0c69f84 --- /dev/null +++ b/src/packages/separator/SeparatorConfig.ts @@ -0,0 +1,44 @@ +import { GraphicData } from "jl-graphic"; +import { CategoryType } from "../CategoryType"; + +export enum separatorTypeEnum { + turnout = 'turnout', // 道岔分隔符 + endA = 'endA', // A端尽头分隔符 + endB = 'endB', // B端尽头分隔符 + section = 'section', // 区段分隔符 +} + +export interface SeparatorConstsConfig{ + height: number, + lineWidth: number, + lineColor: string, + circleColor: string, + radius: number, +} + +const THConsts = { + height: 12, + lineWidth: 2, + lineColor: '0xFFFFFF', + circleColor: '0xEF0200', + radius: 5, +}; +const JKConsts = { + height: 12, + lineWidth: 2, + lineColor: '0x617799', + circleColor: '0xEF0200', + radius: 5, +}; + +export const SeparatorConstsMap = new Map([[CategoryType.JK,JKConsts],[CategoryType.TH,THConsts]]) + +export interface ISeparatorData extends GraphicData { + get code(): string; // 编号 + set code(v: string); + get separatorType(): string; // 类型 + set separatorType(v: string); + clone(): ISeparatorData; + copyFrom(data: ISeparatorData): void; + eq(other: ISeparatorData): boolean; +}