Add tracking target parameter
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user