diff --git a/lib/index.js b/lib/index.js index 7d8cfd5..2fe1080 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1068,7 +1068,7 @@ class GraphicCopyPlugin { container; scene; keyListeners; - graphicKeyListenercMap; + graphicControlers; copys; start; running = false; @@ -1076,7 +1076,7 @@ class GraphicCopyPlugin { constructor(scene) { this.scene = scene; this.container = new Container(); - this.graphicKeyListenercMap = new Map(); + this.graphicControlers = []; this.copys = []; this.keyListeners = []; this.keyListeners.push(new KeyListener({ @@ -1132,10 +1132,11 @@ class GraphicCopyPlugin { this.container.addChild(clone); clone.repaint(); }); - const addGraphicTypeKeyListener = this.graphicKeyListenercMap.get(app.selectedGraphics[0].type); - if (addGraphicTypeKeyListener) { - this.keyListeners.push(...addGraphicTypeKeyListener); - } + this.graphicControlers.forEach((graphicControler) => { + if (graphicControler.check()) { + this.keyListeners.push(...graphicControler.controlerList); + } + }); this.scene.canvas.on('mousemove', this.onPointerMove, this); this.scene.canvas.on('mouseup', this.onFinish, this); this.scene.canvas.on('rightup', this.cancle, this); @@ -1143,6 +1144,9 @@ class GraphicCopyPlugin { this.scene.app.addKeyboardListener(kl); }); } + addGraphicControlers(graphicControlers) { + this.graphicControlers.push(...graphicControlers); + } clear() { this.running = false; this.start = undefined; diff --git a/lib/plugins/CopyPlugin.d.ts b/lib/plugins/CopyPlugin.d.ts index c88899f..f117769 100644 --- a/lib/plugins/CopyPlugin.d.ts +++ b/lib/plugins/CopyPlugin.d.ts @@ -2,6 +2,10 @@ import { Container, FederatedPointerEvent, Point } from 'pixi.js'; import { IGraphicScene } from '../app'; import { JlGraphic } from '../core'; import { KeyListener } from './KeyboardPlugin'; +interface GraphicControler { + controlerList: KeyListener[]; + check: () => boolean; +} /** * 图形复制插件 */ @@ -9,7 +13,7 @@ export declare class GraphicCopyPlugin { container: Container; scene: IGraphicScene; keyListeners: KeyListener[]; - graphicKeyListenercMap: Map; + graphicControlers: GraphicControler[]; copys: JlGraphic[]; start?: Point; running: boolean; @@ -17,9 +21,11 @@ export declare class GraphicCopyPlugin { constructor(scene: IGraphicScene); updateMoveLimit(limit?: 'x' | 'y'): void; init(): void; + addGraphicControlers(graphicControlers: GraphicControler[]): void; clear(): void; onPointerMove(e: FederatedPointerEvent): void; onFinish(): void; saveCopyGraphic(): void; cancle(): void; } +export {}; diff --git a/package.json b/package.json index 5863d3f..5250347 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "graphic-pixi", - "version": "0.1.4", + "version": "0.1.6", "description": "基于pixijs的图形应用、绘制应用框架", "productName": "Graphic-pixi", "author": "walker ", diff --git a/src/plugins/CopyPlugin.ts b/src/plugins/CopyPlugin.ts index 19af628..695f245 100644 --- a/src/plugins/CopyPlugin.ts +++ b/src/plugins/CopyPlugin.ts @@ -3,6 +3,11 @@ import { IGraphicScene } from '../app'; import { JlGraphic } from '../core'; import { KeyListener } from './KeyboardPlugin'; +interface GraphicControler { + controlerList: KeyListener[]; + check: () => boolean; +} + /** * 图形复制插件 */ @@ -10,7 +15,7 @@ export class GraphicCopyPlugin { container: Container; scene: IGraphicScene; keyListeners: KeyListener[]; - graphicKeyListenercMap: Map; + graphicControlers: GraphicControler[]; copys: JlGraphic[]; start?: Point; running = false; @@ -18,7 +23,7 @@ export class GraphicCopyPlugin { constructor(scene: IGraphicScene) { this.scene = scene; this.container = new Container(); - this.graphicKeyListenercMap = new Map(); + this.graphicControlers = []; this.copys = []; this.keyListeners = []; this.keyListeners.push( @@ -78,12 +83,11 @@ 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.graphicControlers.forEach((graphicControler) => { + if (graphicControler.check()) { + this.keyListeners.push(...graphicControler.controlerList); + } + }); this.scene.canvas.on('mousemove', this.onPointerMove, this); this.scene.canvas.on('mouseup', this.onFinish, this); this.scene.canvas.on('rightup', this.cancle, this); @@ -92,6 +96,10 @@ export class GraphicCopyPlugin { }); } + addGraphicControlers(graphicControlers: GraphicControler[]) { + this.graphicControlers.push(...graphicControlers); + } + clear(): void { this.running = false; this.start = undefined;