站台代码优化
This commit is contained in:
parent
6fc88043e7
commit
e25403077a
@ -1,10 +1,11 @@
|
|||||||
import { Color, Container, Graphics, Rectangle } from 'pixi.js';
|
import { Color, Container, Graphics, Point, Rectangle } from 'pixi.js';
|
||||||
import {
|
import {
|
||||||
GraphicData,
|
GraphicData,
|
||||||
GraphicState,
|
GraphicState,
|
||||||
JlGraphic,
|
JlGraphic,
|
||||||
JlGraphicTemplate,
|
JlGraphicTemplate,
|
||||||
VectorText,
|
VectorText,
|
||||||
|
calculateMirrorPoint,
|
||||||
getRectangleCenter,
|
getRectangleCenter,
|
||||||
} from 'src/jl-graphic';
|
} from 'src/jl-graphic';
|
||||||
|
|
||||||
@ -152,14 +153,6 @@ export class doorGraphic extends Container {
|
|||||||
doorCloseGraphic.lineStyle(platformConsts.lineWidth, new Color(lineColor));
|
doorCloseGraphic.lineStyle(platformConsts.lineWidth, new Color(lineColor));
|
||||||
doorCloseGraphic.moveTo(-platformConsts.doorOpenSpacing, 0);
|
doorCloseGraphic.moveTo(-platformConsts.doorOpenSpacing, 0);
|
||||||
doorCloseGraphic.lineTo(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 {
|
clear(): void {
|
||||||
this.doorGraphic.clear();
|
this.doorGraphic.clear();
|
||||||
@ -331,12 +324,6 @@ class besideGraphic extends Container {
|
|||||||
);
|
);
|
||||||
besideGraphic.pivot = getRectangleCenter(rect);
|
besideGraphic.pivot = getRectangleCenter(rect);
|
||||||
besideGraphic.rotation = Math.PI / 4;
|
besideGraphic.rotation = Math.PI / 4;
|
||||||
besideGraphic.position.set(
|
|
||||||
0,
|
|
||||||
-platformConsts.height / 2 -
|
|
||||||
platformConsts.doorPlatformSpacing -
|
|
||||||
platformConsts.height / 3
|
|
||||||
);
|
|
||||||
besideGraphic.visible = false;
|
besideGraphic.visible = false;
|
||||||
}
|
}
|
||||||
clear(): void {
|
clear(): void {
|
||||||
@ -379,51 +366,37 @@ export class Platform extends JlGraphic {
|
|||||||
this.platformGraphic.draw(this.states);
|
this.platformGraphic.draw(this.states);
|
||||||
this.besideGraphic.draw();
|
this.besideGraphic.draw();
|
||||||
this.codeGraph.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);
|
this.codeGraph.position.set(0, 0);
|
||||||
//站台方向
|
//站台方向
|
||||||
if (this.datas.direction == 'down') {
|
if (this.datas.direction == 'down') {
|
||||||
this.doorGraphic.position.set(
|
const psChange = [
|
||||||
0,
|
this.doorGraphic,
|
||||||
platformConsts.height + platformConsts.doorPlatformSpacing * 2
|
this.besideGraphic,
|
||||||
);
|
this.codeGraph.children[0],
|
||||||
this.besideGraphic.position.set(
|
this.codeGraph.children[1],
|
||||||
0,
|
this.codeGraph.children[3],
|
||||||
platformConsts.height +
|
this.codeGraph.children[4],
|
||||||
platformConsts.doorPlatformSpacing * 2 +
|
];
|
||||||
(platformConsts.height * 2) / 3
|
psChange.forEach((g) => {
|
||||||
);
|
g.position.copyFrom(calculateMirrorPoint(new Point(0, 0), g.position));
|
||||||
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
|
|
||||||
);
|
|
||||||
this.codeGraph.children[2].position.set(
|
this.codeGraph.children[2].position.set(
|
||||||
platformConsts.width / 2 +
|
platformConsts.width / 2 +
|
||||||
platformConsts.lineWidth / 2 +
|
platformConsts.lineWidth / 2 +
|
||||||
(platformConsts.besideSpacing * 4) / 3,
|
(platformConsts.besideSpacing * 4) / 3,
|
||||||
(-platformConsts.height * 10) / 11
|
(-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();
|
this.changeState();
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,7 @@ import {
|
|||||||
JlGraphic,
|
JlGraphic,
|
||||||
} from 'src/jl-graphic';
|
} from 'src/jl-graphic';
|
||||||
|
|
||||||
import {
|
import { IPlatformData, Platform, PlatformTemplate } from './Platform';
|
||||||
IPlatformData,
|
|
||||||
Platform,
|
|
||||||
PlatformTemplate,
|
|
||||||
rectGraphic,
|
|
||||||
doorGraphic,
|
|
||||||
IPlatformState,
|
|
||||||
} from './Platform';
|
|
||||||
|
|
||||||
export interface IPlatformDrawOptions {
|
export interface IPlatformDrawOptions {
|
||||||
newData: () => IPlatformData;
|
newData: () => IPlatformData;
|
||||||
@ -25,9 +18,7 @@ export class PlatformDraw extends GraphicDrawAssistant<
|
|||||||
PlatformTemplate,
|
PlatformTemplate,
|
||||||
IPlatformData
|
IPlatformData
|
||||||
> {
|
> {
|
||||||
platformGraphic: rectGraphic = new rectGraphic();
|
platformGraphic: Platform;
|
||||||
doorGraphic: doorGraphic = new doorGraphic();
|
|
||||||
|
|
||||||
constructor(app: JlDrawApp, template: PlatformTemplate) {
|
constructor(app: JlDrawApp, template: PlatformTemplate) {
|
||||||
super(
|
super(
|
||||||
app,
|
app,
|
||||||
@ -35,20 +26,19 @@ export class PlatformDraw extends GraphicDrawAssistant<
|
|||||||
'svguse:../../drawIcon.svg#icon-platform',
|
'svguse:../../drawIcon.svg#icon-platform',
|
||||||
'站台Platform'
|
'站台Platform'
|
||||||
);
|
);
|
||||||
|
this.platformGraphic = this.graphicTemplate.new();
|
||||||
this.container.addChild(this.platformGraphic);
|
this.container.addChild(this.platformGraphic);
|
||||||
this.container.addChild(this.doorGraphic);
|
|
||||||
platformInteraction.init(app);
|
platformInteraction.init(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
bind(): void {
|
bind(): void {
|
||||||
super.bind();
|
super.bind();
|
||||||
this.platformGraphic.draw(this.graphicTemplate.states as IPlatformState);
|
this.platformGraphic.loadData(this.graphicTemplate.datas);
|
||||||
this.doorGraphic.draw(this.graphicTemplate.states as IPlatformState);
|
this.platformGraphic.doRepaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
clearCache(): void {
|
clearCache(): void {
|
||||||
this.platformGraphic.clear();
|
//this.platformGraphic.clear();
|
||||||
this.doorGraphic.clear();
|
|
||||||
}
|
}
|
||||||
onLeftDown(e: FederatedPointerEvent): void {
|
onLeftDown(e: FederatedPointerEvent): void {
|
||||||
this.container.position.copyFrom(this.toCanvasCoordinates(e.global));
|
this.container.position.copyFrom(this.toCanvasCoordinates(e.global));
|
||||||
|
@ -12,7 +12,7 @@ import { Section, SectionType } from '../section/Section';
|
|||||||
export interface ITrainWindowData extends GraphicData {
|
export interface ITrainWindowData extends GraphicData {
|
||||||
get code(): string; // 编号
|
get code(): string; // 编号
|
||||||
set code(v: string);
|
set code(v: string);
|
||||||
get sectionId(): string; // 编号
|
get sectionId(): string; // 关联的区段的id
|
||||||
set sectionId(v: string);
|
set sectionId(v: string);
|
||||||
clone(): ITrainWindowData;
|
clone(): ITrainWindowData;
|
||||||
copyFrom(data: ITrainWindowData): void;
|
copyFrom(data: ITrainWindowData): void;
|
||||||
|
Loading…
Reference in New Issue
Block a user