Change object id into uuid
This commit is contained in:
@@ -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);
|
||||
|
||||
+44
-12
@@ -56,12 +56,6 @@ class Status extends Emitter<IStatusEvent> {
|
||||
|
||||
public setting: Setting = undefined as any;
|
||||
|
||||
/**
|
||||
* 对象命名
|
||||
*/
|
||||
public objectNameIndex = 1;
|
||||
public labelNameIndex = 1;
|
||||
|
||||
/**
|
||||
* 渲染器
|
||||
*/
|
||||
@@ -300,34 +294,72 @@ class Status extends Emitter<IStatusEvent> {
|
||||
*/
|
||||
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();
|
||||
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: this.objectNameIndex.toString()
|
||||
id: nextIndex.toString()
|
||||
});
|
||||
this.objectNameIndex ++;
|
||||
return group;
|
||||
}
|
||||
|
||||
public newRange() {
|
||||
const range = this.model.addRange();
|
||||
range.color = randomColor();
|
||||
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: this.objectNameIndex.toString()
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,9 +36,6 @@ class Archive<
|
||||
*/
|
||||
public save(model: Model): string {
|
||||
let fileData: Record<string, any> = {};
|
||||
|
||||
// 保存 Next ID
|
||||
fileData.idIndex = model.idIndex;
|
||||
|
||||
// 保存对象
|
||||
fileData.objects = [];
|
||||
|
||||
@@ -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<EventType, any> = {}
|
||||
> = new (id: string, parameter: IParameterValue<P>) => Behavior<P, E>;
|
||||
> = new (parameter: IParameterValue<P>) => Behavior<P, E>;
|
||||
|
||||
type IAnyBehavior = Behavior<any, any>;
|
||||
type IAnyBehaviorRecorder = BehaviorRecorder<any, any>;
|
||||
@@ -76,18 +77,6 @@ class BehaviorRecorder<
|
||||
E extends Record<EventType, any> = {}
|
||||
> extends BehaviorInfo<{}> {
|
||||
|
||||
/**
|
||||
* 命名序号
|
||||
*/
|
||||
public nameIndex: number = 0;
|
||||
|
||||
/**
|
||||
* 获取下一个 ID
|
||||
*/
|
||||
public getNextId() {
|
||||
return `B-${this.behaviorId}-${this.nameIndex ++}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 行为类型
|
||||
*/
|
||||
@@ -107,13 +96,13 @@ class BehaviorRecorder<
|
||||
* 创建一个新的行为实例
|
||||
*/
|
||||
public new(): Behavior<P, E> {
|
||||
return new this.behavior(this.getNextId(), getDefaultValue(this.parameterOption));
|
||||
return new this.behavior(getDefaultValue(this.parameterOption));
|
||||
}
|
||||
|
||||
public constructor(behavior: IBehaviorConstructor<P, E>) {
|
||||
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<P> = {} as any;
|
||||
|
||||
public constructor(id: string, parameter: IParameterValue<P>) {
|
||||
public constructor(parameter: IParameterValue<P>) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.id = uuid();
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+8
-27
@@ -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<ModelEvent> {
|
||||
|
||||
/**
|
||||
* 下一个需要分配的 ID
|
||||
*/
|
||||
public idIndex: number = 1;
|
||||
public nextId(label: string = "U"): string {
|
||||
return `${label}-${this.idIndex ++}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象列表
|
||||
*/
|
||||
@@ -75,10 +66,10 @@ class Model extends Emitter<ModelEvent> {
|
||||
* 添加标签
|
||||
*/
|
||||
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<ModelEvent> {
|
||||
* 添加组
|
||||
*/
|
||||
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<ModelEvent> {
|
||||
* 添加范围
|
||||
*/
|
||||
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<ModelEvent> {
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
Individual,
|
||||
Group,
|
||||
Emitter,
|
||||
EventType,
|
||||
EventMixin,
|
||||
Model,
|
||||
CtrlObject,
|
||||
ObjectID,
|
||||
IAnyObject
|
||||
}
|
||||
export { Model, ObjectID, IAnyObject }
|
||||
@@ -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);
|
||||
|
||||
@@ -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<IMixinStatusProps & IMixinSettingProps> {
|
||||
return <DetailsList
|
||||
className="object-list"
|
||||
items={objList.concat([]).map((object => {
|
||||
|
||||
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<IMixinStatusProps & IMixinSettingProps> {
|
||||
this.props.status.setFocusObject(new Set<ObjectID>().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<IMixinStatusProps & IMixinSettingProps> {
|
||||
}}
|
||||
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 <div
|
||||
return <div
|
||||
className="object-list-checkbox details-list-checkbox"
|
||||
onClick={click}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user