Add ctrl object & range
This commit is contained in:
parent
b10b614113
commit
e15cc0e410
24
source/Model/CtrlObject.ts
Normal file
24
source/Model/CtrlObject.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import { LabelObject } from "./Label"
|
||||||
|
import type { Model } from "./Model";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 可控对象
|
||||||
|
*/
|
||||||
|
class CtrlObject extends LabelObject {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 控制模型
|
||||||
|
*/
|
||||||
|
protected model: Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造器
|
||||||
|
*/
|
||||||
|
public constructor(model: Model) {
|
||||||
|
super();
|
||||||
|
this.model = model;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CtrlObject;
|
||||||
|
export { CtrlObject };
|
@ -1,12 +1,12 @@
|
|||||||
import { Individual } from "./Individual";
|
import { Individual } from "./Individual";
|
||||||
import { LabelObject } from "./Label";
|
import { CtrlObject } from "./CtrlObject";
|
||||||
import type { Behavior } from "./Behavior";
|
import type { Behavior } from "./Behavior";
|
||||||
import type { Model } from "./Model";
|
import type { Model } from "./Model";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 群体类型
|
* 群体类型
|
||||||
*/
|
*/
|
||||||
class Group extends LabelObject {
|
class Group extends CtrlObject {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 所有个体
|
* 所有个体
|
||||||
@ -112,10 +112,10 @@ class Group extends LabelObject {
|
|||||||
* 执行行为影响
|
* 执行行为影响
|
||||||
* @param
|
* @param
|
||||||
*/
|
*/
|
||||||
public runner(model: Model, t: number): void {
|
public runner(t: number): void {
|
||||||
this.individuals.forEach((individual) => {
|
this.individuals.forEach((individual) => {
|
||||||
for(let j = 0; j < this.behaviors.length; j++) {
|
for(let j = 0; j < this.behaviors.length; j++) {
|
||||||
this.behaviors[j].effect(individual, this, model, t);
|
this.behaviors[j].effect(individual, this, this.model, t);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -44,20 +44,20 @@ class LabelObject {
|
|||||||
/**
|
/**
|
||||||
* 标签集合
|
* 标签集合
|
||||||
*/
|
*/
|
||||||
private labels: Set<Label> = new Set();
|
private labels: Label[] = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取全部 Label
|
* 获取全部 Label
|
||||||
*/
|
*/
|
||||||
public allLabels(): Label[] {
|
public allLabels(): Label[] {
|
||||||
return Array.from(this.labels);
|
return this.labels.concat([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加标签
|
* 添加标签
|
||||||
*/
|
*/
|
||||||
public addLabel(label: Label): this {
|
public addLabel(label: Label): this {
|
||||||
this.labels.add(label);
|
this.labels.push(label);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +65,9 @@ class LabelObject {
|
|||||||
* 移除标签
|
* 移除标签
|
||||||
*/
|
*/
|
||||||
public removeLabel(label: Label): this {
|
public removeLabel(label: Label): this {
|
||||||
this.labels.delete(label);
|
this.labels = this.labels.filter((localLabel) => {
|
||||||
|
return !localLabel.equal(label);
|
||||||
|
});
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
source/Model/Range.ts
Normal file
16
source/Model/Range.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { CtrlObject } from "./CtrlObject";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 范围
|
||||||
|
*/
|
||||||
|
class Range extends CtrlObject {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 坐标
|
||||||
|
*/
|
||||||
|
public position: number[] = [];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Range;
|
||||||
|
export { Range };
|
Loading…
Reference in New Issue
Block a user