diff --git a/src/examples/app/app_message/protos/draw_data_storage.proto b/src/examples/app/app_message/protos/draw_data_storage.proto index 5cf6407..5d7d9fb 100644 --- a/src/examples/app/app_message/protos/draw_data_storage.proto +++ b/src/examples/app/app_message/protos/draw_data_storage.proto @@ -5,6 +5,7 @@ package graphicData; message RtssGraphicStorage { Canvas canvas = 1; repeated Link links = 2; + repeated IscsFan iscsFans = 3; } message Canvas { @@ -61,3 +62,8 @@ message Link { string lineColor = 6; // 线色 repeated Point points = 7; // 点坐标列表 } + +message IscsFan { + CommonInfo common = 1; + string code = 2; +} diff --git a/src/examples/app/graphics/BaseGraphicData.ts b/src/examples/app/graphics/BaseGraphicData.ts new file mode 100644 index 0000000..628d6ec --- /dev/null +++ b/src/examples/app/graphics/BaseGraphicData.ts @@ -0,0 +1,87 @@ +import * as pb_1 from 'google-protobuf'; +import { + ChildTransform, + GraphicData, + GraphicTransform, + IChildTransform, + IGraphicTransform, +} from 'src/jlgraphic'; +import { toStorageTransform } from '..'; +import { graphicData } from '../protos/draw_data_storage'; + +export interface ICommonInfo { + id: string; + graphicType: string; + transform: IGraphicTransform; + childTransforms: IChildTransform[]; +} + +export interface IProtoGraphicData extends pb_1.Message { + common: ICommonInfo; + code: string; +} + +export abstract class BaseGraphicData implements GraphicData { + _data: IProtoGraphicData; + constructor(data: IProtoGraphicData) { + this._data = data; + } + + getData(): D { + return this._data as D; + } + + get id(): string { + return this._data.common.id; + } + set id(v: string) { + this._data.common.id = v; + } + get graphicType(): string { + return this._data.common.graphicType; + } + set graphicType(v: string) { + this._data.common.graphicType = v; + } + get transform(): GraphicTransform { + return GraphicTransform.from(this._data.common.transform); + } + set transform(v: GraphicTransform) { + this._data.common.transform = toStorageTransform(v); + } + get childTransforms(): ChildTransform[] | undefined { + const cts: ChildTransform[] = []; + if (this._data.common.childTransforms) { + this._data.common.childTransforms.forEach((ct) => { + cts.push(ChildTransform.from(ct)); + }); + } + return cts; + } + set childTransforms(v: ChildTransform[] | undefined) { + if (v) { + const cts: graphicData.ChildTransform[] = []; + v.forEach((ct) => + cts.push( + new graphicData.ChildTransform({ + ...ct, + transform: toStorageTransform(ct.transform), + }) + ) + ); + this._data.common.childTransforms = cts; + } else { + this._data.common.childTransforms = []; + } + } + + clone(): GraphicData { + throw new Error('Method not implemented.'); + } + copyFrom(gd: BaseGraphicData): void { + pb_1.Message.copyInto(gd._data, this._data); + } + eq(other: BaseGraphicData): boolean { + return pb_1.Message.equals(this._data, other._data); + } +} diff --git a/src/examples/app/graphics/IscsFanInteraction.ts b/src/examples/app/graphics/IscsFanInteraction.ts new file mode 100644 index 0000000..347ffe6 --- /dev/null +++ b/src/examples/app/graphics/IscsFanInteraction.ts @@ -0,0 +1,38 @@ +import * as pb_1 from 'google-protobuf'; +import { IIscsFanData } from 'src/graphics/iscs-fan/IscsFan'; +import { graphicData } from '../protos/draw_data_storage'; +import { BaseGraphicData } from './BaseGraphicData'; + +export class IscsFanData extends BaseGraphicData implements IIscsFanData { + constructor(data?: graphicData.IscsFan) { + let fan; + if (data) { + fan = data; + } else { + fan = new graphicData.IscsFan({ + common: new graphicData.CommonInfo(), + }); + } + super(fan); + } + + public get data(): graphicData.IscsFan { + return this.getData(); + } + + get code(): string { + return this.data.code; + } + set code(v: string) { + this.data.code = v; + } + clone(): IscsFanData { + return new IscsFanData(this.data.cloneMessage()); + } + copyFrom(data: IscsFanData): void { + pb_1.Message.copyInto(data.data, this.data); + } + eq(other: IscsFanData): boolean { + return pb_1.Message.equals(this.data, other.data); + } +} diff --git a/src/examples/app/graphics/LinkInteraction.ts b/src/examples/app/graphics/LinkInteraction.ts index 6f23466..73fbb0a 100644 --- a/src/examples/app/graphics/LinkInteraction.ts +++ b/src/examples/app/graphics/LinkInteraction.ts @@ -1,21 +1,26 @@ import * as pb_1 from 'google-protobuf'; import { IPointData } from 'pixi.js'; import { ILinkData } from 'src/graphics/link/Link'; -import { ChildTransform, GraphicTransform } from 'src/jlgraphic'; -import { toStorageTransform } from '..'; import { graphicData } from '../protos/draw_data_storage'; +import { BaseGraphicData } from './BaseGraphicData'; -export class LinkData implements ILinkData { - data: graphicData.Link; +export class LinkData extends BaseGraphicData implements ILinkData { constructor(data?: graphicData.Link) { - if (data) { - this.data = data; - } else { - this.data = new graphicData.Link({ + let link; + if (!data) { + link = new graphicData.Link({ common: new graphicData.CommonInfo(), }); + } else { + link = data; } + super(link); } + + public get data(): graphicData.Link { + return this.getData(); + } + get code(): string { return this.data.code; } @@ -63,47 +68,4 @@ export class LinkData implements ILinkData { eq(other: LinkData): boolean { return pb_1.Message.equals(this.data, other.data); } - get id(): string { - return this.data.common.id; - } - set id(v: string) { - this.data.common.id = v; - } - get graphicType(): string { - return this.data.common.graphicType; - } - set graphicType(v: string) { - this.data.common.graphicType = v; - } - get transform(): GraphicTransform { - return GraphicTransform.from(this.data.common.transform); - } - set transform(v: GraphicTransform) { - this.data.common.transform = toStorageTransform(v); - } - get childTransforms(): ChildTransform[] | undefined { - const cts: ChildTransform[] = []; - if (this.data.common.childTransforms) { - this.data.common.childTransforms.forEach((ct) => { - cts.push(ChildTransform.from(ct)); - }); - } - return cts; - } - set childTransforms(v: ChildTransform[] | undefined) { - if (v) { - const cts: graphicData.ChildTransform[] = []; - v.forEach((ct) => - cts.push( - new graphicData.ChildTransform({ - ...ct, - transform: toStorageTransform(ct.transform), - }) - ) - ); - this.data.common.childTransforms = cts; - } else { - this.data.common.childTransforms = []; - } - } } diff --git a/src/examples/app/index.ts b/src/examples/app/index.ts index 9c00df7..d016df7 100644 --- a/src/examples/app/index.ts +++ b/src/examples/app/index.ts @@ -12,6 +12,9 @@ import { } from 'src/jlgraphic'; import { LinkData } from './graphics/LinkInteraction'; import { graphicData } from './protos/draw_data_storage'; +import { IscsFanDraw } from 'src/graphics/iscs-fan/IscsFanDrawAssistant'; +import { IscsFanData } from './graphics/IscsFanInteraction'; +import { IscsFan } from 'src/graphics/iscs-fan/IscsFan'; export function fromStoragePoint(p: graphicData.Point): Point { return new Point(p.x, p.y); @@ -46,13 +49,15 @@ export function toStorageTransform( export function initDrawApp(app: JlDrawApp) { app.setOptions({ drawAssistants: [ - new LinkDraw(app, { - newData: () => { - return new LinkData(); - }, + new LinkDraw(app, () => { + return new LinkData(); + }), + new IscsFanDraw(app, () => { + return new IscsFanData(); }), ], }); + app.addKeyboardListener( new KeyListener({ value: 'KeyL', @@ -61,6 +66,25 @@ export function initDrawApp(app: JlDrawApp) { }, }) ); + app.addKeyboardListener( + new KeyListener({ + value: 'KeyF', + onPress: () => { + app.interactionPlugin(IscsFan.Type).resume(); + }, + }) + ); + app.addKeyboardListener( + new KeyListener({ + value: 'KeyR', + onPress: () => { + app.queryStore.queryByType(IscsFan.Type).forEach((fan) => { + fan._run = !fan._run; + fan.repaint(); + }); + }, + }) + ); app.addKeyboardListener( new KeyListener({ value: 'KeyS', @@ -86,6 +110,9 @@ export function saveDrawDatas(app: JlDrawApp) { if (Link.Type === g.type) { const linkData = (g as Link).saveData(); storage.links.push((linkData as LinkData).data); + } else if (IscsFan.Type === g.type) { + const IscsFanData = (g as IscsFan).saveData(); + storage.iscsFans.push((IscsFanData as IscsFanData).data); } }); const base64 = fromUint8Array(storage.serialize()); @@ -96,6 +123,7 @@ export function saveDrawDatas(app: JlDrawApp) { export function loadDrawDatas(app: GraphicApp) { // localStorage.removeItem(StorageKey); const base64 = localStorage.getItem(StorageKey); + // console.log('加载数据', base64); if (base64) { const storage = graphicData.RtssGraphicStorage.deserialize( toUint8Array(base64) @@ -106,6 +134,9 @@ export function loadDrawDatas(app: GraphicApp) { storage.links.forEach((link) => { datas.push(new LinkData(link)); }); + storage.iscsFans.forEach((fan) => { + datas.push(new IscsFanData(fan)); + }); app.loadGraphic(datas); } } diff --git a/src/examples/app/protos/draw_data_storage.ts b/src/examples/app/protos/draw_data_storage.ts index bb9fc4b..03cac85 100644 --- a/src/examples/app/protos/draw_data_storage.ts +++ b/src/examples/app/protos/draw_data_storage.ts @@ -3,854 +3,733 @@ * compiler version: 4.22.2 * source: draw_data_storage.proto * git: https://github.com/thesayyn/protoc-gen-ts */ -import * as pb_1 from 'google-protobuf'; +import * as pb_1 from "google-protobuf"; export namespace graphicData { - export class RtssGraphicStorage extends pb_1.Message { - #one_of_decls: number[][] = []; - constructor( - data?: - | any[] - | { + export class RtssGraphicStorage extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { canvas?: Canvas; links?: Link[]; - } - ) { - super(); - pb_1.Message.initialize( - this, - Array.isArray(data) ? data : [], - 0, - -1, - [2], - this.#one_of_decls - ); - if (!Array.isArray(data) && typeof data == 'object') { - if ('canvas' in data && data.canvas != undefined) { - this.canvas = data.canvas; + iscsFans?: IscsFan[]; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [2, 3], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("canvas" in data && data.canvas != undefined) { + this.canvas = data.canvas; + } + if ("links" in data && data.links != undefined) { + this.links = data.links; + } + if ("iscsFans" in data && data.iscsFans != undefined) { + this.iscsFans = data.iscsFans; + } + } } - if ('links' in data && data.links != undefined) { - this.links = data.links; + get canvas() { + return pb_1.Message.getWrapperField(this, Canvas, 1) as Canvas; } - } - } - get canvas() { - return pb_1.Message.getWrapperField(this, Canvas, 1) as Canvas; - } - set canvas(value: Canvas) { - pb_1.Message.setWrapperField(this, 1, value); - } - get has_canvas() { - return pb_1.Message.getField(this, 1) != null; - } - get links() { - return pb_1.Message.getRepeatedWrapperField(this, Link, 2) as Link[]; - } - set links(value: Link[]) { - pb_1.Message.setRepeatedWrapperField(this, 2, value); - } - static fromObject(data: { - canvas?: ReturnType; - links?: ReturnType[]; - }): RtssGraphicStorage { - const message = new RtssGraphicStorage({}); - if (data.canvas != null) { - message.canvas = Canvas.fromObject(data.canvas); - } - if (data.links != null) { - message.links = data.links.map((item) => Link.fromObject(item)); - } - return message; - } - toObject() { - const data: { - canvas?: ReturnType; - links?: ReturnType[]; - } = {}; - if (this.canvas != null) { - data.canvas = this.canvas.toObject(); - } - if (this.links != null) { - data.links = this.links.map((item: Link) => item.toObject()); - } - return data; - } - serialize(): Uint8Array; - serialize(w: pb_1.BinaryWriter): void; - serialize(w?: pb_1.BinaryWriter): Uint8Array | void { - const writer = w || new pb_1.BinaryWriter(); - if (this.has_canvas) - writer.writeMessage(1, this.canvas, () => - this.canvas.serialize(writer) - ); - if (this.links.length) - writer.writeRepeatedMessage(2, this.links, (item: Link) => - item.serialize(writer) - ); - if (!w) return writer.getResultBuffer(); - } - static deserialize( - bytes: Uint8Array | pb_1.BinaryReader - ): RtssGraphicStorage { - const reader = - bytes instanceof pb_1.BinaryReader - ? bytes - : new pb_1.BinaryReader(bytes), - message = new RtssGraphicStorage(); - while (reader.nextField()) { - if (reader.isEndGroup()) break; - switch (reader.getFieldNumber()) { - case 1: - reader.readMessage( - message.canvas, - () => (message.canvas = Canvas.deserialize(reader)) - ); - break; - case 2: - reader.readMessage(message.links, () => - pb_1.Message.addToRepeatedWrapperField( - message, - 2, - Link.deserialize(reader), - Link - ) - ); - break; - default: - reader.skipField(); + set canvas(value: Canvas) { + pb_1.Message.setWrapperField(this, 1, value); + } + get has_canvas() { + return pb_1.Message.getField(this, 1) != null; + } + get links() { + return pb_1.Message.getRepeatedWrapperField(this, Link, 2) as Link[]; + } + set links(value: Link[]) { + pb_1.Message.setRepeatedWrapperField(this, 2, value); + } + get iscsFans() { + return pb_1.Message.getRepeatedWrapperField(this, IscsFan, 3) as IscsFan[]; + } + set iscsFans(value: IscsFan[]) { + pb_1.Message.setRepeatedWrapperField(this, 3, value); + } + static fromObject(data: { + canvas?: ReturnType; + links?: ReturnType[]; + iscsFans?: ReturnType[]; + }): RtssGraphicStorage { + const message = new RtssGraphicStorage({}); + if (data.canvas != null) { + message.canvas = Canvas.fromObject(data.canvas); + } + if (data.links != null) { + message.links = data.links.map(item => Link.fromObject(item)); + } + if (data.iscsFans != null) { + message.iscsFans = data.iscsFans.map(item => IscsFan.fromObject(item)); + } + return message; + } + toObject() { + const data: { + canvas?: ReturnType; + links?: ReturnType[]; + iscsFans?: ReturnType[]; + } = {}; + if (this.canvas != null) { + data.canvas = this.canvas.toObject(); + } + if (this.links != null) { + data.links = this.links.map((item: Link) => item.toObject()); + } + if (this.iscsFans != null) { + data.iscsFans = this.iscsFans.map((item: IscsFan) => item.toObject()); + } + return data; + } + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + serialize(w?: pb_1.BinaryWriter): Uint8Array | void { + const writer = w || new pb_1.BinaryWriter(); + if (this.has_canvas) + writer.writeMessage(1, this.canvas, () => this.canvas.serialize(writer)); + if (this.links.length) + writer.writeRepeatedMessage(2, this.links, (item: Link) => item.serialize(writer)); + if (this.iscsFans.length) + writer.writeRepeatedMessage(3, this.iscsFans, (item: IscsFan) => item.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): RtssGraphicStorage { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new RtssGraphicStorage(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.canvas, () => message.canvas = Canvas.deserialize(reader)); + break; + case 2: + reader.readMessage(message.links, () => pb_1.Message.addToRepeatedWrapperField(message, 2, Link.deserialize(reader), Link)); + break; + case 3: + reader.readMessage(message.iscsFans, () => pb_1.Message.addToRepeatedWrapperField(message, 3, IscsFan.deserialize(reader), IscsFan)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): RtssGraphicStorage { + return RtssGraphicStorage.deserialize(bytes); } - } - return message; } - serializeBinary(): Uint8Array { - return this.serialize(); - } - static deserializeBinary(bytes: Uint8Array): RtssGraphicStorage { - return RtssGraphicStorage.deserialize(bytes); - } - } - export class Canvas extends pb_1.Message { - #one_of_decls: number[][] = []; - constructor( - data?: - | any[] - | { + export class Canvas extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { width?: number; height?: number; backgroundColor?: string; viewportTransform?: Transform; - } - ) { - super(); - pb_1.Message.initialize( - this, - Array.isArray(data) ? data : [], - 0, - -1, - [], - this.#one_of_decls - ); - if (!Array.isArray(data) && typeof data == 'object') { - if ('width' in data && data.width != undefined) { - this.width = data.width; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("width" in data && data.width != undefined) { + this.width = data.width; + } + if ("height" in data && data.height != undefined) { + this.height = data.height; + } + if ("backgroundColor" in data && data.backgroundColor != undefined) { + this.backgroundColor = data.backgroundColor; + } + if ("viewportTransform" in data && data.viewportTransform != undefined) { + this.viewportTransform = data.viewportTransform; + } + } } - if ('height' in data && data.height != undefined) { - this.height = data.height; + get width() { + return pb_1.Message.getFieldWithDefault(this, 1, 0) as number; } - if ('backgroundColor' in data && data.backgroundColor != undefined) { - this.backgroundColor = data.backgroundColor; + set width(value: number) { + pb_1.Message.setField(this, 1, value); } - if ( - 'viewportTransform' in data && - data.viewportTransform != undefined - ) { - this.viewportTransform = data.viewportTransform; + get height() { + return pb_1.Message.getFieldWithDefault(this, 2, 0) as number; } - } - } - get width() { - return pb_1.Message.getFieldWithDefault(this, 1, 0) as number; - } - set width(value: number) { - pb_1.Message.setField(this, 1, value); - } - get height() { - return pb_1.Message.getFieldWithDefault(this, 2, 0) as number; - } - set height(value: number) { - pb_1.Message.setField(this, 2, value); - } - get backgroundColor() { - return pb_1.Message.getFieldWithDefault(this, 3, '') as string; - } - set backgroundColor(value: string) { - pb_1.Message.setField(this, 3, value); - } - get viewportTransform() { - return pb_1.Message.getWrapperField(this, Transform, 4) as Transform; - } - set viewportTransform(value: Transform) { - pb_1.Message.setWrapperField(this, 4, value); - } - get has_viewportTransform() { - return pb_1.Message.getField(this, 4) != null; - } - static fromObject(data: { - width?: number; - height?: number; - backgroundColor?: string; - viewportTransform?: ReturnType; - }): Canvas { - const message = new Canvas({}); - if (data.width != null) { - message.width = data.width; - } - if (data.height != null) { - message.height = data.height; - } - if (data.backgroundColor != null) { - message.backgroundColor = data.backgroundColor; - } - if (data.viewportTransform != null) { - message.viewportTransform = Transform.fromObject( - data.viewportTransform - ); - } - return message; - } - toObject() { - const data: { - width?: number; - height?: number; - backgroundColor?: string; - viewportTransform?: ReturnType; - } = {}; - if (this.width != null) { - data.width = this.width; - } - if (this.height != null) { - data.height = this.height; - } - if (this.backgroundColor != null) { - data.backgroundColor = this.backgroundColor; - } - if (this.viewportTransform != null) { - data.viewportTransform = this.viewportTransform.toObject(); - } - return data; - } - serialize(): Uint8Array; - serialize(w: pb_1.BinaryWriter): void; - serialize(w?: pb_1.BinaryWriter): Uint8Array | void { - const writer = w || new pb_1.BinaryWriter(); - if (this.width != 0) writer.writeInt32(1, this.width); - if (this.height != 0) writer.writeInt32(2, this.height); - if (this.backgroundColor.length) - writer.writeString(3, this.backgroundColor); - if (this.has_viewportTransform) - writer.writeMessage(4, this.viewportTransform, () => - this.viewportTransform.serialize(writer) - ); - if (!w) return writer.getResultBuffer(); - } - static deserialize(bytes: Uint8Array | pb_1.BinaryReader): Canvas { - const reader = - bytes instanceof pb_1.BinaryReader - ? bytes - : new pb_1.BinaryReader(bytes), - message = new Canvas(); - while (reader.nextField()) { - if (reader.isEndGroup()) break; - switch (reader.getFieldNumber()) { - case 1: - message.width = reader.readInt32(); - break; - case 2: - message.height = reader.readInt32(); - break; - case 3: - message.backgroundColor = reader.readString(); - break; - case 4: - reader.readMessage( - message.viewportTransform, - () => (message.viewportTransform = Transform.deserialize(reader)) - ); - break; - default: - reader.skipField(); + set height(value: number) { + pb_1.Message.setField(this, 2, value); + } + get backgroundColor() { + return pb_1.Message.getFieldWithDefault(this, 3, "") as string; + } + set backgroundColor(value: string) { + pb_1.Message.setField(this, 3, value); + } + get viewportTransform() { + return pb_1.Message.getWrapperField(this, Transform, 4) as Transform; + } + set viewportTransform(value: Transform) { + pb_1.Message.setWrapperField(this, 4, value); + } + get has_viewportTransform() { + return pb_1.Message.getField(this, 4) != null; + } + static fromObject(data: { + width?: number; + height?: number; + backgroundColor?: string; + viewportTransform?: ReturnType; + }): Canvas { + const message = new Canvas({}); + if (data.width != null) { + message.width = data.width; + } + if (data.height != null) { + message.height = data.height; + } + if (data.backgroundColor != null) { + message.backgroundColor = data.backgroundColor; + } + if (data.viewportTransform != null) { + message.viewportTransform = Transform.fromObject(data.viewportTransform); + } + return message; + } + toObject() { + const data: { + width?: number; + height?: number; + backgroundColor?: string; + viewportTransform?: ReturnType; + } = {}; + if (this.width != null) { + data.width = this.width; + } + if (this.height != null) { + data.height = this.height; + } + if (this.backgroundColor != null) { + data.backgroundColor = this.backgroundColor; + } + if (this.viewportTransform != null) { + data.viewportTransform = this.viewportTransform.toObject(); + } + return data; + } + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + serialize(w?: pb_1.BinaryWriter): Uint8Array | void { + const writer = w || new pb_1.BinaryWriter(); + if (this.width != 0) + writer.writeInt32(1, this.width); + if (this.height != 0) + writer.writeInt32(2, this.height); + if (this.backgroundColor.length) + writer.writeString(3, this.backgroundColor); + if (this.has_viewportTransform) + writer.writeMessage(4, this.viewportTransform, () => this.viewportTransform.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): Canvas { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new Canvas(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + message.width = reader.readInt32(); + break; + case 2: + message.height = reader.readInt32(); + break; + case 3: + message.backgroundColor = reader.readString(); + break; + case 4: + reader.readMessage(message.viewportTransform, () => message.viewportTransform = Transform.deserialize(reader)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): Canvas { + return Canvas.deserialize(bytes); } - } - return message; } - serializeBinary(): Uint8Array { - return this.serialize(); - } - static deserializeBinary(bytes: Uint8Array): Canvas { - return Canvas.deserialize(bytes); - } - } - export class Point extends pb_1.Message { - #one_of_decls: number[][] = []; - constructor( - data?: - | any[] - | { + export class Point extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { x?: number; y?: number; - } - ) { - super(); - pb_1.Message.initialize( - this, - Array.isArray(data) ? data : [], - 0, - -1, - [], - this.#one_of_decls - ); - if (!Array.isArray(data) && typeof data == 'object') { - if ('x' in data && data.x != undefined) { - this.x = data.x; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("x" in data && data.x != undefined) { + this.x = data.x; + } + if ("y" in data && data.y != undefined) { + this.y = data.y; + } + } } - if ('y' in data && data.y != undefined) { - this.y = data.y; + get x() { + return pb_1.Message.getFieldWithDefault(this, 1, 0) as number; } - } - } - get x() { - return pb_1.Message.getFieldWithDefault(this, 1, 0) as number; - } - set x(value: number) { - pb_1.Message.setField(this, 1, value); - } - get y() { - return pb_1.Message.getFieldWithDefault(this, 2, 0) as number; - } - set y(value: number) { - pb_1.Message.setField(this, 2, value); - } - static fromObject(data: { x?: number; y?: number }): Point { - const message = new Point({}); - if (data.x != null) { - message.x = data.x; - } - if (data.y != null) { - message.y = data.y; - } - return message; - } - toObject() { - const data: { - x?: number; - y?: number; - } = {}; - if (this.x != null) { - data.x = this.x; - } - if (this.y != null) { - data.y = this.y; - } - return data; - } - serialize(): Uint8Array; - serialize(w: pb_1.BinaryWriter): void; - serialize(w?: pb_1.BinaryWriter): Uint8Array | void { - const writer = w || new pb_1.BinaryWriter(); - if (this.x != 0) writer.writeFloat(1, this.x); - if (this.y != 0) writer.writeFloat(2, this.y); - if (!w) return writer.getResultBuffer(); - } - static deserialize(bytes: Uint8Array | pb_1.BinaryReader): Point { - const reader = - bytes instanceof pb_1.BinaryReader - ? bytes - : new pb_1.BinaryReader(bytes), - message = new Point(); - while (reader.nextField()) { - if (reader.isEndGroup()) break; - switch (reader.getFieldNumber()) { - case 1: - message.x = reader.readFloat(); - break; - case 2: - message.y = reader.readFloat(); - break; - default: - reader.skipField(); + set x(value: number) { + pb_1.Message.setField(this, 1, value); + } + get y() { + return pb_1.Message.getFieldWithDefault(this, 2, 0) as number; + } + set y(value: number) { + pb_1.Message.setField(this, 2, value); + } + static fromObject(data: { + x?: number; + y?: number; + }): Point { + const message = new Point({}); + if (data.x != null) { + message.x = data.x; + } + if (data.y != null) { + message.y = data.y; + } + return message; + } + toObject() { + const data: { + x?: number; + y?: number; + } = {}; + if (this.x != null) { + data.x = this.x; + } + if (this.y != null) { + data.y = this.y; + } + return data; + } + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + serialize(w?: pb_1.BinaryWriter): Uint8Array | void { + const writer = w || new pb_1.BinaryWriter(); + if (this.x != 0) + writer.writeFloat(1, this.x); + if (this.y != 0) + writer.writeFloat(2, this.y); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): Point { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new Point(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + message.x = reader.readFloat(); + break; + case 2: + message.y = reader.readFloat(); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): Point { + return Point.deserialize(bytes); } - } - return message; } - serializeBinary(): Uint8Array { - return this.serialize(); - } - static deserializeBinary(bytes: Uint8Array): Point { - return Point.deserialize(bytes); - } - } - export class Transform extends pb_1.Message { - #one_of_decls: number[][] = []; - constructor( - data?: - | any[] - | { + export class Transform extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { position?: Point; scale?: Point; rotation?: number; skew?: Point; - } - ) { - super(); - pb_1.Message.initialize( - this, - Array.isArray(data) ? data : [], - 0, - -1, - [], - this.#one_of_decls - ); - if (!Array.isArray(data) && typeof data == 'object') { - if ('position' in data && data.position != undefined) { - this.position = data.position; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("position" in data && data.position != undefined) { + this.position = data.position; + } + if ("scale" in data && data.scale != undefined) { + this.scale = data.scale; + } + if ("rotation" in data && data.rotation != undefined) { + this.rotation = data.rotation; + } + if ("skew" in data && data.skew != undefined) { + this.skew = data.skew; + } + } } - if ('scale' in data && data.scale != undefined) { - this.scale = data.scale; + get position() { + return pb_1.Message.getWrapperField(this, Point, 1) as Point; } - if ('rotation' in data && data.rotation != undefined) { - this.rotation = data.rotation; + set position(value: Point) { + pb_1.Message.setWrapperField(this, 1, value); } - if ('skew' in data && data.skew != undefined) { - this.skew = data.skew; + get has_position() { + return pb_1.Message.getField(this, 1) != null; } - } - } - get position() { - return pb_1.Message.getWrapperField(this, Point, 1) as Point; - } - set position(value: Point) { - pb_1.Message.setWrapperField(this, 1, value); - } - get has_position() { - return pb_1.Message.getField(this, 1) != null; - } - get scale() { - return pb_1.Message.getWrapperField(this, Point, 2) as Point; - } - set scale(value: Point) { - pb_1.Message.setWrapperField(this, 2, value); - } - get has_scale() { - return pb_1.Message.getField(this, 2) != null; - } - get rotation() { - return pb_1.Message.getFieldWithDefault(this, 3, 0) as number; - } - set rotation(value: number) { - pb_1.Message.setField(this, 3, value); - } - get skew() { - return pb_1.Message.getWrapperField(this, Point, 4) as Point; - } - set skew(value: Point) { - pb_1.Message.setWrapperField(this, 4, value); - } - get has_skew() { - return pb_1.Message.getField(this, 4) != null; - } - static fromObject(data: { - position?: ReturnType; - scale?: ReturnType; - rotation?: number; - skew?: ReturnType; - }): Transform { - const message = new Transform({}); - if (data.position != null) { - message.position = Point.fromObject(data.position); - } - if (data.scale != null) { - message.scale = Point.fromObject(data.scale); - } - if (data.rotation != null) { - message.rotation = data.rotation; - } - if (data.skew != null) { - message.skew = Point.fromObject(data.skew); - } - return message; - } - toObject() { - const data: { - position?: ReturnType; - scale?: ReturnType; - rotation?: number; - skew?: ReturnType; - } = {}; - if (this.position != null) { - data.position = this.position.toObject(); - } - if (this.scale != null) { - data.scale = this.scale.toObject(); - } - if (this.rotation != null) { - data.rotation = this.rotation; - } - if (this.skew != null) { - data.skew = this.skew.toObject(); - } - return data; - } - serialize(): Uint8Array; - serialize(w: pb_1.BinaryWriter): void; - serialize(w?: pb_1.BinaryWriter): Uint8Array | void { - const writer = w || new pb_1.BinaryWriter(); - if (this.has_position) - writer.writeMessage(1, this.position, () => - this.position.serialize(writer) - ); - if (this.has_scale) - writer.writeMessage(2, this.scale, () => this.scale.serialize(writer)); - if (this.rotation != 0) writer.writeFloat(3, this.rotation); - if (this.has_skew) - writer.writeMessage(4, this.skew, () => this.skew.serialize(writer)); - if (!w) return writer.getResultBuffer(); - } - static deserialize(bytes: Uint8Array | pb_1.BinaryReader): Transform { - const reader = - bytes instanceof pb_1.BinaryReader - ? bytes - : new pb_1.BinaryReader(bytes), - message = new Transform(); - while (reader.nextField()) { - if (reader.isEndGroup()) break; - switch (reader.getFieldNumber()) { - case 1: - reader.readMessage( - message.position, - () => (message.position = Point.deserialize(reader)) - ); - break; - case 2: - reader.readMessage( - message.scale, - () => (message.scale = Point.deserialize(reader)) - ); - break; - case 3: - message.rotation = reader.readFloat(); - break; - case 4: - reader.readMessage( - message.skew, - () => (message.skew = Point.deserialize(reader)) - ); - break; - default: - reader.skipField(); + get scale() { + return pb_1.Message.getWrapperField(this, Point, 2) as Point; + } + set scale(value: Point) { + pb_1.Message.setWrapperField(this, 2, value); + } + get has_scale() { + return pb_1.Message.getField(this, 2) != null; + } + get rotation() { + return pb_1.Message.getFieldWithDefault(this, 3, 0) as number; + } + set rotation(value: number) { + pb_1.Message.setField(this, 3, value); + } + get skew() { + return pb_1.Message.getWrapperField(this, Point, 4) as Point; + } + set skew(value: Point) { + pb_1.Message.setWrapperField(this, 4, value); + } + get has_skew() { + return pb_1.Message.getField(this, 4) != null; + } + static fromObject(data: { + position?: ReturnType; + scale?: ReturnType; + rotation?: number; + skew?: ReturnType; + }): Transform { + const message = new Transform({}); + if (data.position != null) { + message.position = Point.fromObject(data.position); + } + if (data.scale != null) { + message.scale = Point.fromObject(data.scale); + } + if (data.rotation != null) { + message.rotation = data.rotation; + } + if (data.skew != null) { + message.skew = Point.fromObject(data.skew); + } + return message; + } + toObject() { + const data: { + position?: ReturnType; + scale?: ReturnType; + rotation?: number; + skew?: ReturnType; + } = {}; + if (this.position != null) { + data.position = this.position.toObject(); + } + if (this.scale != null) { + data.scale = this.scale.toObject(); + } + if (this.rotation != null) { + data.rotation = this.rotation; + } + if (this.skew != null) { + data.skew = this.skew.toObject(); + } + return data; + } + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + serialize(w?: pb_1.BinaryWriter): Uint8Array | void { + const writer = w || new pb_1.BinaryWriter(); + if (this.has_position) + writer.writeMessage(1, this.position, () => this.position.serialize(writer)); + if (this.has_scale) + writer.writeMessage(2, this.scale, () => this.scale.serialize(writer)); + if (this.rotation != 0) + writer.writeFloat(3, this.rotation); + if (this.has_skew) + writer.writeMessage(4, this.skew, () => this.skew.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): Transform { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new Transform(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.position, () => message.position = Point.deserialize(reader)); + break; + case 2: + reader.readMessage(message.scale, () => message.scale = Point.deserialize(reader)); + break; + case 3: + message.rotation = reader.readFloat(); + break; + case 4: + reader.readMessage(message.skew, () => message.skew = Point.deserialize(reader)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): Transform { + return Transform.deserialize(bytes); } - } - return message; } - serializeBinary(): Uint8Array { - return this.serialize(); - } - static deserializeBinary(bytes: Uint8Array): Transform { - return Transform.deserialize(bytes); - } - } - export class ChildTransform extends pb_1.Message { - #one_of_decls: number[][] = []; - constructor( - data?: - | any[] - | { + export class ChildTransform extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { name?: string; transform?: Transform; - } - ) { - super(); - pb_1.Message.initialize( - this, - Array.isArray(data) ? data : [], - 0, - -1, - [], - this.#one_of_decls - ); - if (!Array.isArray(data) && typeof data == 'object') { - if ('name' in data && data.name != undefined) { - this.name = data.name; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("name" in data && data.name != undefined) { + this.name = data.name; + } + if ("transform" in data && data.transform != undefined) { + this.transform = data.transform; + } + } } - if ('transform' in data && data.transform != undefined) { - this.transform = data.transform; + get name() { + return pb_1.Message.getFieldWithDefault(this, 1, "") as string; } - } - } - get name() { - return pb_1.Message.getFieldWithDefault(this, 1, '') as string; - } - set name(value: string) { - pb_1.Message.setField(this, 1, value); - } - get transform() { - return pb_1.Message.getWrapperField(this, Transform, 2) as Transform; - } - set transform(value: Transform) { - pb_1.Message.setWrapperField(this, 2, value); - } - get has_transform() { - return pb_1.Message.getField(this, 2) != null; - } - static fromObject(data: { - name?: string; - transform?: ReturnType; - }): ChildTransform { - const message = new ChildTransform({}); - if (data.name != null) { - message.name = data.name; - } - if (data.transform != null) { - message.transform = Transform.fromObject(data.transform); - } - return message; - } - toObject() { - const data: { - name?: string; - transform?: ReturnType; - } = {}; - if (this.name != null) { - data.name = this.name; - } - if (this.transform != null) { - data.transform = this.transform.toObject(); - } - return data; - } - serialize(): Uint8Array; - serialize(w: pb_1.BinaryWriter): void; - serialize(w?: pb_1.BinaryWriter): Uint8Array | void { - const writer = w || new pb_1.BinaryWriter(); - if (this.name.length) writer.writeString(1, this.name); - if (this.has_transform) - writer.writeMessage(2, this.transform, () => - this.transform.serialize(writer) - ); - if (!w) return writer.getResultBuffer(); - } - static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ChildTransform { - const reader = - bytes instanceof pb_1.BinaryReader - ? bytes - : new pb_1.BinaryReader(bytes), - message = new ChildTransform(); - while (reader.nextField()) { - if (reader.isEndGroup()) break; - switch (reader.getFieldNumber()) { - case 1: - message.name = reader.readString(); - break; - case 2: - reader.readMessage( - message.transform, - () => (message.transform = Transform.deserialize(reader)) - ); - break; - default: - reader.skipField(); + set name(value: string) { + pb_1.Message.setField(this, 1, value); + } + get transform() { + return pb_1.Message.getWrapperField(this, Transform, 2) as Transform; + } + set transform(value: Transform) { + pb_1.Message.setWrapperField(this, 2, value); + } + get has_transform() { + return pb_1.Message.getField(this, 2) != null; + } + static fromObject(data: { + name?: string; + transform?: ReturnType; + }): ChildTransform { + const message = new ChildTransform({}); + if (data.name != null) { + message.name = data.name; + } + if (data.transform != null) { + message.transform = Transform.fromObject(data.transform); + } + return message; + } + toObject() { + const data: { + name?: string; + transform?: ReturnType; + } = {}; + if (this.name != null) { + data.name = this.name; + } + if (this.transform != null) { + data.transform = this.transform.toObject(); + } + return data; + } + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + serialize(w?: pb_1.BinaryWriter): Uint8Array | void { + const writer = w || new pb_1.BinaryWriter(); + if (this.name.length) + writer.writeString(1, this.name); + if (this.has_transform) + writer.writeMessage(2, this.transform, () => this.transform.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ChildTransform { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ChildTransform(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + message.name = reader.readString(); + break; + case 2: + reader.readMessage(message.transform, () => message.transform = Transform.deserialize(reader)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): ChildTransform { + return ChildTransform.deserialize(bytes); } - } - return message; } - serializeBinary(): Uint8Array { - return this.serialize(); - } - static deserializeBinary(bytes: Uint8Array): ChildTransform { - return ChildTransform.deserialize(bytes); - } - } - export class CommonInfo extends pb_1.Message { - #one_of_decls: number[][] = []; - constructor( - data?: - | any[] - | { + export class CommonInfo extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { id?: string; graphicType?: string; transform?: Transform; childTransforms?: ChildTransform[]; - } - ) { - super(); - pb_1.Message.initialize( - this, - Array.isArray(data) ? data : [], - 0, - -1, - [4], - this.#one_of_decls - ); - if (!Array.isArray(data) && typeof data == 'object') { - if ('id' in data && data.id != undefined) { - this.id = data.id; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [4], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("id" in data && data.id != undefined) { + this.id = data.id; + } + if ("graphicType" in data && data.graphicType != undefined) { + this.graphicType = data.graphicType; + } + if ("transform" in data && data.transform != undefined) { + this.transform = data.transform; + } + if ("childTransforms" in data && data.childTransforms != undefined) { + this.childTransforms = data.childTransforms; + } + } } - if ('graphicType' in data && data.graphicType != undefined) { - this.graphicType = data.graphicType; + get id() { + return pb_1.Message.getFieldWithDefault(this, 1, "") as string; } - if ('transform' in data && data.transform != undefined) { - this.transform = data.transform; + set id(value: string) { + pb_1.Message.setField(this, 1, value); } - if ('childTransforms' in data && data.childTransforms != undefined) { - this.childTransforms = data.childTransforms; + get graphicType() { + return pb_1.Message.getFieldWithDefault(this, 2, "") as string; } - } - } - get id() { - return pb_1.Message.getFieldWithDefault(this, 1, '') as string; - } - set id(value: string) { - pb_1.Message.setField(this, 1, value); - } - get graphicType() { - return pb_1.Message.getFieldWithDefault(this, 2, '') as string; - } - set graphicType(value: string) { - pb_1.Message.setField(this, 2, value); - } - get transform() { - return pb_1.Message.getWrapperField(this, Transform, 3) as Transform; - } - set transform(value: Transform) { - pb_1.Message.setWrapperField(this, 3, value); - } - get has_transform() { - return pb_1.Message.getField(this, 3) != null; - } - get childTransforms() { - return pb_1.Message.getRepeatedWrapperField( - this, - ChildTransform, - 4 - ) as ChildTransform[]; - } - set childTransforms(value: ChildTransform[]) { - pb_1.Message.setRepeatedWrapperField(this, 4, value); - } - static fromObject(data: { - id?: string; - graphicType?: string; - transform?: ReturnType; - childTransforms?: ReturnType[]; - }): CommonInfo { - const message = new CommonInfo({}); - if (data.id != null) { - message.id = data.id; - } - if (data.graphicType != null) { - message.graphicType = data.graphicType; - } - if (data.transform != null) { - message.transform = Transform.fromObject(data.transform); - } - if (data.childTransforms != null) { - message.childTransforms = data.childTransforms.map((item) => - ChildTransform.fromObject(item) - ); - } - return message; - } - toObject() { - const data: { - id?: string; - graphicType?: string; - transform?: ReturnType; - childTransforms?: ReturnType< - typeof ChildTransform.prototype.toObject - >[]; - } = {}; - if (this.id != null) { - data.id = this.id; - } - if (this.graphicType != null) { - data.graphicType = this.graphicType; - } - if (this.transform != null) { - data.transform = this.transform.toObject(); - } - if (this.childTransforms != null) { - data.childTransforms = this.childTransforms.map( - (item: ChildTransform) => item.toObject() - ); - } - return data; - } - serialize(): Uint8Array; - serialize(w: pb_1.BinaryWriter): void; - serialize(w?: pb_1.BinaryWriter): Uint8Array | void { - const writer = w || new pb_1.BinaryWriter(); - if (this.id.length) writer.writeString(1, this.id); - if (this.graphicType.length) writer.writeString(2, this.graphicType); - if (this.has_transform) - writer.writeMessage(3, this.transform, () => - this.transform.serialize(writer) - ); - if (this.childTransforms.length) - writer.writeRepeatedMessage( - 4, - this.childTransforms, - (item: ChildTransform) => item.serialize(writer) - ); - if (!w) return writer.getResultBuffer(); - } - static deserialize(bytes: Uint8Array | pb_1.BinaryReader): CommonInfo { - const reader = - bytes instanceof pb_1.BinaryReader - ? bytes - : new pb_1.BinaryReader(bytes), - message = new CommonInfo(); - while (reader.nextField()) { - if (reader.isEndGroup()) break; - switch (reader.getFieldNumber()) { - case 1: - message.id = reader.readString(); - break; - case 2: - message.graphicType = reader.readString(); - break; - case 3: - reader.readMessage( - message.transform, - () => (message.transform = Transform.deserialize(reader)) - ); - break; - case 4: - reader.readMessage(message.childTransforms, () => - pb_1.Message.addToRepeatedWrapperField( - message, - 4, - ChildTransform.deserialize(reader), - ChildTransform - ) - ); - break; - default: - reader.skipField(); + set graphicType(value: string) { + pb_1.Message.setField(this, 2, value); + } + get transform() { + return pb_1.Message.getWrapperField(this, Transform, 3) as Transform; + } + set transform(value: Transform) { + pb_1.Message.setWrapperField(this, 3, value); + } + get has_transform() { + return pb_1.Message.getField(this, 3) != null; + } + get childTransforms() { + return pb_1.Message.getRepeatedWrapperField(this, ChildTransform, 4) as ChildTransform[]; + } + set childTransforms(value: ChildTransform[]) { + pb_1.Message.setRepeatedWrapperField(this, 4, value); + } + static fromObject(data: { + id?: string; + graphicType?: string; + transform?: ReturnType; + childTransforms?: ReturnType[]; + }): CommonInfo { + const message = new CommonInfo({}); + if (data.id != null) { + message.id = data.id; + } + if (data.graphicType != null) { + message.graphicType = data.graphicType; + } + if (data.transform != null) { + message.transform = Transform.fromObject(data.transform); + } + if (data.childTransforms != null) { + message.childTransforms = data.childTransforms.map(item => ChildTransform.fromObject(item)); + } + return message; + } + toObject() { + const data: { + id?: string; + graphicType?: string; + transform?: ReturnType; + childTransforms?: ReturnType[]; + } = {}; + if (this.id != null) { + data.id = this.id; + } + if (this.graphicType != null) { + data.graphicType = this.graphicType; + } + if (this.transform != null) { + data.transform = this.transform.toObject(); + } + if (this.childTransforms != null) { + data.childTransforms = this.childTransforms.map((item: ChildTransform) => item.toObject()); + } + return data; + } + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + serialize(w?: pb_1.BinaryWriter): Uint8Array | void { + const writer = w || new pb_1.BinaryWriter(); + if (this.id.length) + writer.writeString(1, this.id); + if (this.graphicType.length) + writer.writeString(2, this.graphicType); + if (this.has_transform) + writer.writeMessage(3, this.transform, () => this.transform.serialize(writer)); + if (this.childTransforms.length) + writer.writeRepeatedMessage(4, this.childTransforms, (item: ChildTransform) => item.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): CommonInfo { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new CommonInfo(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + message.id = reader.readString(); + break; + case 2: + message.graphicType = reader.readString(); + break; + case 3: + reader.readMessage(message.transform, () => message.transform = Transform.deserialize(reader)); + break; + case 4: + reader.readMessage(message.childTransforms, () => pb_1.Message.addToRepeatedWrapperField(message, 4, ChildTransform.deserialize(reader), ChildTransform)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): CommonInfo { + return CommonInfo.deserialize(bytes); } - } - return message; } - serializeBinary(): Uint8Array { - return this.serialize(); - } - static deserializeBinary(bytes: Uint8Array): CommonInfo { - return CommonInfo.deserialize(bytes); - } - } - export class Link extends pb_1.Message { - #one_of_decls: number[][] = []; - constructor( - data?: - | any[] - | { + export class Link extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { common?: CommonInfo; code?: string; curve?: boolean; @@ -858,222 +737,295 @@ export namespace graphicData { lineWidth?: number; lineColor?: string; points?: Point[]; - } - ) { - super(); - pb_1.Message.initialize( - this, - Array.isArray(data) ? data : [], - 0, - -1, - [7], - this.#one_of_decls - ); - if (!Array.isArray(data) && typeof data == 'object') { - if ('common' in data && data.common != undefined) { - this.common = data.common; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [7], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("common" in data && data.common != undefined) { + this.common = data.common; + } + if ("code" in data && data.code != undefined) { + this.code = data.code; + } + if ("curve" in data && data.curve != undefined) { + this.curve = data.curve; + } + if ("segmentsCount" in data && data.segmentsCount != undefined) { + this.segmentsCount = data.segmentsCount; + } + if ("lineWidth" in data && data.lineWidth != undefined) { + this.lineWidth = data.lineWidth; + } + if ("lineColor" in data && data.lineColor != undefined) { + this.lineColor = data.lineColor; + } + if ("points" in data && data.points != undefined) { + this.points = data.points; + } + } } - if ('code' in data && data.code != undefined) { - this.code = data.code; + get common() { + return pb_1.Message.getWrapperField(this, CommonInfo, 1) as CommonInfo; } - if ('curve' in data && data.curve != undefined) { - this.curve = data.curve; + set common(value: CommonInfo) { + pb_1.Message.setWrapperField(this, 1, value); } - if ('segmentsCount' in data && data.segmentsCount != undefined) { - this.segmentsCount = data.segmentsCount; + get has_common() { + return pb_1.Message.getField(this, 1) != null; } - if ('lineWidth' in data && data.lineWidth != undefined) { - this.lineWidth = data.lineWidth; + get code() { + return pb_1.Message.getFieldWithDefault(this, 2, "") as string; } - if ('lineColor' in data && data.lineColor != undefined) { - this.lineColor = data.lineColor; + set code(value: string) { + pb_1.Message.setField(this, 2, value); } - if ('points' in data && data.points != undefined) { - this.points = data.points; + get curve() { + return pb_1.Message.getFieldWithDefault(this, 3, false) as boolean; } - } - } - get common() { - return pb_1.Message.getWrapperField(this, CommonInfo, 1) as CommonInfo; - } - set common(value: CommonInfo) { - pb_1.Message.setWrapperField(this, 1, value); - } - get has_common() { - return pb_1.Message.getField(this, 1) != null; - } - get code() { - return pb_1.Message.getFieldWithDefault(this, 2, '') as string; - } - set code(value: string) { - pb_1.Message.setField(this, 2, value); - } - get curve() { - return pb_1.Message.getFieldWithDefault(this, 3, false) as boolean; - } - set curve(value: boolean) { - pb_1.Message.setField(this, 3, value); - } - get segmentsCount() { - return pb_1.Message.getFieldWithDefault(this, 4, 0) as number; - } - set segmentsCount(value: number) { - pb_1.Message.setField(this, 4, value); - } - get lineWidth() { - return pb_1.Message.getFieldWithDefault(this, 5, 0) as number; - } - set lineWidth(value: number) { - pb_1.Message.setField(this, 5, value); - } - get lineColor() { - return pb_1.Message.getFieldWithDefault(this, 6, '') as string; - } - set lineColor(value: string) { - pb_1.Message.setField(this, 6, value); - } - get points() { - return pb_1.Message.getRepeatedWrapperField(this, Point, 7) as Point[]; - } - set points(value: Point[]) { - pb_1.Message.setRepeatedWrapperField(this, 7, value); - } - static fromObject(data: { - common?: ReturnType; - code?: string; - curve?: boolean; - segmentsCount?: number; - lineWidth?: number; - lineColor?: string; - points?: ReturnType[]; - }): Link { - const message = new Link({}); - if (data.common != null) { - message.common = CommonInfo.fromObject(data.common); - } - if (data.code != null) { - message.code = data.code; - } - if (data.curve != null) { - message.curve = data.curve; - } - if (data.segmentsCount != null) { - message.segmentsCount = data.segmentsCount; - } - if (data.lineWidth != null) { - message.lineWidth = data.lineWidth; - } - if (data.lineColor != null) { - message.lineColor = data.lineColor; - } - if (data.points != null) { - message.points = data.points.map((item) => Point.fromObject(item)); - } - return message; - } - toObject() { - const data: { - common?: ReturnType; - code?: string; - curve?: boolean; - segmentsCount?: number; - lineWidth?: number; - lineColor?: string; - points?: ReturnType[]; - } = {}; - if (this.common != null) { - data.common = this.common.toObject(); - } - if (this.code != null) { - data.code = this.code; - } - if (this.curve != null) { - data.curve = this.curve; - } - if (this.segmentsCount != null) { - data.segmentsCount = this.segmentsCount; - } - if (this.lineWidth != null) { - data.lineWidth = this.lineWidth; - } - if (this.lineColor != null) { - data.lineColor = this.lineColor; - } - if (this.points != null) { - data.points = this.points.map((item: Point) => item.toObject()); - } - return data; - } - serialize(): Uint8Array; - serialize(w: pb_1.BinaryWriter): void; - serialize(w?: pb_1.BinaryWriter): Uint8Array | void { - const writer = w || new pb_1.BinaryWriter(); - if (this.has_common) - writer.writeMessage(1, this.common, () => - this.common.serialize(writer) - ); - if (this.code.length) writer.writeString(2, this.code); - if (this.curve != false) writer.writeBool(3, this.curve); - if (this.segmentsCount != 0) writer.writeInt32(4, this.segmentsCount); - if (this.lineWidth != 0) writer.writeInt32(5, this.lineWidth); - if (this.lineColor.length) writer.writeString(6, this.lineColor); - if (this.points.length) - writer.writeRepeatedMessage(7, this.points, (item: Point) => - item.serialize(writer) - ); - if (!w) return writer.getResultBuffer(); - } - static deserialize(bytes: Uint8Array | pb_1.BinaryReader): Link { - const reader = - bytes instanceof pb_1.BinaryReader - ? bytes - : new pb_1.BinaryReader(bytes), - message = new Link(); - while (reader.nextField()) { - if (reader.isEndGroup()) break; - switch (reader.getFieldNumber()) { - case 1: - reader.readMessage( - message.common, - () => (message.common = CommonInfo.deserialize(reader)) - ); - break; - case 2: - message.code = reader.readString(); - break; - case 3: - message.curve = reader.readBool(); - break; - case 4: - message.segmentsCount = reader.readInt32(); - break; - case 5: - message.lineWidth = reader.readInt32(); - break; - case 6: - message.lineColor = reader.readString(); - break; - case 7: - reader.readMessage(message.points, () => - pb_1.Message.addToRepeatedWrapperField( - message, - 7, - Point.deserialize(reader), - Point - ) - ); - break; - default: - reader.skipField(); + set curve(value: boolean) { + pb_1.Message.setField(this, 3, value); + } + get segmentsCount() { + return pb_1.Message.getFieldWithDefault(this, 4, 0) as number; + } + set segmentsCount(value: number) { + pb_1.Message.setField(this, 4, value); + } + get lineWidth() { + return pb_1.Message.getFieldWithDefault(this, 5, 0) as number; + } + set lineWidth(value: number) { + pb_1.Message.setField(this, 5, value); + } + get lineColor() { + return pb_1.Message.getFieldWithDefault(this, 6, "") as string; + } + set lineColor(value: string) { + pb_1.Message.setField(this, 6, value); + } + get points() { + return pb_1.Message.getRepeatedWrapperField(this, Point, 7) as Point[]; + } + set points(value: Point[]) { + pb_1.Message.setRepeatedWrapperField(this, 7, value); + } + static fromObject(data: { + common?: ReturnType; + code?: string; + curve?: boolean; + segmentsCount?: number; + lineWidth?: number; + lineColor?: string; + points?: ReturnType[]; + }): Link { + const message = new Link({}); + if (data.common != null) { + message.common = CommonInfo.fromObject(data.common); + } + if (data.code != null) { + message.code = data.code; + } + if (data.curve != null) { + message.curve = data.curve; + } + if (data.segmentsCount != null) { + message.segmentsCount = data.segmentsCount; + } + if (data.lineWidth != null) { + message.lineWidth = data.lineWidth; + } + if (data.lineColor != null) { + message.lineColor = data.lineColor; + } + if (data.points != null) { + message.points = data.points.map(item => Point.fromObject(item)); + } + return message; + } + toObject() { + const data: { + common?: ReturnType; + code?: string; + curve?: boolean; + segmentsCount?: number; + lineWidth?: number; + lineColor?: string; + points?: ReturnType[]; + } = {}; + if (this.common != null) { + data.common = this.common.toObject(); + } + if (this.code != null) { + data.code = this.code; + } + if (this.curve != null) { + data.curve = this.curve; + } + if (this.segmentsCount != null) { + data.segmentsCount = this.segmentsCount; + } + if (this.lineWidth != null) { + data.lineWidth = this.lineWidth; + } + if (this.lineColor != null) { + data.lineColor = this.lineColor; + } + if (this.points != null) { + data.points = this.points.map((item: Point) => item.toObject()); + } + return data; + } + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + serialize(w?: pb_1.BinaryWriter): Uint8Array | void { + const writer = w || new pb_1.BinaryWriter(); + if (this.has_common) + writer.writeMessage(1, this.common, () => this.common.serialize(writer)); + if (this.code.length) + writer.writeString(2, this.code); + if (this.curve != false) + writer.writeBool(3, this.curve); + if (this.segmentsCount != 0) + writer.writeInt32(4, this.segmentsCount); + if (this.lineWidth != 0) + writer.writeInt32(5, this.lineWidth); + if (this.lineColor.length) + writer.writeString(6, this.lineColor); + if (this.points.length) + writer.writeRepeatedMessage(7, this.points, (item: Point) => item.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): Link { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new Link(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.common, () => message.common = CommonInfo.deserialize(reader)); + break; + case 2: + message.code = reader.readString(); + break; + case 3: + message.curve = reader.readBool(); + break; + case 4: + message.segmentsCount = reader.readInt32(); + break; + case 5: + message.lineWidth = reader.readInt32(); + break; + case 6: + message.lineColor = reader.readString(); + break; + case 7: + reader.readMessage(message.points, () => pb_1.Message.addToRepeatedWrapperField(message, 7, Point.deserialize(reader), Point)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): Link { + return Link.deserialize(bytes); } - } - return message; } - serializeBinary(): Uint8Array { - return this.serialize(); + export class IscsFan extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { + common?: CommonInfo; + code?: string; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("common" in data && data.common != undefined) { + this.common = data.common; + } + if ("code" in data && data.code != undefined) { + this.code = data.code; + } + } + } + get common() { + return pb_1.Message.getWrapperField(this, CommonInfo, 1) as CommonInfo; + } + set common(value: CommonInfo) { + pb_1.Message.setWrapperField(this, 1, value); + } + get has_common() { + return pb_1.Message.getField(this, 1) != null; + } + get code() { + return pb_1.Message.getFieldWithDefault(this, 2, "") as string; + } + set code(value: string) { + pb_1.Message.setField(this, 2, value); + } + static fromObject(data: { + common?: ReturnType; + code?: string; + }): IscsFan { + const message = new IscsFan({}); + if (data.common != null) { + message.common = CommonInfo.fromObject(data.common); + } + if (data.code != null) { + message.code = data.code; + } + return message; + } + toObject() { + const data: { + common?: ReturnType; + code?: string; + } = {}; + if (this.common != null) { + data.common = this.common.toObject(); + } + if (this.code != null) { + data.code = this.code; + } + return data; + } + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + serialize(w?: pb_1.BinaryWriter): Uint8Array | void { + const writer = w || new pb_1.BinaryWriter(); + if (this.has_common) + writer.writeMessage(1, this.common, () => this.common.serialize(writer)); + if (this.code.length) + writer.writeString(2, this.code); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): IscsFan { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new IscsFan(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.common, () => message.common = CommonInfo.deserialize(reader)); + break; + case 2: + message.code = reader.readString(); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): IscsFan { + return IscsFan.deserialize(bytes); + } } - static deserializeBinary(bytes: Uint8Array): Link { - return Link.deserialize(bytes); - } - } } diff --git a/src/graphics/iscs-fan/IscsFan.ts b/src/graphics/iscs-fan/IscsFan.ts new file mode 100644 index 0000000..e47bb8c --- /dev/null +++ b/src/graphics/iscs-fan/IscsFan.ts @@ -0,0 +1,91 @@ +import { + GraphicAnimation, + GraphicData, + JlGraphic, + JlGraphicTemplate, +} from 'src/jlgraphic'; +import fanBorder from './assets/fan-border.png'; +import fanBlue from './assets/fan-blue.png'; +import fanGray from './assets/fan-gray.png'; +import fanGreen from './assets/fan-green.png'; +import fanRed from './assets/fan-red.png'; +import fanYellow from './assets/fan-yellow.png'; +import { Assets, Sprite, Texture } from 'pixi.js'; + +interface FanTextures { + border: Texture; + blue: Texture; + gray: Texture; + green: Texture; + red: Texture; + yellow: Texture; +} + +export interface IIscsFanData extends GraphicData { + get code(): string; + set code(v: string); +} + +export class IscsFan extends JlGraphic { + static Type = 'IscsFan'; + _border: Sprite; + _fan: Sprite; + fanTextures: FanTextures; + _run = false; + + constructor(fanTextures: FanTextures) { + super(IscsFan.Type); + this.fanTextures = fanTextures; + this._border = new Sprite(); + this._border.texture = this.fanTextures.border; + this._border.anchor.set(0.5); + this._fan = new Sprite(); + this._fan.texture = this.fanTextures.gray; + this._fan.anchor.set(0.5); + this.addChild(this._border); + this.addChild(this._fan); + } + doRepaint(): void { + if (this._run) { + this._fan.texture = this.fanTextures.green; + // 动画 + this.addAnimation( + GraphicAnimation.init({ + name: 'fan_run', + run: (dt: number) => { + this._fan.angle = (this._fan.angle + dt * 3) % 360; + }, + }).resume() + ); + } else { + this.removeAnimation('fan_run'); + this._fan.rotation = 0; + this._fan.texture = this.fanTextures.gray; + } + } +} + +export class IscsFanTemplate extends JlGraphicTemplate { + fanTextures?: FanTextures; + constructor() { + super(IscsFan.Type); + } + new(): IscsFan { + if (this.fanTextures) { + return new IscsFan(this.fanTextures); + } + throw new Error('资源未加载/加载失败'); + } + async loadAssets(): Promise { + Assets.addBundle('iscsFan', { + border: fanBorder, + blue: fanBlue, + gray: fanGray, + green: fanGreen, + red: fanRed, + yellow: fanYellow, + }); + this.fanTextures = await Assets.loadBundle('iscsFan'); + return this.fanTextures as FanTextures; + } +} diff --git a/src/graphics/iscs-fan/IscsFanDrawAssistant.ts b/src/graphics/iscs-fan/IscsFanDrawAssistant.ts new file mode 100644 index 0000000..8f4247e --- /dev/null +++ b/src/graphics/iscs-fan/IscsFanDrawAssistant.ts @@ -0,0 +1,55 @@ +import { FederatedMouseEvent, Point } from 'pixi.js'; +import { + GraphicDrawAssistant, + GraphicTransform, + JlDrawApp, +} from 'src/jlgraphic'; +import { IIscsFanData, IscsFan, IscsFanTemplate } from './IscsFan'; + +export class IscsFanDraw extends GraphicDrawAssistant< + IscsFanTemplate, + IIscsFanData +> { + _iscsFan: IscsFan | null = null; + + constructor(app: JlDrawApp, createData: () => IIscsFanData) { + const template = new IscsFanTemplate(); + super(app, template, createData, IscsFan.Type, ''); + } + + bind(): void { + super.bind(); + if (!this._iscsFan) { + this._iscsFan = this.graphicTemplate.new(); + this.container.addChild(this._iscsFan); + } + } + + public get iscsFan(): IscsFan { + if (!this._iscsFan) { + throw new Error('风机绘制逻辑异常'); + } + return this._iscsFan; + } + + redraw(cp: Point): void { + this.iscsFan.position.copyFrom(cp); + } + onLeftUp(e: FederatedMouseEvent): void { + this.iscsFan.position.copyFrom(this.toCanvasCoordinates(e.global)); + this.createAndStore(false); + } + onRightUp(): void { + this.finish(); + } + prepareData(data: IIscsFanData): boolean { + // 变换设置必须新建变换赋值,不能直接修改变换数据 + const transfrom = GraphicTransform.default(); + transfrom.position = this.iscsFan.position.clone(); + data.transform = transfrom; + return true; + } + onEsc(): void { + this.finish(); + } +} diff --git a/src/graphics/iscs-fan/assets/fan-blue.png b/src/graphics/iscs-fan/assets/fan-blue.png new file mode 100644 index 0000000..31bf36d Binary files /dev/null and b/src/graphics/iscs-fan/assets/fan-blue.png differ diff --git a/src/graphics/iscs-fan/assets/fan-border.png b/src/graphics/iscs-fan/assets/fan-border.png new file mode 100644 index 0000000..6d95a58 Binary files /dev/null and b/src/graphics/iscs-fan/assets/fan-border.png differ diff --git a/src/graphics/iscs-fan/assets/fan-gray.png b/src/graphics/iscs-fan/assets/fan-gray.png new file mode 100644 index 0000000..3677b8c Binary files /dev/null and b/src/graphics/iscs-fan/assets/fan-gray.png differ diff --git a/src/graphics/iscs-fan/assets/fan-green.png b/src/graphics/iscs-fan/assets/fan-green.png new file mode 100644 index 0000000..8f4da74 Binary files /dev/null and b/src/graphics/iscs-fan/assets/fan-green.png differ diff --git a/src/graphics/iscs-fan/assets/fan-red.png b/src/graphics/iscs-fan/assets/fan-red.png new file mode 100644 index 0000000..307d1d0 Binary files /dev/null and b/src/graphics/iscs-fan/assets/fan-red.png differ diff --git a/src/graphics/iscs-fan/assets/fan-yellow.png b/src/graphics/iscs-fan/assets/fan-yellow.png new file mode 100644 index 0000000..668622a Binary files /dev/null and b/src/graphics/iscs-fan/assets/fan-yellow.png differ diff --git a/src/graphics/link/LinkDrawAssistant.ts b/src/graphics/link/LinkDrawAssistant.ts index d7c8fca..b995830 100644 --- a/src/graphics/link/LinkDrawAssistant.ts +++ b/src/graphics/link/LinkDrawAssistant.ts @@ -34,8 +34,7 @@ export interface ILinkDrawOptions { newData: () => ILinkData; } -export class LinkDraw extends GraphicDrawAssistant { - _options: ILinkDrawOptions; +export class LinkDraw extends GraphicDrawAssistant { points: Point[] = []; graphic: Graphics = new Graphics(); @@ -60,18 +59,14 @@ export class LinkDraw extends GraphicDrawAssistant { }, }); - constructor(app: JlDrawApp, options: ILinkDrawOptions) { - super(app, new LinkTemplate(), Link.Type, '轨道Link'); + constructor(app: JlDrawApp, createData: () => ILinkData) { + super(app, new LinkTemplate(), createData, Link.Type, '轨道Link'); this.container.addChild(this.graphic); - this._options = options; this.graphicTemplate.curve = true; new LinkPointsEditPlugin(app); } - newLinkData(): ILinkData { - return this._options.newData(); - } bind(): void { super.bind(); this.app.addKeyboardListener(this.keyqListener, this.keyzListener); @@ -158,28 +153,25 @@ export class LinkDraw extends GraphicDrawAssistant { } } } - prepareData(): ILinkData | null { + prepareData(data: ILinkData): boolean { const template = this.graphicTemplate; if ( (!template.curve && this.points.length < 2) || (template.curve && this.points.length < 4) ) { console.log('Link绘制因点不够取消绘制'); - return null; + return false; } if (template.curve) { this.points.pop(); } - const data = this.newLinkData(); - data.id = this.nextId(); - data.graphicType = Link.Type; data.curve = template.curve; data.segmentsCount = template.segmentsCount; data.points = this.points; data.lineWidth = template.lineWidth; data.lineColor = template.lineColor; data.segmentsCount = template.segmentsCount; - return data; + return true; } } diff --git a/src/graphics/signal/Signal.ts b/src/graphics/signal/Signal.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/jlgraphic/app/JlDrawApp.ts b/src/jlgraphic/app/JlDrawApp.ts index 0d4e9ca..cd481f1 100644 --- a/src/jlgraphic/app/JlDrawApp.ts +++ b/src/jlgraphic/app/JlDrawApp.ts @@ -10,7 +10,7 @@ import { Point, } from 'pixi.js'; import { GraphicIdGenerator } from '../core/IdGenerator'; -import { JlGraphic, GraphicData, GraphicTemplate } from '../core/JlGraphic'; +import { GraphicData, GraphicTemplate, JlGraphic } from '../core/JlGraphic'; import { BoundsGraphic, TransformPoints } from '../graphic'; import { JlOperation } from '../operation/JlOperation'; import { @@ -35,33 +35,40 @@ import { * 图形绘制助手 */ export abstract class GraphicDrawAssistant< - GT extends GraphicTemplate + GT extends GraphicTemplate, + GD extends GraphicData > extends AppInteractionPlugin { - _isDrawAssistant = true; app: JlDrawApp; type: string; // 图形对象类型 description?: string; // 描述 icon: string; // 界面显示的图标 container: Container = new Container(); graphicTemplate: GT; + createGraphicData: () => GD; escListener: KeyListener = new KeyListener({ value: 'Escape', - onPress: () => { - this.createAndStore(true); + onRelease: () => { + this.onEsc(); }, }); + onEsc() { + this.createAndStore(true); + } + constructor( graphicApp: JlDrawApp, graphicTemplate: GT, + createGraphicData: () => GD, icon: string, description?: string ) { super(graphicTemplate.type, graphicApp); this.app = graphicApp; - this.graphicTemplate = graphicTemplate; this.type = graphicTemplate.type; + this.graphicTemplate = graphicTemplate; + this.createGraphicData = createGraphicData; this.icon = icon; this.description = description; this.app.registerGraphicTemplates(this.graphicTemplate); @@ -131,7 +138,7 @@ export abstract class GraphicDrawAssistant< */ abstract redraw(cp: Point): void; - abstract prepareData(): GraphicData | null; + abstract prepareData(data: GD): boolean; toCanvasCoordinates(p: Point): Point { return this.app.toCanvasCoordinates(p); @@ -148,8 +155,10 @@ export abstract class GraphicDrawAssistant< * 创建并添加到图形App */ createAndStore(finish: boolean): JlGraphic | null { - const data = this.prepareData(); - if (!data) { + const data = this.createGraphicData(); + data.id = this.nextId(); + data.graphicType = this.graphicTemplate.type; + if (!this.prepareData(data)) { if (finish) { this.finish(); } @@ -158,7 +167,6 @@ export abstract class GraphicDrawAssistant< const template = this.graphicTemplate; const g = template.new(); g.loadData(data); - g.id = this.nextId(); this.storeGraphic(g); if (finish) { this.finish(g); @@ -183,11 +191,13 @@ export enum DrawAppEvent { propertiesupdate = 'propertiesupdate', // 图形对象数据变更 } +export type DrawAssistant = GraphicDrawAssistant; + export interface IDrawAppOptions { /** * 绘制辅助交互插件 */ - drawAssistants: GraphicDrawAssistant[]; + drawAssistants: DrawAssistant[]; } export type DrawAppOptions = GraphicAppOptions & IDrawAppOptions; @@ -212,7 +222,7 @@ export class JlDrawApp extends GraphicApp { fontName: 'coordinates', }); - drawAssistants: GraphicDrawAssistant[] = []; + drawAssistants: DrawAssistant[] = []; selectedData: GraphicData | ICanvasProperties | null; @@ -244,14 +254,14 @@ export class JlDrawApp extends GraphicApp { }); } - getDrawAssistant(graphicType: string): GraphicDrawAssistant { + getDrawAssistant(graphicType: string): DA { const sda = this.drawAssistants .filter((da) => da.type === graphicType) .pop(); if (!sda) { throw new Error(`未找到图形绘制助手: ${graphicType}`); } - return sda; + return sda as DA; } private appDragRecord() { diff --git a/src/jlgraphic/app/JlGraphicApp.ts b/src/jlgraphic/app/JlGraphicApp.ts index f204913..f3eae80 100644 --- a/src/jlgraphic/app/JlGraphicApp.ts +++ b/src/jlgraphic/app/JlGraphicApp.ts @@ -432,6 +432,16 @@ export class GraphicApp extends EventEmitter { tool.resume(); // 视口移动插件 ViewportMovePlugin.new(this); + + this.app.ticker.add((dt: number) => { + this.queryStore.getAllGraphics().forEach((g) => { + g.animationMap.forEach((animation) => { + if (animation.running) { + animation.run(dt); + } + }); + }); + }); } setOptions(options: GraphicAppOptions) { @@ -458,8 +468,6 @@ export class GraphicApp extends EventEmitter { registerGraphicTemplates(...graphicTemplates: GraphicTemplate[]) { graphicTemplates.forEach((graphicTemplate) => { this.graphicTemplateMap.set(graphicTemplate.type, graphicTemplate); - // 加载资源 - graphicTemplate.loadAsserts(); }); } @@ -597,8 +605,11 @@ export class GraphicApp extends EventEmitter { * @param protos * @param options 添加到可交互/不可交互容器选项配置 */ - loadGraphic(protos: GraphicData[]) { - // console.log('开始加载proto数据', protos); + async loadGraphic(protos: GraphicData[]) { + for (const item of this.graphicTemplateMap) { + await item[1].loadAssets(); + } + console.log('开始加载proto数据', protos); // 加载数据到图形存储 protos.forEach((proto) => { const template = this.getGraphicTemplatesByType(proto.graphicType); diff --git a/src/jlgraphic/core/JlGraphic.ts b/src/jlgraphic/core/JlGraphic.ts index 161cd9c..2050234 100644 --- a/src/jlgraphic/core/JlGraphic.ts +++ b/src/jlgraphic/core/JlGraphic.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-empty-function */ import { Viewport } from 'pixi-viewport'; @@ -451,9 +452,9 @@ export interface GraphicData { copyFrom(data: GraphicData): void; /** * 是否相等 - * @param data + * @param other */ - eq(data: GraphicData): boolean; + eq(other: GraphicData): boolean; } /** @@ -478,6 +479,63 @@ export interface GraphicState { eq(data: GraphicState): boolean; } +export interface GraphicAnimationOptions { + name: string; + /** + * 位移路径 + */ + path?: IPointData[]; + /** + * 是否循环运动(运动到终点后重新从开始运动),与moveToAndFro互斥 + */ + cycleMove?: boolean; + /** + * 是否往复运动(运动到终点后从终点往回运动),与cycleMove互斥 + */ + moveToAndFro?: boolean; + + run?: (dt: number) => void; +} + +export class GraphicAnimation { + options: GraphicAnimationOptions; + _running: boolean; + _finish: boolean; + constructor(options: GraphicAnimationOptions) { + this.options = options; + this._running = false; + this._finish = false; + } + + static init(options: GraphicAnimationOptions) { + return new GraphicAnimation(options); + } + + pause(): GraphicAnimation { + this._running = false; + return this; + } + resume(): GraphicAnimation { + this._running = true; + return this; + } + + public get name(): string { + return this.options.name; + } + + public get running(): boolean { + return this._running; + } + + run(dt: number): GraphicAnimation { + if (this.options.run) { + this.options.run(dt); + } + return this; + } +} + /** * 图形对象基类 */ @@ -488,6 +546,7 @@ export abstract class JlGraphic extends Container { private _code = ''; // 业务编号/名称,用于标识图形对象,具有业务意义 _datas?: GraphicData; // 图形数据 _states?: GraphicState; // 图形状态数据 + animationMap: Map = new Map(); private _relationManage?: RelationManage; // 图形关系管理 private _queryStore?: GraphicQueryStore; // 图形对象查询仓库 @@ -498,6 +557,13 @@ export abstract class JlGraphic extends Container { this.filters; } + addAnimation(animation: GraphicAnimation): void { + this.animationMap.set(animation.name, animation); + } + removeAnimation(name: string): void { + this.animationMap.delete(name); + } + /** * 更新选中状态 * @param selected @@ -803,6 +869,7 @@ export abstract class JlGraphic extends Container { * 处理重绘逻辑 */ abstract doRepaint(): void; + /** * 处理删除逻辑 */ @@ -838,7 +905,7 @@ export abstract class JlGraphicTemplate { /** * 加载图形对象需要用到的资源 */ - loadAsserts(): void {} + async loadAssets(): Promise {} /** * 克隆图形对象 diff --git a/src/jlgraphic/plugins/KeyboardPlugin.ts b/src/jlgraphic/plugins/KeyboardPlugin.ts index afa97d5..309c4af 100644 --- a/src/jlgraphic/plugins/KeyboardPlugin.ts +++ b/src/jlgraphic/plugins/KeyboardPlugin.ts @@ -153,6 +153,7 @@ export class JlGraphicAppKeyboardPlugin { * @param keyListener */ removeKeyListener(keyListener: KeyListener) { + keyListener.onRemove(); const map = this.getOrInit(keyListener.value); const old = map.get(keyListener.identifier); map.delete(keyListener.identifier); @@ -343,4 +344,8 @@ export class KeyListener { } } } + onRemove(): void { + // 重置按下状态 + this.isPress = false; + } } diff --git a/src/jlgraphic/utils/ObjectUtils.ts b/src/jlgraphic/utils/ObjectUtils.ts deleted file mode 100644 index f95c19d..0000000 --- a/src/jlgraphic/utils/ObjectUtils.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * 判定是否代理对象 - * @param obj - * @returns - */ -export function isProxy(obj: any): boolean { - return !!(obj && obj['__Proxy']); -} diff --git a/src/jlgraphic/utils/index.ts b/src/jlgraphic/utils/index.ts index ab051f1..57ec464 100644 --- a/src/jlgraphic/utils/index.ts +++ b/src/jlgraphic/utils/index.ts @@ -2,7 +2,6 @@ import { Point, Rectangle } from 'pixi.js'; export * from './GraphicUtils'; export * from './IntersectUtils'; -export * from './ObjectUtils'; export const UP: Point = new Point(0, -1); export const DOWN: Point = new Point(0, 1);