From d57b7bdbfaeec770e1b9395e10c7eeba07e8d116 Mon Sep 17 00:00:00 2001 From: fan Date: Tue, 20 Jun 2023 11:06:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- graphic-pixi | 2 +- src/jl-graphic/app/JlDrawApp.ts | 5 +-- src/jl-graphic/core/JlGraphic.ts | 34 ++++++++++++++++++++- src/jl-graphic/plugins/GraphicEditPlugin.ts | 1 - 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/graphic-pixi b/graphic-pixi index 6d905a2..33ac26a 160000 --- a/graphic-pixi +++ b/graphic-pixi @@ -1 +1 @@ -Subproject commit 6d905a2fbeca5e52b94df9a4a29282828e9a679b +Subproject commit 33ac26a8259c7a1b247612e826861bc8a183d4c9 diff --git a/src/jl-graphic/app/JlDrawApp.ts b/src/jl-graphic/app/JlDrawApp.ts index 22151c0..8a1bfa2 100644 --- a/src/jl-graphic/app/JlDrawApp.ts +++ b/src/jl-graphic/app/JlDrawApp.ts @@ -45,7 +45,6 @@ export abstract class GraphicDrawAssistant< icon: string; // 界面显示的图标 container: Container = new Container(); graphicTemplate: GT; - createGraphicData: () => GD; escListener: KeyListener = new KeyListener({ value: 'Escape', @@ -61,7 +60,6 @@ export abstract class GraphicDrawAssistant< constructor( graphicApp: JlDrawApp, graphicTemplate: GT, - createGraphicData: () => GD, icon: string, description: string ) { @@ -69,7 +67,6 @@ export abstract class GraphicDrawAssistant< this.app = graphicApp; this.type = graphicTemplate.type; this.graphicTemplate = graphicTemplate; - this.createGraphicData = createGraphicData; this.icon = icon; this.description = description; this.app.registerGraphicTemplates(this.graphicTemplate); @@ -163,7 +160,7 @@ export abstract class GraphicDrawAssistant< * 创建并添加到图形App */ createAndStore(finish: boolean): JlGraphic | null { - const data = this.createGraphicData(); + const data = this.graphicTemplate.datas as GD; data.id = this.nextId(); data.graphicType = this.graphicTemplate.type; if (!this.prepareData(data)) { diff --git a/src/jl-graphic/core/JlGraphic.ts b/src/jl-graphic/core/JlGraphic.ts index 640b6fd..2d07da3 100644 --- a/src/jl-graphic/core/JlGraphic.ts +++ b/src/jl-graphic/core/JlGraphic.ts @@ -923,15 +923,47 @@ export abstract class JlGraphic extends Container { } } +export type CreateData = () => GraphicData; +export type CreateState = () => GraphicState; + +export interface IGraphicTemplateOptions { + dataTemplate?: GraphicData; + stateTemplate?: GraphicState; +} + /** * 图形对象模板 */ export abstract class JlGraphicTemplate { readonly type: string; + options: IGraphicTemplateOptions; - constructor(type: string) { + constructor(type: string, options: IGraphicTemplateOptions) { this.type = type; + this.options = options; } + + get datas(): GraphicData { + if (this.options.dataTemplate) { + return this.options.dataTemplate.clone(); + } + throw new Error(`type=${this.type}的图形模板没有数据模板`); + } + + get states(): GraphicState { + if (this.options.stateTemplate) { + return this.options.stateTemplate.clone(); + } + throw new Error(`type=${this.type}的图形模板没有状态模板`); + } + + // getDataCreator(): T { + // return this.options.dataCreator as T; + // } + // getStateCreator(): T { + // return this.options.stateCreator as T; + // } + /** * 初始化一个新的图形对象 */ diff --git a/src/jl-graphic/plugins/GraphicEditPlugin.ts b/src/jl-graphic/plugins/GraphicEditPlugin.ts index a9986e3..9b1cc5b 100644 --- a/src/jl-graphic/plugins/GraphicEditPlugin.ts +++ b/src/jl-graphic/plugins/GraphicEditPlugin.ts @@ -10,7 +10,6 @@ import { import { JlGraphic } from '../core'; import { DraggablePoint } from '../graphic'; import { - assertBezierPoints, calculateDistanceFromPointToLine, calculateFootPointFromPointToLine, calculateLineSegmentingPoint,