TS配置启用对ES模块的兼容性支持+站台绘制助手

This commit is contained in:
joylink_zhaoerwei 2024-01-02 16:29:31 +08:00
parent 1946c1a1c2
commit f8e1f3b7aa
2 changed files with 110 additions and 0 deletions

View File

@ -0,0 +1,109 @@
import { FederatedPointerEvent, Point } from 'pixi.js';
import {
AbsorbableLine,
AbsorbablePosition,
GraphicDrawAssistant,
GraphicInteractionPlugin,
IDrawApp,
JlGraphic,
} from 'jl-graphic';
import { JlPlatform, PlatformTemplate } from './JlPlatform';
import { CategoryType, IPlatformData } from './PlatformConfig';
export interface IPlatformDrawOptions {
newData: () => IPlatformData;
}
export class PlatformDraw extends GraphicDrawAssistant<
PlatformTemplate,
IPlatformData
> {
platformGraphic: JlPlatform;
constructor(app: IDrawApp, template: PlatformTemplate, icon: string) {
super(app, template, icon, '站台Platform');
this.platformGraphic = this.graphicTemplate.new();
this.container.addChild(this.platformGraphic);
platformInteraction.init(app);
}
bind(): void {
super.bind();
this.platformGraphic.loadData(this.graphicTemplate.datas);
this.platformGraphic.doRepaint();
}
onLeftDown(e: FederatedPointerEvent): void {
this.container.position.copyFrom(this.toCanvasCoordinates(e.global));
this.createAndStore(true);
}
redraw(p: Point): void {
this.container.position.copyFrom(p);
}
prepareData(data: IPlatformData): boolean {
const template = this.graphicTemplate;
switch (template.categoryType) {
case CategoryType.XiAn:
data.hasdoor = template.hasdoor;
data.direction = template.direction;
break;
}
data.transform = this.container.saveTransform();
return true;
}
}
function buildAbsorbablePositions(platform: JlPlatform): AbsorbablePosition[] {
const aps: AbsorbablePosition[] = [];
const platforms = platform.queryStore.queryByType<JlPlatform>(
JlPlatform.Type,
);
const { width, height } = platform.getGraphicApp().canvas;
platforms.forEach((other) => {
if (other.id == platform.id) {
return;
}
const ps = other.datas.transform.position;
const xs = new AbsorbableLine({ x: 0, y: ps.y }, { x: width, y: ps.y });
const ys = new AbsorbableLine({ x: ps.x, y: 0 }, { x: ps.x, y: height });
aps.push(xs, ys);
});
return aps;
}
export class platformInteraction extends GraphicInteractionPlugin<JlPlatform> {
static Name = 'platform_transform';
constructor(app: IDrawApp) {
super(platformInteraction.Name, app);
}
static init(app: IDrawApp) {
return new platformInteraction(app);
}
filter(...grahpics: JlGraphic[]): JlPlatform[] | undefined {
return grahpics
.filter((g) => g.type === JlPlatform.Type)
.map((g) => g as JlPlatform);
}
bind(g: JlPlatform): void {
g.eventMode = 'static';
g.cursor = 'pointer';
g.scalable = true;
g.rotatable = true;
g.on('selected', this.onSelected, this);
}
unbind(g: JlPlatform): void {
g.eventMode = 'none';
g.scalable = false;
g.rotatable = false;
g.off('selected', this.onSelected, this);
}
onSelected(): void {
const platform = this.app.selectedGraphics[0] as JlPlatform;
this.app.setOptions({
absorbablePositions: buildAbsorbablePositions(platform),
});
}
}

View File

@ -4,6 +4,7 @@
"allowJs": false,
"module": "ESNext",
"target": "ESNext",
"esModuleInterop": true,
"moduleResolution": "Node",
"strict": true,
"isolatedModules": true,