import { GraphicDrawAssistant, GraphicInteractionPlugin, AbsorbableLine } from 'jl-graphic'; import { JlPlatform } from './JlPlatform.js'; import { StyleType } from '../../common/common.js'; class PlatformDraw extends GraphicDrawAssistant { platformGraphic; constructor(app, template, icon) { super(app, template, icon, '站台Platform'); this.platformGraphic = this.graphicTemplate.new(); this.container.addChild(this.platformGraphic); PlatformInteraction.init(app); } bind() { super.bind(); this.platformGraphic.loadData(this.graphicTemplate.datas); this.platformGraphic.doRepaint(); } onLeftDown(e) { this.container.position.copyFrom(this.toCanvasCoordinates(e.global)); this.createAndStore(true); } redraw(p) { this.container.position.copyFrom(p); } prepareData(data) { const template = this.graphicTemplate; switch (template.styleType) { case StyleType.TH: data.hasdoor = template.hasdoor; data.direction = template.direction; break; } data.transform = this.container.saveTransform(); return true; } } function buildAbsorbablePositions(platform) { const aps = []; const platforms = platform.queryStore.queryByType(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; } class PlatformInteraction extends GraphicInteractionPlugin { static Name = 'platform_transform'; constructor(app) { super(PlatformInteraction.Name, app); } static init(app) { return new PlatformInteraction(app); } filter(...grahpics) { return grahpics .filter((g) => g.type === JlPlatform.Type) .map((g) => g); } bind(g) { g.eventMode = 'static'; g.cursor = 'pointer'; g.scalable = true; g.rotatable = true; g.on('selected', this.onSelected, this); } unbind(g) { g.eventMode = 'none'; g.scalable = false; g.rotatable = false; g.off('selected', this.onSelected, this); } onSelected() { const platform = this.app.selectedGraphics[0]; this.app.setOptions({ absorbablePositions: buildAbsorbablePositions(platform), }); } } export { PlatformDraw };