Add group archive function

This commit is contained in:
MrKBear 2022-04-21 23:22:38 +08:00
parent de0dd57a04
commit d11fd2d328
7 changed files with 45 additions and 13 deletions

View File

@ -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 = {

View File

@ -47,7 +47,7 @@ class CtrlObject<A extends IAnyObject = IAnyObject> extends LabelObject {
/** /**
* *
*/ */
protected model: Model; public model: Model;
/** /**
* *

View File

@ -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 };

View File

@ -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 };

View File

@ -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;
} }

View File

@ -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");
/** /**
* *

View File

@ -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
} }