diff --git a/source/Behavior/PhysicsDynamics.ts b/source/Behavior/PhysicsDynamics.ts index 994b731..e29ee85 100644 --- a/source/Behavior/PhysicsDynamics.ts +++ b/source/Behavior/PhysicsDynamics.ts @@ -1,6 +1,6 @@ import { Behavior } from "@Model/Behavior"; -import Group from "@Model/Group"; -import Individual from "@Model/Individual"; +import { Group } from "@Model/Group"; +import { Individual } from "@Model/Individual"; import { Model } from "@Model/Model"; type IPhysicsDynamicsBehaviorParameter = { diff --git a/source/Model/CtrlObject.ts b/source/Model/CtrlObject.ts index 8769222..53afb9c 100644 --- a/source/Model/CtrlObject.ts +++ b/source/Model/CtrlObject.ts @@ -47,7 +47,7 @@ class CtrlObject extends LabelObject { /** * 控制模型 */ - protected model: Model; + public model: Model; /** * 渲染数据 diff --git a/source/Model/Group.ts b/source/Model/Group.ts index d16f175..2fe5c5f 100644 --- a/source/Model/Group.ts +++ b/source/Model/Group.ts @@ -4,17 +4,29 @@ import type { Behavior, IAnyBehavior } from "@Model/Behavior"; import { Label } from "@Model/Label"; import { Range } from "@Model/Range"; import { Model, ObjectID } from "@Model/Model"; -import { getDefaultValue } from "@Model/Parameter"; +import { getDefaultValue, IObjectParamArchiveType } from "@Model/Parameter"; enum GenMod { Point = "p", Range = "R" } +interface IArchiveGroup { + individuals: IObjectParamArchiveType[]; + genMethod: Group["genMethod"]; + genPoint: Group["genPoint"]; + genRange: IObjectParamArchiveType | undefined; + genCount: Group["genCount"]; + genErrorMessage: Group["genErrorMessage"]; + genErrorMessageShowCount: Group["genErrorMessageShowCount"]; + killCount: Group["killCount"]; + behaviors: IObjectParamArchiveType[]; +} + /** * 群体类型 */ -class Group extends CtrlObject { +class Group extends CtrlObject { /** * 所有个体 @@ -417,5 +429,4 @@ class Group extends CtrlObject { } } -export default Group; export { Group, GenMod }; \ No newline at end of file diff --git a/source/Model/Individual.ts b/source/Model/Individual.ts index ba41bb9..74e926e 100644 --- a/source/Model/Individual.ts +++ b/source/Model/Individual.ts @@ -47,6 +47,8 @@ class Individual { } } + public id: string; + /** * 坐标 */ @@ -95,6 +97,7 @@ class Individual { */ public constructor(group: Group) { this.group = group; + this.id = this.group.model.getNextIndividualId(); } public isDie(): boolean { @@ -169,5 +172,4 @@ class Individual { } } -export default Individual; export { Individual }; \ No newline at end of file diff --git a/source/Model/Label.ts b/source/Model/Label.ts index 96e10f5..f7ffb39 100644 --- a/source/Model/Label.ts +++ b/source/Model/Label.ts @@ -78,7 +78,8 @@ class Label { /** * 设置为内置标签 */ - public setBuildInLabel(): this { + public setBuildInLabel(id: string): this { + this.id = id; this.isBuildIn = true; return this; } diff --git a/source/Model/Model.ts b/source/Model/Model.ts index c7a0086..1ac2e2a 100644 --- a/source/Model/Model.ts +++ b/source/Model/Model.ts @@ -29,6 +29,17 @@ type ModelEvent = { */ class Model extends Emitter { + /** + * 个体 ID 生成 + */ + public nextIndividualId: number = 0; + + public getNextIndividualId() { + this.nextIndividualId ++; + const random = Math.random().toString(36).slice(-8); + return `${this.nextIndividualId}-${random}`; + } + /** * 对象列表 */ @@ -50,17 +61,17 @@ class Model extends Emitter { /** * 内置标签-全部范围标签 */ - public allRangeLabel = new Label(this, "AllRange").setBuildInLabel(); + public allRangeLabel = new Label(this).setBuildInLabel("AllRange"); /** * 内置标签-全部群标签 */ - public allGroupLabel = new Label(this, "AllGroup").setBuildInLabel(); + public allGroupLabel = new Label(this).setBuildInLabel("AllGroup"); /** * 内置标签-全部群标签 */ - public currentGroupLabel = new Label(this, "CurrentGroupLabel").setBuildInLabel(); + public currentGroupLabel = new Label(this).setBuildInLabel("CurrentGroupLabel"); /** * 添加标签 diff --git a/source/Model/Parameter.ts b/source/Model/Parameter.ts index b77702b..b0353ae 100644 --- a/source/Model/Parameter.ts +++ b/source/Model/Parameter.ts @@ -2,6 +2,7 @@ import { Group } from "@Model/Group"; import { Range } from "@Model/Range"; import { Label } from "@Model/Label"; import { Behavior } from "@Model/Behavior"; +import { Individual } from "@Model/Individual"; type IObjectParamArchiveType = { __LIVING_TOGETHER_OBJECT_ID: string; @@ -229,7 +230,13 @@ type IArchiveParseFn = (archive: IObjectParamArchiveType) => IRealObjectType | u function object2ArchiveObject(object: IRealObjectType | IRealObjectType[] | any, testArray: boolean = true): IObjectParamArchiveType | IObjectParamArchiveType[] | undefined { - if (object instanceof Range) { + if (object instanceof Individual) { + return { + __LIVING_TOGETHER_OBJECT_ID: "Individual", + __LIVING_TOGETHER_OBJECT_TYPE: object.id + } + } + else if (object instanceof Range) { return { __LIVING_TOGETHER_OBJECT_ID: "Range", __LIVING_TOGETHER_OBJECT_TYPE: object.id @@ -351,5 +358,5 @@ export { IParamType, IParamValue, isObjectType, isVectorType, getDefaultValue, IParameterOptionItem, IParameter, IParameterOption, IParameterValue, object2ArchiveObject, parameter2ArchiveObject, archiveObject2Parameter, - IArchiveParseFn + IArchiveParseFn, IObjectParamArchiveType } \ No newline at end of file