Add group individual label archive function #43

Merged
MrKBear merged 3 commits from dev-mrkbear into master 2022-04-23 16:56:08 +08:00
7 changed files with 45 additions and 13 deletions
Showing only changes of commit d11fd2d328 - Show all commits

View File

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

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 { 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<IArchiveGroup> {
/**
*
@ -417,5 +429,4 @@ class Group extends CtrlObject {
}
}
export default Group;
export { Group, GenMod };

View File

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

View File

@ -78,7 +78,8 @@ class Label {
/**
*
*/
public setBuildInLabel(): this {
public setBuildInLabel(id: string): this {
this.id = id;
this.isBuildIn = true;
return this;
}

View File

@ -29,6 +29,17 @@ type 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 { 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
}