2024-01-02 17:03:15 +08:00
|
|
|
import { GraphicDrawAssistant, GraphicInteractionPlugin, AbsorbableLine } from 'jl-graphic';
|
|
|
|
import { JlPlatform } from './JlPlatform.js';
|
2024-01-11 13:38:16 +08:00
|
|
|
import { StyleType } from '../../../common/common.js';
|
2024-01-02 17:03:15 +08:00
|
|
|
|
|
|
|
class PlatformDraw extends GraphicDrawAssistant {
|
|
|
|
platformGraphic;
|
|
|
|
constructor(app, template, icon) {
|
|
|
|
super(app, template, icon, '站台Platform');
|
|
|
|
this.platformGraphic = this.graphicTemplate.new();
|
|
|
|
this.container.addChild(this.platformGraphic);
|
2024-01-03 13:35:59 +08:00
|
|
|
PlatformInteraction.init(app);
|
2024-01-02 17:03:15 +08:00
|
|
|
}
|
|
|
|
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;
|
2024-01-10 15:46:15 +08:00
|
|
|
switch (template.styleType) {
|
|
|
|
case StyleType.TH:
|
2024-01-02 17:03:15 +08:00
|
|
|
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;
|
|
|
|
}
|
2024-01-03 13:35:59 +08:00
|
|
|
class PlatformInteraction extends GraphicInteractionPlugin {
|
2024-01-02 17:03:15 +08:00
|
|
|
static Name = 'platform_transform';
|
|
|
|
constructor(app) {
|
2024-01-03 13:35:59 +08:00
|
|
|
super(PlatformInteraction.Name, app);
|
2024-01-02 17:03:15 +08:00
|
|
|
}
|
|
|
|
static init(app) {
|
2024-01-03 13:35:59 +08:00
|
|
|
return new PlatformInteraction(app);
|
2024-01-02 17:03:15 +08:00
|
|
|
}
|
|
|
|
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),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-03 13:35:59 +08:00
|
|
|
export { PlatformDraw };
|