复制插件增加针对特定图形的KeyListener

This commit is contained in:
joylink_zhaoerwei 2024-01-15 13:45:09 +08:00
parent 100ddafc75
commit b5f2a9c1df
2 changed files with 15 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{
"name": "graphic-pixi",
"version": "0.1.3",
"version": "0.1.4",
"description": "基于pixijs的图形应用、绘制应用框架",
"productName": "Graphic-pixi",
"author": "walker <shengxuqiang@joylink.club>",

View File

@ -10,6 +10,7 @@ export class GraphicCopyPlugin {
container: Container;
scene: IGraphicScene;
keyListeners: KeyListener[];
graphicKeyListenercMap: Map<string, KeyListener[]>;
copys: JlGraphic[];
start?: Point;
running = false;
@ -17,6 +18,7 @@ export class GraphicCopyPlugin {
constructor(scene: IGraphicScene) {
this.scene = scene;
this.container = new Container();
this.graphicKeyListenercMap = new Map<string, KeyListener[]>();
this.copys = [];
this.keyListeners = [];
this.keyListeners.push(
@ -76,6 +78,12 @@ export class GraphicCopyPlugin {
this.container.addChild(clone);
clone.repaint();
});
const addGraphicTypeKeyListener = this.graphicKeyListenercMap.get(
app.selectedGraphics[0].type,
);
if (addGraphicTypeKeyListener) {
this.keyListeners.push(...addGraphicTypeKeyListener);
}
this.scene.canvas.on('mousemove', this.onPointerMove, this);
this.scene.canvas.on('mouseup', this.onFinish, this);
this.scene.canvas.on('rightup', this.cancle, this);
@ -97,6 +105,7 @@ export class GraphicCopyPlugin {
this.keyListeners.forEach((kl) => {
this.scene.app.removeKeyboardListener(kl);
});
this.keyListeners = this.keyListeners.splice(0, 3);
}
onPointerMove(e: FederatedPointerEvent): void {
@ -128,10 +137,14 @@ export class GraphicCopyPlugin {
g.position.x += this.container.position.x;
g.position.y += this.container.position.y;
});
this.saveCopyGraphic();
this.clear();
}
saveCopyGraphic() {
this.scene.app.addGraphicAndRecord(...this.copys);
this.scene.detectRelations();
this.scene.updateSelected(...this.copys);
this.clear();
}
cancle(): void {