From a2b1819dd85174f1cfc90dae879cb790074eac65 Mon Sep 17 00:00:00 2001 From: MrKBear Date: Mon, 18 Apr 2022 17:23:30 +0800 Subject: [PATCH 1/5] Change object id into uuid --- package-lock.json | 92 +++++++++++-------- package.json | 4 +- .../Component/BehaviorPopup/BehaviorPopup.tsx | 22 ++++- source/Context/Status.tsx | 60 +++++++++--- source/Model/Archive.ts | 3 - source/Model/Behavior.ts | 23 ++--- source/Model/CtrlObject.ts | 5 +- source/Model/Group.ts | 4 +- source/Model/Label.ts | 5 +- source/Model/Model.ts | 35 ++----- source/Model/Range.ts | 4 +- source/Panel/ObjectList/ObjectList.tsx | 21 ++++- 12 files changed, 160 insertions(+), 118 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8705181..4288663 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,13 +15,15 @@ "express": "^4.17.3", "gl-matrix": "^3.4.3", "react": "^17.0.2", - "react-dom": "^17.0.2" + "react-dom": "^17.0.2", + "uuid": "^8.3.2" }, "devDependencies": { "@atao60/fse-cli": "^0.1.7", "@types/detect-port": "^1.3.2", "@types/react": "^17.0.38", "@types/react-dom": "^17.0.11", + "@types/uuid": "^8.3.4", "autoprefixer": "^10.4.2", "css-loader": "^6.5.1", "electron": "^18.0.4", @@ -1273,6 +1275,12 @@ "@types/node": "*" } }, + "node_modules/@types/uuid": { + "version": "8.3.4", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz", + "integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==", + "dev": true + }, "node_modules/@types/ws": { "version": "8.5.0", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.0.tgz", @@ -1737,9 +1745,9 @@ } }, "node_modules/async": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz", - "integrity": "sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==", + "version": "2.6.4", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz", + "integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==", "dev": true, "dependencies": { "lodash": "^4.17.14" @@ -5214,9 +5222,9 @@ } }, "node_modules/node-forge": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.2.1.tgz", - "integrity": "sha512-Fcvtbb+zBcZXbTTVwqGA5W+MKBj56UjVRevvchv5XrcyXbmNdesfZL37nlcWOfpgHhgmxApw3tQbTr4CqNmX4w==", + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz", + "integrity": "sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==", "dev": true, "engines": { "node": ">= 6.13.0" @@ -6354,6 +6362,16 @@ "node": ">= 6" } }, + "node_modules/request/node_modules/uuid": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", + "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==", + "deprecated": "Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.", + "dev": true, + "bin": { + "uuid": "bin/uuid" + } + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -6937,15 +6955,6 @@ "websocket-driver": "^0.7.4" } }, - "node_modules/sockjs/node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", - "dev": true, - "bin": { - "uuid": "dist/bin/uuid" - } - }, "node_modules/socks": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/socks/-/socks-2.6.2.tgz", @@ -7628,13 +7637,11 @@ } }, "node_modules/uuid": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", - "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==", - "deprecated": "Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.", - "dev": true, + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", "bin": { - "uuid": "bin/uuid" + "uuid": "dist/bin/uuid" } }, "node_modules/validate-npm-package-license": { @@ -9238,6 +9245,12 @@ "@types/node": "*" } }, + "@types/uuid": { + "version": "8.3.4", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz", + "integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==", + "dev": true + }, "@types/ws": { "version": "8.5.0", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.0.tgz", @@ -9620,9 +9633,9 @@ "dev": true }, "async": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz", - "integrity": "sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==", + "version": "2.6.4", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz", + "integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==", "dev": true, "requires": { "lodash": "^4.17.14" @@ -12326,9 +12339,9 @@ } }, "node-forge": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.2.1.tgz", - "integrity": "sha512-Fcvtbb+zBcZXbTTVwqGA5W+MKBj56UjVRevvchv5XrcyXbmNdesfZL37nlcWOfpgHhgmxApw3tQbTr4CqNmX4w==", + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz", + "integrity": "sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==", "dev": true }, "node-gyp": { @@ -13181,6 +13194,14 @@ "tough-cookie": "~2.5.0", "tunnel-agent": "^0.6.0", "uuid": "^3.3.2" + }, + "dependencies": { + "uuid": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", + "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==", + "dev": true + } } }, "require-directory": { @@ -13619,14 +13640,6 @@ "faye-websocket": "^0.11.3", "uuid": "^8.3.2", "websocket-driver": "^0.7.4" - }, - "dependencies": { - "uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", - "dev": true - } } }, "socks": { @@ -14161,10 +14174,9 @@ "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" }, "uuid": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", - "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==", - "dev": true + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==" }, "validate-npm-package-license": { "version": "3.0.4", diff --git a/package.json b/package.json index 3ba3002..fcb77ec 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "@types/detect-port": "^1.3.2", "@types/react": "^17.0.38", "@types/react-dom": "^17.0.11", + "@types/uuid": "^8.3.4", "autoprefixer": "^10.4.2", "css-loader": "^6.5.1", "electron": "^18.0.4", @@ -72,6 +73,7 @@ "express": "^4.17.3", "gl-matrix": "^3.4.3", "react": "^17.0.2", - "react-dom": "^17.0.2" + "react-dom": "^17.0.2", + "uuid": "^8.3.2" } } diff --git a/source/Component/BehaviorPopup/BehaviorPopup.tsx b/source/Component/BehaviorPopup/BehaviorPopup.tsx index 3ffdd52..017c79f 100644 --- a/source/Component/BehaviorPopup/BehaviorPopup.tsx +++ b/source/Component/BehaviorPopup/BehaviorPopup.tsx @@ -117,10 +117,26 @@ class BehaviorPopupComponent extends Component< if (this.props.status && recorder instanceof BehaviorRecorder) { let newBehavior = this.props.status.model.addBehavior(recorder); - // 初始化名字 - newBehavior.name = recorder.getTerms( + // 根据用户的命名搜索下一个名字 + let searchKey = recorder.getTerms( recorder.behaviorName, this.props.setting?.language - ) + " " + (recorder.nameIndex - 1).toString(); + ); + + let nextIndex = 1; + this.props.status.model.behaviorPool.forEach((obj) => { + if (obj.behaviorId === recorder.behaviorId && obj.name.indexOf(searchKey) >= 0) { + let searchRes = obj.name.match(/(\d+)$/); + if (searchRes) { + let nameNumber = parseInt(searchRes[1]); + if (!isNaN(nameNumber)) { + nextIndex = Math.max(nextIndex, nameNumber + 1); + } + } + } + }); + + // 初始化名字 + newBehavior.name = `${searchKey} ${nextIndex}`; // 赋予一个随机颜色 newBehavior.color = randomColor(true); diff --git a/source/Context/Status.tsx b/source/Context/Status.tsx index 2844a47..bc857ec 100644 --- a/source/Context/Status.tsx +++ b/source/Context/Status.tsx @@ -56,12 +56,6 @@ class Status extends Emitter { public setting: Setting = undefined as any; - /** - * 对象命名 - */ - public objectNameIndex = 1; - public labelNameIndex = 1; - /** * 渲染器 */ @@ -300,34 +294,72 @@ class Status extends Emitter { */ public mouseMod: MouseMod = MouseMod.Drag; + private readonly SEARCH_NAME_KEY_REG = /(\d+)$/; + private getNextNumber(name: string, searchKey: string): number { + if (name.indexOf(searchKey) < 0) return 1; + let searchRes = name.match(this.SEARCH_NAME_KEY_REG); + if (searchRes) { + let nameNumber = parseInt(searchRes[1]); + if (isNaN(nameNumber)) { + return 1; + } else { + return nameNumber + 1; + } + } else { + return 1; + } + } + public newGroup() { const group = this.model.addGroup(); group.color = randomColor(); - group.displayName = I18N(this.setting.language, "Object.List.New.Group", { - id: this.objectNameIndex.toString() + let searchKey = I18N(this.setting.language, "Object.List.New.Group", { id: "" }); + let nextIndex = 1; + this.model.objectPool.forEach((obj) => { + if (obj instanceof Group) { + nextIndex = Math.max(nextIndex, this.getNextNumber( + obj.displayName, searchKey + )); + } + }); + group.displayName = I18N(this.setting.language, "Object.List.New.Group", { + id: nextIndex.toString() }); - this.objectNameIndex ++; return group; } public newRange() { const range = this.model.addRange(); range.color = randomColor(); - range.displayName = I18N(this.setting.language, "Object.List.New.Range", { - id: this.objectNameIndex.toString() + let searchKey = I18N(this.setting.language, "Object.List.New.Range", { id: "" }); + let nextIndex = 1; + this.model.objectPool.forEach((obj) => { + if (obj instanceof Range) { + nextIndex = Math.max(nextIndex, this.getNextNumber( + obj.displayName, searchKey + )); + } + }); + range.displayName = I18N(this.setting.language, "Object.List.New.Range", { + id: nextIndex.toString() }); - this.objectNameIndex ++; return range; } public newLabel() { + let searchKey = I18N(this.setting.language, "Object.List.New.Label", { id: "" }); + let nextIndex = 1; + this.model.labelPool.forEach((obj) => { + nextIndex = Math.max(nextIndex, this.getNextNumber( + obj.name, searchKey + )); + }); const label = this.model.addLabel( I18N(this.setting.language, "Object.List.New.Label", { - id: this.labelNameIndex.toString() + id: nextIndex.toString() }) ); label.color = randomColor(true); - this.labelNameIndex ++; return label; } diff --git a/source/Model/Archive.ts b/source/Model/Archive.ts index 70c6684..b229182 100644 --- a/source/Model/Archive.ts +++ b/source/Model/Archive.ts @@ -36,9 +36,6 @@ class Archive< */ public save(model: Model): string { let fileData: Record = {}; - - // 保存 Next ID - fileData.idIndex = model.idIndex; // 保存对象 fileData.objects = []; diff --git a/source/Model/Behavior.ts b/source/Model/Behavior.ts index 76563ee..7db5f66 100644 --- a/source/Model/Behavior.ts +++ b/source/Model/Behavior.ts @@ -1,4 +1,5 @@ import { Emitter, EventType } from "@Model/Emitter"; +import { v4 as uuid } from "uuid"; import type { Individual } from "@Model/Individual"; import type { Group } from "@Model/Group"; import type { Model } from "@Model/Model"; @@ -10,7 +11,7 @@ import { getDefaultValue, IParameter, IParameterOption, IParameterValue } from " type IBehaviorConstructor< P extends IParameter = {}, E extends Record = {} -> = new (id: string, parameter: IParameterValue

) => Behavior; +> = new (parameter: IParameterValue

) => Behavior; type IAnyBehavior = Behavior; type IAnyBehaviorRecorder = BehaviorRecorder; @@ -76,18 +77,6 @@ class BehaviorRecorder< E extends Record = {} > extends BehaviorInfo<{}> { - /** - * 命名序号 - */ - public nameIndex: number = 0; - - /** - * 获取下一个 ID - */ - public getNextId() { - return `B-${this.behaviorId}-${this.nameIndex ++}`; - } - /** * 行为类型 */ @@ -107,13 +96,13 @@ class BehaviorRecorder< * 创建一个新的行为实例 */ public new(): Behavior { - return new this.behavior(this.getNextId(), getDefaultValue(this.parameterOption)); + return new this.behavior(getDefaultValue(this.parameterOption)); } public constructor(behavior: IBehaviorConstructor) { super(); this.behavior = behavior; - this.behaviorInstance = new this.behavior(this.getNextId(), {} as any); + this.behaviorInstance = new this.behavior({} as any); this.parameterOption = this.behaviorInstance.parameterOption; this.iconName = this.behaviorInstance.iconName; this.behaviorId = this.behaviorInstance.behaviorId; @@ -168,9 +157,9 @@ class Behavior< */ public parameterOption: IParameterOption

= {} as any; - public constructor(id: string, parameter: IParameterValue

) { + public constructor(parameter: IParameterValue

) { super(); - this.id = id; + this.id = uuid(); this.parameter = parameter; } diff --git a/source/Model/CtrlObject.ts b/source/Model/CtrlObject.ts index 19a768f..89913e1 100644 --- a/source/Model/CtrlObject.ts +++ b/source/Model/CtrlObject.ts @@ -1,4 +1,5 @@ import { LabelObject } from "@Model/Label" +import { v4 as uuid } from "uuid"; import type { IAnyObject, Model } from "@Model/Model"; import type { ObjectID } from "@Model/Model"; @@ -45,10 +46,10 @@ class CtrlObject extends LabelObject { /** * 构造器 */ - public constructor(model: Model, id: ObjectID) { + public constructor(model: Model) { super(); this.model = model; - this.id = id; + this.id = uuid(); } /** diff --git a/source/Model/Group.ts b/source/Model/Group.ts index d38e9d5..d16f175 100644 --- a/source/Model/Group.ts +++ b/source/Model/Group.ts @@ -407,9 +407,9 @@ class Group extends CtrlObject { return dataBuffer; } - public constructor(model: Model, id: ObjectID) { + public constructor(model: Model) { - super(model, id); + super(model); if (model.renderer) { this.renderParameter = getDefaultValue(model.renderer.pointsParameterOption); diff --git a/source/Model/Label.ts b/source/Model/Label.ts index cd1f31f..96e10f5 100644 --- a/source/Model/Label.ts +++ b/source/Model/Label.ts @@ -1,4 +1,5 @@ import type { Model, ObjectID } from "@Model/Model"; +import { v4 as uuid } from "uuid"; /** * 数据标签 @@ -35,9 +36,9 @@ class Label { * @param id 标签 ID * @param name 用户定义的名称 */ - public constructor(model: Model, id: ObjectID, name?: string) { + public constructor(model: Model, name?: string) { this.model = model; - this.id = id; + this.id = uuid(); this.name = name ?? this.name; } diff --git a/source/Model/Model.ts b/source/Model/Model.ts index 27b618b..c7a0086 100644 --- a/source/Model/Model.ts +++ b/source/Model/Model.ts @@ -2,9 +2,8 @@ import { Label } from "@Model/Label"; import { Group } from "@Model/Group"; import { Range } from "@Model/Range"; import { IParamValue } from "@Model/Parameter"; -import { Individual } from "@Model/Individual"; import { CtrlObject } from "@Model/CtrlObject"; -import { Emitter, EventType, EventMixin } from "@Model/Emitter"; +import { Emitter } from "@Model/Emitter"; import { AbstractRenderer } from "@Model/Renderer"; import { Behavior, IAnyBehavior, IAnyBehaviorRecorder } from "@Model/Behavior"; @@ -30,14 +29,6 @@ type ModelEvent = { */ class Model extends Emitter { - /** - * 下一个需要分配的 ID - */ - public idIndex: number = 1; - public nextId(label: string = "U"): string { - return `${label}-${this.idIndex ++}`; - } - /** * 对象列表 */ @@ -75,10 +66,10 @@ class Model extends Emitter { * 添加标签 */ public addLabel(name: string): Label { - console.log(`Model: Creat label with id ${this.idIndex}`); - let label = new Label(this, this.nextId("L"), name); + let label = new Label(this, name); this.labelPool.push(label); this.emit("labelChange", this.labelPool); + console.log(`Model: Creat label with id ${label.id}`); return label; } @@ -140,10 +131,10 @@ class Model extends Emitter { * 添加组 */ public addGroup(): Group { - console.log(`Model: Creat group with id ${this.idIndex}`); - let group = new Group(this, this.nextId("G")); + let group = new Group(this); this.objectPool.push(group); this.emit("objectChange", this.objectPool); + console.log(`Model: Creat group with id ${group.id}`); return group; } @@ -151,10 +142,10 @@ class Model extends Emitter { * 添加范围 */ public addRange(): Range { - console.log(`Model: Creat range with id ${this.idIndex}`); - let range = new Range(this, this.nextId("R")); + let range = new Range(this); this.objectPool.push(range); this.emit("objectChange", this.objectPool); + console.log(`Model: Creat range with id ${range.id}`); return range; } @@ -393,14 +384,4 @@ class Model extends Emitter { } } -export { - Individual, - Group, - Emitter, - EventType, - EventMixin, - Model, - CtrlObject, - ObjectID, - IAnyObject -} \ No newline at end of file +export { Model, ObjectID, IAnyObject } \ No newline at end of file diff --git a/source/Model/Range.ts b/source/Model/Range.ts index 197b30c..032b1f0 100644 --- a/source/Model/Range.ts +++ b/source/Model/Range.ts @@ -17,9 +17,9 @@ class Range extends CtrlObject { */ public radius: number[] = [1, 1, 1]; - public constructor(model: Model, id: ObjectID) { + public constructor(model: Model) { - super(model, id); + super(model); if (model.renderer) { this.renderParameter = getDefaultValue(model.renderer.cubeParameterOption); diff --git a/source/Panel/ObjectList/ObjectList.tsx b/source/Panel/ObjectList/ObjectList.tsx index 7961d26..67f75df 100644 --- a/source/Panel/ObjectList/ObjectList.tsx +++ b/source/Panel/ObjectList/ObjectList.tsx @@ -4,6 +4,8 @@ import { useSetting, IMixinSettingProps } from "@Context/Setting"; import { Localization } from "@Component/Localization/Localization"; import { DetailsList } from "@Component/DetailsList/DetailsList"; import { ObjectID } from "@Model/Model"; +import { Group } from "@Model/Group"; +import { Range } from "@Model/Range"; import { Icon } from "@fluentui/react"; import "./ObjectList.scss"; @@ -24,12 +26,21 @@ class ObjectList extends Component { return { + + let objectType = ""; + if (object instanceof Group) { + objectType = "G"; + } else if (object instanceof Range) { + objectType = "R"; + } + return { key: object.id.toString(), name: object.displayName, color: object.color, display: object.display, update: object.update, + type: objectType, select: this.props.status ? this.props.status.focusObject.has(object.id.toString()) || this.props.status.focusObject.has(object.id) : @@ -41,10 +52,10 @@ class ObjectList extends Component { this.props.status.setFocusObject(new Set().add(item.key)); } if (this.props.setting) { - if (item.key.slice(0, 1) === "R") { + if (item.type === "R") { this.props.setting.layout.focus("RangeDetails"); } - if (item.key.slice(0, 1) === "G") { + else if (item.type === "G") { this.props.setting.layout.focus("GroupDetails"); } this.props.setting.layout.focus("ObjectList"); @@ -71,13 +82,13 @@ class ObjectList extends Component { }} renderCheckbox={(item, click) => { let icon = "CheckMark"; - if (item.key.slice(0, 1) === "R") { + if (item.type === "R") { icon = "CubeShape"; } - if (item.key.slice(0, 1) === "G") { + else if (item.type === "G") { icon = "WebAppBuilderFragment"; } - return

-- 2.45.2 From 21960778f52af3f670494df99f8a8d93fd206307 Mon Sep 17 00:00:00 2001 From: MrKBear Date: Wed, 20 Apr 2022 23:23:51 +0800 Subject: [PATCH 2/5] Add parameter archive func --- source/Model/CtrlObject.ts | 21 ++++- source/Model/Parameter.ts | 175 ++++++++++++++++++++++++++++++++++--- 2 files changed, 184 insertions(+), 12 deletions(-) diff --git a/source/Model/CtrlObject.ts b/source/Model/CtrlObject.ts index 89913e1..613355c 100644 --- a/source/Model/CtrlObject.ts +++ b/source/Model/CtrlObject.ts @@ -3,6 +3,16 @@ import { v4 as uuid } from "uuid"; import type { IAnyObject, Model } from "@Model/Model"; import type { ObjectID } from "@Model/Model"; +interface IArchiveCtrlObject { + displayName: CtrlObject["displayName"]; + color: CtrlObject["color"]; + display: CtrlObject["display"]; + update: CtrlObject["update"]; + id: string; + renderParameter: Record; + deleteFlag: CtrlObject["deleteFlag"]; +} + /** * 可控对象 */ @@ -97,7 +107,14 @@ class CtrlObject extends LabelObject { public isDeleted(): boolean { return this.deleteFlag; } + + public toArchive(): IArchiveCtrlObject { + return {} as any; + } + + public fromArchive(archive: IArchiveCtrlObject): void { + + } } -export default CtrlObject; -export { CtrlObject }; \ No newline at end of file +export { CtrlObject, IArchiveCtrlObject }; \ No newline at end of file diff --git a/source/Model/Parameter.ts b/source/Model/Parameter.ts index a40eb8b..06a4683 100644 --- a/source/Model/Parameter.ts +++ b/source/Model/Parameter.ts @@ -1,6 +1,12 @@ -import type { Group } from "@Model/Group"; -import type { Range } from "@Model/Range"; -import type { Label } from "@Model/Label"; +import { Group } from "@Model/Group"; +import { Range } from "@Model/Range"; +import { Label } from "@Model/Label"; +import { Behavior } from "@Model/Behavior"; + +type IObjectParamArchiveType = { + __LIVING_TOGETHER_OBJECT_ID: string; + __LIVING_TOGETHER_OBJECT_TYPE: string; +} type IObjectParamCacheType = { picker: P; @@ -26,6 +32,15 @@ type IMapObjectParamTypeKeyToType = { "CLG": IObjectParamCacheType