Add ctrl object & range

This commit is contained in:
MrKBear 2022-02-18 16:17:39 +08:00
parent b10b614113
commit e15cc0e410
4 changed files with 50 additions and 8 deletions

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

View File

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

View File

@ -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
View File

@ -0,0 +1,16 @@
import { CtrlObject } from "./CtrlObject";
/**
*
*/
class Range extends CtrlObject {
/**
*
*/
public position: number[] = [];
}
export default Range;
export { Range };