Add tracking target parameter

This commit is contained in:
2022-04-11 17:33:56 +08:00
parent c3d4c13c10
commit 0afb0b6aee
5 changed files with 104 additions and 23 deletions
+2 -2
View File
@@ -61,8 +61,8 @@ class CtrlObject extends LabelObject {
/**
* 判断是否为相同对象
*/
public equal(obj: CtrlObject): boolean {
return this === obj || this.id === obj.id;
public equal(obj?: CtrlObject): boolean {
return this === obj || this.id === obj?.id;
}
/**
+2
View File
@@ -272,9 +272,11 @@ class Group extends CtrlObject {
public remove(individual: Individual[] | Individual): this {
if (Array.isArray(individual)) {
for (let i = 0; i < individual.length; i++) {
individual[i].group = undefined;
this.individuals.delete(individual[i]);
}
} else {
individual.group = undefined;
this.individuals.delete(individual);
}
return this;
+8 -3
View File
@@ -88,7 +88,7 @@ class Individual {
/**
* 所属群组
*/
public group: Group;
public group: Group | undefined;
/**
* 初始化
@@ -97,11 +97,16 @@ class Individual {
this.group = group;
}
public isDie(): boolean {
return !!this.group;
}
/**
* 死亡
*/
public die(): this {
this.group.remove(this);
this.group?.remove(this);
this.group = undefined;
return this;
}
@@ -110,7 +115,7 @@ class Individual {
* @param newGroup 新群体
*/
public transfer(newGroup: Group): this {
this.group.remove(this);
this.group?.remove(this);
newGroup.add(this);
this.group = newGroup;
return this;