复制插件修改

This commit is contained in:
joylink_zhaoerwei 2024-01-15 16:08:34 +08:00
parent dd9c5b528a
commit 294973738c
4 changed files with 34 additions and 16 deletions

View File

@ -1068,7 +1068,7 @@ class GraphicCopyPlugin {
container; container;
scene; scene;
keyListeners; keyListeners;
graphicKeyListenercMap; graphicControlers;
copys; copys;
start; start;
running = false; running = false;
@ -1076,7 +1076,7 @@ class GraphicCopyPlugin {
constructor(scene) { constructor(scene) {
this.scene = scene; this.scene = scene;
this.container = new Container(); this.container = new Container();
this.graphicKeyListenercMap = new Map(); this.graphicControlers = [];
this.copys = []; this.copys = [];
this.keyListeners = []; this.keyListeners = [];
this.keyListeners.push(new KeyListener({ this.keyListeners.push(new KeyListener({
@ -1132,10 +1132,11 @@ class GraphicCopyPlugin {
this.container.addChild(clone); this.container.addChild(clone);
clone.repaint(); clone.repaint();
}); });
const addGraphicTypeKeyListener = this.graphicKeyListenercMap.get(app.selectedGraphics[0].type); this.graphicControlers.forEach((graphicControler) => {
if (addGraphicTypeKeyListener) { if (graphicControler.check()) {
this.keyListeners.push(...addGraphicTypeKeyListener); this.keyListeners.push(...graphicControler.controlerList);
} }
});
this.scene.canvas.on('mousemove', this.onPointerMove, this); this.scene.canvas.on('mousemove', this.onPointerMove, this);
this.scene.canvas.on('mouseup', this.onFinish, this); this.scene.canvas.on('mouseup', this.onFinish, this);
this.scene.canvas.on('rightup', this.cancle, this); this.scene.canvas.on('rightup', this.cancle, this);
@ -1143,6 +1144,9 @@ class GraphicCopyPlugin {
this.scene.app.addKeyboardListener(kl); this.scene.app.addKeyboardListener(kl);
}); });
} }
addGraphicControlers(graphicControlers) {
this.graphicControlers.push(...graphicControlers);
}
clear() { clear() {
this.running = false; this.running = false;
this.start = undefined; this.start = undefined;

View File

@ -2,6 +2,10 @@ import { Container, FederatedPointerEvent, Point } from 'pixi.js';
import { IGraphicScene } from '../app'; import { IGraphicScene } from '../app';
import { JlGraphic } from '../core'; import { JlGraphic } from '../core';
import { KeyListener } from './KeyboardPlugin'; import { KeyListener } from './KeyboardPlugin';
interface GraphicControler {
controlerList: KeyListener[];
check: () => boolean;
}
/** /**
* *
*/ */
@ -9,7 +13,7 @@ export declare class GraphicCopyPlugin {
container: Container; container: Container;
scene: IGraphicScene; scene: IGraphicScene;
keyListeners: KeyListener[]; keyListeners: KeyListener[];
graphicKeyListenercMap: Map<string, KeyListener[]>; graphicControlers: GraphicControler[];
copys: JlGraphic[]; copys: JlGraphic[];
start?: Point; start?: Point;
running: boolean; running: boolean;
@ -17,9 +21,11 @@ export declare class GraphicCopyPlugin {
constructor(scene: IGraphicScene); constructor(scene: IGraphicScene);
updateMoveLimit(limit?: 'x' | 'y'): void; updateMoveLimit(limit?: 'x' | 'y'): void;
init(): void; init(): void;
addGraphicControlers(graphicControlers: GraphicControler[]): void;
clear(): void; clear(): void;
onPointerMove(e: FederatedPointerEvent): void; onPointerMove(e: FederatedPointerEvent): void;
onFinish(): void; onFinish(): void;
saveCopyGraphic(): void; saveCopyGraphic(): void;
cancle(): void; cancle(): void;
} }
export {};

View File

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

View File

@ -3,6 +3,11 @@ import { IGraphicScene } from '../app';
import { JlGraphic } from '../core'; import { JlGraphic } from '../core';
import { KeyListener } from './KeyboardPlugin'; import { KeyListener } from './KeyboardPlugin';
interface GraphicControler {
controlerList: KeyListener[];
check: () => boolean;
}
/** /**
* *
*/ */
@ -10,7 +15,7 @@ export class GraphicCopyPlugin {
container: Container; container: Container;
scene: IGraphicScene; scene: IGraphicScene;
keyListeners: KeyListener[]; keyListeners: KeyListener[];
graphicKeyListenercMap: Map<string, KeyListener[]>; graphicControlers: GraphicControler[];
copys: JlGraphic[]; copys: JlGraphic[];
start?: Point; start?: Point;
running = false; running = false;
@ -18,7 +23,7 @@ export class GraphicCopyPlugin {
constructor(scene: IGraphicScene) { constructor(scene: IGraphicScene) {
this.scene = scene; this.scene = scene;
this.container = new Container(); this.container = new Container();
this.graphicKeyListenercMap = new Map<string, KeyListener[]>(); this.graphicControlers = [];
this.copys = []; this.copys = [];
this.keyListeners = []; this.keyListeners = [];
this.keyListeners.push( this.keyListeners.push(
@ -78,12 +83,11 @@ export class GraphicCopyPlugin {
this.container.addChild(clone); this.container.addChild(clone);
clone.repaint(); clone.repaint();
}); });
const addGraphicTypeKeyListener = this.graphicKeyListenercMap.get( this.graphicControlers.forEach((graphicControler) => {
app.selectedGraphics[0].type, if (graphicControler.check()) {
); this.keyListeners.push(...graphicControler.controlerList);
if (addGraphicTypeKeyListener) {
this.keyListeners.push(...addGraphicTypeKeyListener);
} }
});
this.scene.canvas.on('mousemove', this.onPointerMove, this); this.scene.canvas.on('mousemove', this.onPointerMove, this);
this.scene.canvas.on('mouseup', this.onFinish, this); this.scene.canvas.on('mouseup', this.onFinish, this);
this.scene.canvas.on('rightup', this.cancle, 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 { clear(): void {
this.running = false; this.running = false;
this.start = undefined; this.start = undefined;