站台代码优化

This commit is contained in:
joylink_zhaoerwei 2023-07-05 10:19:17 +08:00
parent 6fc88043e7
commit e25403077a
3 changed files with 31 additions and 68 deletions

View File

@ -1,10 +1,11 @@
import { Color, Container, Graphics, Rectangle } from 'pixi.js';
import { Color, Container, Graphics, Point, Rectangle } from 'pixi.js';
import {
GraphicData,
GraphicState,
JlGraphic,
JlGraphicTemplate,
VectorText,
calculateMirrorPoint,
getRectangleCenter,
} from 'src/jl-graphic';
@ -152,14 +153,6 @@ export class doorGraphic extends Container {
doorCloseGraphic.lineStyle(platformConsts.lineWidth, new Color(lineColor));
doorCloseGraphic.moveTo(-platformConsts.doorOpenSpacing, 0);
doorCloseGraphic.lineTo(platformConsts.doorOpenSpacing, 0);
doorGraphic.position.set(
0,
-platformConsts.height / 2 - platformConsts.doorPlatformSpacing
);
doorCloseGraphic.position.set(
0,
-platformConsts.height / 2 - platformConsts.doorPlatformSpacing
);
}
clear(): void {
this.doorGraphic.clear();
@ -331,12 +324,6 @@ class besideGraphic extends Container {
);
besideGraphic.pivot = getRectangleCenter(rect);
besideGraphic.rotation = Math.PI / 4;
besideGraphic.position.set(
0,
-platformConsts.height / 2 -
platformConsts.doorPlatformSpacing -
platformConsts.height / 3
);
besideGraphic.visible = false;
}
clear(): void {
@ -379,51 +366,37 @@ export class Platform extends JlGraphic {
this.platformGraphic.draw(this.states);
this.besideGraphic.draw();
this.codeGraph.draw();
this.doorGraphic.position.set(0, 0);
this.besideGraphic.position.set(0, 0);
this.doorGraphic.position.set(
0,
-platformConsts.height / 2 - platformConsts.doorPlatformSpacing
);
this.besideGraphic.position.set(
0,
-platformConsts.height / 2 -
platformConsts.doorPlatformSpacing -
platformConsts.height / 3
);
this.codeGraph.position.set(0, 0);
//站台方向
if (this.datas.direction == 'down') {
this.doorGraphic.position.set(
0,
platformConsts.height + platformConsts.doorPlatformSpacing * 2
);
this.besideGraphic.position.set(
0,
platformConsts.height +
platformConsts.doorPlatformSpacing * 2 +
(platformConsts.height * 2) / 3
);
this.codeGraph.children[0].position.set(
platformConsts.width / 2 +
platformConsts.lineWidth / 2 +
(platformConsts.besideSpacing * 2) / 3,
-(platformConsts.height * 3) / 4
);
this.codeGraph.children[1].position.set(
-platformConsts.width / 2 -
platformConsts.lineWidth / 2 -
3 * platformConsts.besideSpacing,
platformConsts.besideSpacing
);
const psChange = [
this.doorGraphic,
this.besideGraphic,
this.codeGraph.children[0],
this.codeGraph.children[1],
this.codeGraph.children[3],
this.codeGraph.children[4],
];
psChange.forEach((g) => {
g.position.copyFrom(calculateMirrorPoint(new Point(0, 0), g.position));
});
this.codeGraph.children[2].position.set(
platformConsts.width / 2 +
platformConsts.lineWidth / 2 +
(platformConsts.besideSpacing * 4) / 3,
(-platformConsts.height * 10) / 11
);
this.codeGraph.children[3].position.set(
-platformConsts.width / 2 -
platformConsts.lineWidth / 2 -
platformConsts.besideSpacing,
-platformConsts.besideSpacing
);
this.codeGraph.children[4].position.set(
-platformConsts.width / 2 -
platformConsts.lineWidth / 2 -
platformConsts.besideSpacing,
platformConsts.besideSpacing
);
}
this.changeState();
}

View File

@ -8,14 +8,7 @@ import {
JlGraphic,
} from 'src/jl-graphic';
import {
IPlatformData,
Platform,
PlatformTemplate,
rectGraphic,
doorGraphic,
IPlatformState,
} from './Platform';
import { IPlatformData, Platform, PlatformTemplate } from './Platform';
export interface IPlatformDrawOptions {
newData: () => IPlatformData;
@ -25,9 +18,7 @@ export class PlatformDraw extends GraphicDrawAssistant<
PlatformTemplate,
IPlatformData
> {
platformGraphic: rectGraphic = new rectGraphic();
doorGraphic: doorGraphic = new doorGraphic();
platformGraphic: Platform;
constructor(app: JlDrawApp, template: PlatformTemplate) {
super(
app,
@ -35,20 +26,19 @@ export class PlatformDraw extends GraphicDrawAssistant<
'svguse:../../drawIcon.svg#icon-platform',
'站台Platform'
);
this.platformGraphic = this.graphicTemplate.new();
this.container.addChild(this.platformGraphic);
this.container.addChild(this.doorGraphic);
platformInteraction.init(app);
}
bind(): void {
super.bind();
this.platformGraphic.draw(this.graphicTemplate.states as IPlatformState);
this.doorGraphic.draw(this.graphicTemplate.states as IPlatformState);
this.platformGraphic.loadData(this.graphicTemplate.datas);
this.platformGraphic.doRepaint();
}
clearCache(): void {
this.platformGraphic.clear();
this.doorGraphic.clear();
//this.platformGraphic.clear();
}
onLeftDown(e: FederatedPointerEvent): void {
this.container.position.copyFrom(this.toCanvasCoordinates(e.global));

View File

@ -12,7 +12,7 @@ import { Section, SectionType } from '../section/Section';
export interface ITrainWindowData extends GraphicData {
get code(): string; // 编号
set code(v: string);
get sectionId(): string; // 编号
get sectionId(): string; // 关联的区段的id
set sectionId(v: string);
clone(): ITrainWindowData;
copyFrom(data: ITrainWindowData): void;