Add label modular
This commit is contained in:
parent
b9ffe91f8f
commit
c1dde87e30
0
source/Localization/en-US.json
Normal file
0
source/Localization/en-US.json
Normal file
0
source/Localization/zh-CN.json
Normal file
0
source/Localization/zh-CN.json
Normal file
@ -2,6 +2,7 @@ import { IAnyObject } from "./Renderer";
|
||||
import { Emitter, EventType } from "./Emitter";
|
||||
import type { Individual } from "./Individual";
|
||||
import type { Group } from "./Group";
|
||||
import type { Model } from "./Model";
|
||||
|
||||
/**
|
||||
* 群体的某种行为
|
||||
@ -43,7 +44,7 @@ abstract class Behavior<
|
||||
* @param group 影响组
|
||||
* @param t 经过时间
|
||||
*/
|
||||
abstract effect(individual: Individual, group: Group, t: number): void;
|
||||
abstract effect(individual: Individual, group: Group, model: Model, t: number): void;
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { Individual } from "./Individual";
|
||||
import type { Behavior } from "./Behavior";
|
||||
import type { Model } from "./Model";
|
||||
|
||||
/**
|
||||
* 群体类型
|
||||
@ -110,10 +111,10 @@ class Group {
|
||||
* 执行行为影响
|
||||
* @param
|
||||
*/
|
||||
public runner(t: number): void {
|
||||
public runner(model: Model, t: number): void {
|
||||
this.individuals.forEach((individual) => {
|
||||
for(let j = 0; j < this.behaviors.length; j++) {
|
||||
this.behaviors[j].effect(individual, this, t);
|
||||
this.behaviors[j].effect(individual, this, model, t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
82
source/Model/Label.ts
Normal file
82
source/Model/Label.ts
Normal file
@ -0,0 +1,82 @@
|
||||
/**
|
||||
* 数据标签
|
||||
*/
|
||||
class Label {
|
||||
|
||||
/**
|
||||
* 唯一标识符
|
||||
*/
|
||||
public id: string;
|
||||
|
||||
/**
|
||||
* 用户定义的名称
|
||||
*/
|
||||
public name?: string;
|
||||
|
||||
/**
|
||||
* CSS 颜色
|
||||
*/
|
||||
public color?: string;
|
||||
|
||||
/**
|
||||
* 构造器
|
||||
* @param id 标签 ID
|
||||
* @param name 用户定义的名称
|
||||
*/
|
||||
public constructor(id: string, name?: string) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为相同标签
|
||||
*/
|
||||
public equal(label: Label): boolean {
|
||||
return this === label || this.id === label.id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 可以被打标签的数据
|
||||
*/
|
||||
class LabelObject {
|
||||
|
||||
/**
|
||||
* 标签集合
|
||||
*/
|
||||
private labels: Set<Label> = new Set();
|
||||
|
||||
/**
|
||||
* 获取全部 Label
|
||||
*/
|
||||
public allLabels(): Label[] {
|
||||
return Array.from(this.labels);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加标签
|
||||
*/
|
||||
public addLabel(label: Label): this {
|
||||
this.labels.add(label);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除标签
|
||||
*/
|
||||
public removeLabel(label: Label): this {
|
||||
this.labels.delete(label);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否存在标签
|
||||
*/
|
||||
public hasLabel(label: Label): boolean {
|
||||
let has = false;
|
||||
this.labels.forEach((localLabel) => {
|
||||
if (localLabel.equal(label)) has = true;
|
||||
});
|
||||
return has;
|
||||
}
|
||||
}
|
@ -3,10 +3,18 @@ import { Individual } from "./Individual";
|
||||
import { Group } from "./Group";
|
||||
import { Emitter, EventType, EventMixin } from "./Emitter";
|
||||
|
||||
/**
|
||||
* 模型 全局控制器
|
||||
*/
|
||||
class Model extends Emitter<{}> {
|
||||
|
||||
}
|
||||
|
||||
export {
|
||||
Individual,
|
||||
Group,
|
||||
Emitter,
|
||||
EventType,
|
||||
EventMixin
|
||||
EventMixin,
|
||||
Model
|
||||
}
|
Loading…
Reference in New Issue
Block a user