Add group archive function
This commit is contained in:
parent
de0dd57a04
commit
d11fd2d328
@ -1,6 +1,6 @@
|
|||||||
import { Behavior } from "@Model/Behavior";
|
import { Behavior } from "@Model/Behavior";
|
||||||
import Group from "@Model/Group";
|
import { Group } from "@Model/Group";
|
||||||
import Individual from "@Model/Individual";
|
import { Individual } from "@Model/Individual";
|
||||||
import { Model } from "@Model/Model";
|
import { Model } from "@Model/Model";
|
||||||
|
|
||||||
type IPhysicsDynamicsBehaviorParameter = {
|
type IPhysicsDynamicsBehaviorParameter = {
|
||||||
|
@ -47,7 +47,7 @@ class CtrlObject<A extends IAnyObject = IAnyObject> extends LabelObject {
|
|||||||
/**
|
/**
|
||||||
* 控制模型
|
* 控制模型
|
||||||
*/
|
*/
|
||||||
protected model: Model;
|
public model: Model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 渲染数据
|
* 渲染数据
|
||||||
|
@ -4,17 +4,29 @@ import type { Behavior, IAnyBehavior } from "@Model/Behavior";
|
|||||||
import { Label } from "@Model/Label";
|
import { Label } from "@Model/Label";
|
||||||
import { Range } from "@Model/Range";
|
import { Range } from "@Model/Range";
|
||||||
import { Model, ObjectID } from "@Model/Model";
|
import { Model, ObjectID } from "@Model/Model";
|
||||||
import { getDefaultValue } from "@Model/Parameter";
|
import { getDefaultValue, IObjectParamArchiveType } from "@Model/Parameter";
|
||||||
|
|
||||||
enum GenMod {
|
enum GenMod {
|
||||||
Point = "p",
|
Point = "p",
|
||||||
Range = "R"
|
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<IArchiveGroup> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 所有个体
|
* 所有个体
|
||||||
@ -417,5 +429,4 @@ class Group extends CtrlObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Group;
|
|
||||||
export { Group, GenMod };
|
export { Group, GenMod };
|
@ -47,6 +47,8 @@ class Individual {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public id: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 坐标
|
* 坐标
|
||||||
*/
|
*/
|
||||||
@ -95,6 +97,7 @@ class Individual {
|
|||||||
*/
|
*/
|
||||||
public constructor(group: Group) {
|
public constructor(group: Group) {
|
||||||
this.group = group;
|
this.group = group;
|
||||||
|
this.id = this.group.model.getNextIndividualId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public isDie(): boolean {
|
public isDie(): boolean {
|
||||||
@ -169,5 +172,4 @@ class Individual {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Individual;
|
|
||||||
export { Individual };
|
export { Individual };
|
@ -78,7 +78,8 @@ class Label {
|
|||||||
/**
|
/**
|
||||||
* 设置为内置标签
|
* 设置为内置标签
|
||||||
*/
|
*/
|
||||||
public setBuildInLabel(): this {
|
public setBuildInLabel(id: string): this {
|
||||||
|
this.id = id;
|
||||||
this.isBuildIn = true;
|
this.isBuildIn = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,17 @@ type ModelEvent = {
|
|||||||
*/
|
*/
|
||||||
class Model extends Emitter<ModelEvent> {
|
class Model extends Emitter<ModelEvent> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 个体 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<ModelEvent> {
|
|||||||
/**
|
/**
|
||||||
* 内置标签-全部范围标签
|
* 内置标签-全部范围标签
|
||||||
*/
|
*/
|
||||||
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");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加标签
|
* 添加标签
|
||||||
|
@ -2,6 +2,7 @@ import { Group } from "@Model/Group";
|
|||||||
import { Range } from "@Model/Range";
|
import { Range } from "@Model/Range";
|
||||||
import { Label } from "@Model/Label";
|
import { Label } from "@Model/Label";
|
||||||
import { Behavior } from "@Model/Behavior";
|
import { Behavior } from "@Model/Behavior";
|
||||||
|
import { Individual } from "@Model/Individual";
|
||||||
|
|
||||||
type IObjectParamArchiveType = {
|
type IObjectParamArchiveType = {
|
||||||
__LIVING_TOGETHER_OBJECT_ID: string;
|
__LIVING_TOGETHER_OBJECT_ID: string;
|
||||||
@ -229,7 +230,13 @@ type IArchiveParseFn = (archive: IObjectParamArchiveType) => IRealObjectType | u
|
|||||||
|
|
||||||
function object2ArchiveObject(object: IRealObjectType | IRealObjectType[] | any, testArray: boolean = true):
|
function object2ArchiveObject(object: IRealObjectType | IRealObjectType[] | any, testArray: boolean = true):
|
||||||
IObjectParamArchiveType | IObjectParamArchiveType[] | undefined {
|
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 {
|
return {
|
||||||
__LIVING_TOGETHER_OBJECT_ID: "Range",
|
__LIVING_TOGETHER_OBJECT_ID: "Range",
|
||||||
__LIVING_TOGETHER_OBJECT_TYPE: object.id
|
__LIVING_TOGETHER_OBJECT_TYPE: object.id
|
||||||
@ -351,5 +358,5 @@ export {
|
|||||||
IParamType, IParamValue, isObjectType, isVectorType, getDefaultValue,
|
IParamType, IParamValue, isObjectType, isVectorType, getDefaultValue,
|
||||||
IParameterOptionItem, IParameter, IParameterOption, IParameterValue,
|
IParameterOptionItem, IParameter, IParameterOption, IParameterValue,
|
||||||
object2ArchiveObject, parameter2ArchiveObject, archiveObject2Parameter,
|
object2ArchiveObject, parameter2ArchiveObject, archiveObject2Parameter,
|
||||||
IArchiveParseFn
|
IArchiveParseFn, IObjectParamArchiveType
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user