Add behavior archive function
This commit is contained in:
parent
068acb19a8
commit
74bda21072
@ -2,6 +2,9 @@ import { Emitter, EventType } from "@Model/Emitter";
|
|||||||
import { IArchiveCtrlObject } from "@Model/CtrlObject";
|
import { IArchiveCtrlObject } from "@Model/CtrlObject";
|
||||||
import { Model } from "@Model/Model";
|
import { Model } from "@Model/Model";
|
||||||
import { IArchiveLabel } from "@Model/Label";
|
import { IArchiveLabel } from "@Model/Label";
|
||||||
|
import { Group, IArchiveGroup } from "@Model/Group";
|
||||||
|
import { IArchiveIndividual } from "@Model/Individual";
|
||||||
|
import { IArchiveBehavior } from "@Model/Behavior";
|
||||||
|
|
||||||
interface IArchiveEvent {
|
interface IArchiveEvent {
|
||||||
fileChange: Archive;
|
fileChange: Archive;
|
||||||
@ -11,6 +14,7 @@ interface IArchiveObject {
|
|||||||
nextIndividualId: number;
|
nextIndividualId: number;
|
||||||
objectPool: IArchiveCtrlObject[];
|
objectPool: IArchiveCtrlObject[];
|
||||||
labelPool: IArchiveLabel[];
|
labelPool: IArchiveLabel[];
|
||||||
|
behaviorPool: IArchiveBehavior[];
|
||||||
}
|
}
|
||||||
|
|
||||||
class Archive<
|
class Archive<
|
||||||
@ -47,19 +51,42 @@ class Archive<
|
|||||||
// 存贮 CtrlObject
|
// 存贮 CtrlObject
|
||||||
const objectPool: IArchiveCtrlObject[] = [];
|
const objectPool: IArchiveCtrlObject[] = [];
|
||||||
model.objectPool.forEach(obj => {
|
model.objectPool.forEach(obj => {
|
||||||
objectPool.push(obj.toArchive());
|
let archiveObject = obj.toArchive();
|
||||||
|
|
||||||
|
// 处理每个群的个体
|
||||||
|
if (archiveObject.objectType === "G") {
|
||||||
|
const archiveGroup: IArchiveGroup = archiveObject as any;
|
||||||
|
const group: Group = obj as Group;
|
||||||
|
|
||||||
|
const individuals: IArchiveIndividual[] = [];
|
||||||
|
group.individuals.forEach((item) => {
|
||||||
|
individuals.push(item.toArchive());
|
||||||
|
});
|
||||||
|
|
||||||
|
archiveGroup.individuals = individuals;
|
||||||
|
}
|
||||||
|
|
||||||
|
objectPool.push(archiveObject);
|
||||||
})
|
})
|
||||||
|
|
||||||
// 存储 Label
|
// 存储 Label
|
||||||
const labelPool: IArchiveLabel[] = [];
|
const labelPool: IArchiveLabel[] = [];
|
||||||
model.labelPool.forEach(obj => {
|
model.labelPool.forEach(obj => {
|
||||||
labelPool.push(obj.toArchive());
|
labelPool.push(obj.toArchive());
|
||||||
})
|
});
|
||||||
|
|
||||||
|
// 存储全部行为
|
||||||
|
const behaviorPool: IArchiveBehavior[] = [];
|
||||||
|
model.behaviorPool.forEach(obj => {
|
||||||
|
behaviorPool.push(obj.toArchive());
|
||||||
|
});
|
||||||
|
|
||||||
|
// 生成存档对象
|
||||||
const fileData: IArchiveObject = {
|
const fileData: IArchiveObject = {
|
||||||
nextIndividualId: model.nextIndividualId,
|
nextIndividualId: model.nextIndividualId,
|
||||||
objectPool: objectPool,
|
objectPool: objectPool,
|
||||||
labelPool: labelPool
|
labelPool: labelPool,
|
||||||
|
behaviorPool: behaviorPool
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(fileData);
|
console.log(fileData);
|
||||||
|
@ -3,7 +3,11 @@ import { v4 as uuid } from "uuid";
|
|||||||
import type { Individual } from "@Model/Individual";
|
import type { Individual } from "@Model/Individual";
|
||||||
import type { Group } from "@Model/Group";
|
import type { Group } from "@Model/Group";
|
||||||
import type { Model } from "@Model/Model";
|
import type { Model } from "@Model/Model";
|
||||||
import { getDefaultValue, IParameter, IParameterOption, IParameterValue } from "@Model/Parameter";
|
import {
|
||||||
|
archiveObject2Parameter,
|
||||||
|
getDefaultValue, IArchiveParameterValue, IArchiveParseFn,
|
||||||
|
IParameter, IParameterOption, IParameterValue, parameter2ArchiveObject
|
||||||
|
} from "@Model/Parameter";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 行为构造函数类型
|
* 行为构造函数类型
|
||||||
@ -113,6 +117,17 @@ class BehaviorRecorder<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IArchiveBehavior {
|
||||||
|
behaviorId: string;
|
||||||
|
name: string;
|
||||||
|
id: string;
|
||||||
|
color: number[];
|
||||||
|
priority: number;
|
||||||
|
currentGroupKey: string[];
|
||||||
|
deleteFlag: boolean;
|
||||||
|
parameter: IArchiveParameterValue<IParameter>;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 群体的某种行为
|
* 群体的某种行为
|
||||||
*/
|
*/
|
||||||
@ -189,6 +204,33 @@ class Behavior<
|
|||||||
return this.deleteFlag;
|
return this.deleteFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public toArchive(): IArchiveBehavior {
|
||||||
|
return {
|
||||||
|
behaviorId: this.behaviorId,
|
||||||
|
name: this.name,
|
||||||
|
id: this.id,
|
||||||
|
color: this.color.concat([]),
|
||||||
|
priority: this.priority,
|
||||||
|
currentGroupKey: this.currentGroupKey.concat([]) as any,
|
||||||
|
deleteFlag: this.deleteFlag,
|
||||||
|
parameter: parameter2ArchiveObject(
|
||||||
|
this.parameter, this.parameterOption
|
||||||
|
)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public fromArchive(archive: IArchiveBehavior, paster: IArchiveParseFn): void {
|
||||||
|
this.name = this.name,
|
||||||
|
this.id = this.id,
|
||||||
|
this.color = this.color.concat([]),
|
||||||
|
this.priority = this.priority,
|
||||||
|
this.currentGroupKey = this.currentGroupKey.concat([]) as any,
|
||||||
|
this.deleteFlag = this.deleteFlag,
|
||||||
|
this.parameter = archiveObject2Parameter(
|
||||||
|
archive.parameter, paster
|
||||||
|
) as any;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加载时调用
|
* 加载时调用
|
||||||
*/
|
*/
|
||||||
@ -241,6 +283,6 @@ class Behavior<
|
|||||||
type IRenderBehavior = BehaviorInfo | Behavior;
|
type IRenderBehavior = BehaviorInfo | Behavior;
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Behavior, BehaviorRecorder, IAnyBehavior, IAnyBehaviorRecorder, BehaviorInfo, IRenderBehavior
|
Behavior, BehaviorRecorder, IAnyBehavior, IAnyBehaviorRecorder,
|
||||||
};
|
BehaviorInfo, IRenderBehavior, IArchiveBehavior
|
||||||
export default { Behavior };
|
};
|
@ -4,16 +4,18 @@ import type { IAnyObject, Model } from "@Model/Model";
|
|||||||
import type { ObjectID } from "@Model/Model";
|
import type { ObjectID } from "@Model/Model";
|
||||||
import {
|
import {
|
||||||
parameter2ArchiveObject, archiveObject2Parameter,
|
parameter2ArchiveObject, archiveObject2Parameter,
|
||||||
IArchiveParseFn, IObjectParamArchiveType, object2ArchiveObject
|
IArchiveParseFn, IObjectParamArchiveType, object2ArchiveObject,
|
||||||
|
IArchiveParameterValue, IParameter
|
||||||
} from "@Model/Parameter";
|
} from "@Model/Parameter";
|
||||||
|
|
||||||
interface IArchiveCtrlObject {
|
interface IArchiveCtrlObject {
|
||||||
|
objectType: "R" | "G";
|
||||||
displayName: CtrlObject["displayName"];
|
displayName: CtrlObject["displayName"];
|
||||||
color: CtrlObject["color"];
|
color: CtrlObject["color"];
|
||||||
display: CtrlObject["display"];
|
display: CtrlObject["display"];
|
||||||
update: CtrlObject["update"];
|
update: CtrlObject["update"];
|
||||||
id: string;
|
id: string;
|
||||||
renderParameter: any;
|
renderParameter: IArchiveParameterValue<IParameter>;
|
||||||
deleteFlag: CtrlObject["deleteFlag"];
|
deleteFlag: CtrlObject["deleteFlag"];
|
||||||
labels: IObjectParamArchiveType[];
|
labels: IObjectParamArchiveType[];
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,11 @@ 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, IArchiveParseFn, IObjectParamArchiveType, object2ArchiveObject } from "@Model/Parameter";
|
import { IArchiveIndividual } from "@Model/Individual";
|
||||||
|
import {
|
||||||
|
getDefaultValue, IArchiveParseFn,
|
||||||
|
IObjectParamArchiveType, object2ArchiveObject
|
||||||
|
} from "@Model/Parameter";
|
||||||
|
|
||||||
enum GenMod {
|
enum GenMod {
|
||||||
Point = "p",
|
Point = "p",
|
||||||
@ -12,6 +16,7 @@ enum GenMod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface IArchiveGroup {
|
interface IArchiveGroup {
|
||||||
|
individuals: IArchiveIndividual[];
|
||||||
genMethod: Group["genMethod"];
|
genMethod: Group["genMethod"];
|
||||||
genPoint: Group["genPoint"];
|
genPoint: Group["genPoint"];
|
||||||
genRange: IObjectParamArchiveType | undefined;
|
genRange: IObjectParamArchiveType | undefined;
|
||||||
@ -421,6 +426,7 @@ class Group extends CtrlObject<IArchiveGroup> {
|
|||||||
public override toArchive(): IArchiveCtrlObject & IArchiveGroup {
|
public override toArchive(): IArchiveCtrlObject & IArchiveGroup {
|
||||||
return {
|
return {
|
||||||
...super.toArchive(),
|
...super.toArchive(),
|
||||||
|
objectType: "G",
|
||||||
genMethod: this.genMethod,
|
genMethod: this.genMethod,
|
||||||
genPoint: this.genPoint.concat([]),
|
genPoint: this.genPoint.concat([]),
|
||||||
genRange: object2ArchiveObject(this.genRange) as IObjectParamArchiveType,
|
genRange: object2ArchiveObject(this.genRange) as IObjectParamArchiveType,
|
||||||
@ -456,4 +462,4 @@ class Group extends CtrlObject<IArchiveGroup> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Group, GenMod };
|
export { Group, GenMod, IArchiveGroup };
|
@ -243,4 +243,4 @@ class Individual {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Individual };
|
export { Individual, IArchiveIndividual };
|
@ -358,5 +358,6 @@ 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, IObjectParamArchiveType, isArchiveObjectType
|
IArchiveParseFn, IObjectParamArchiveType, isArchiveObjectType,
|
||||||
|
IArchiveParameterValue
|
||||||
}
|
}
|
@ -34,6 +34,7 @@ class Range extends CtrlObject<IArchiveRange> {
|
|||||||
public override toArchive(): IArchiveCtrlObject & IArchiveRange {
|
public override toArchive(): IArchiveCtrlObject & IArchiveRange {
|
||||||
return {
|
return {
|
||||||
...super.toArchive(),
|
...super.toArchive(),
|
||||||
|
objectType: "R",
|
||||||
position: this.position.concat([]),
|
position: this.position.concat([]),
|
||||||
radius: this.radius.concat([])
|
radius: this.radius.concat([])
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user