From c1dde87e300b734793e8434d7d41129681f7ed1f Mon Sep 17 00:00:00 2001 From: MrKBear Date: Fri, 18 Feb 2022 14:14:38 +0800 Subject: [PATCH] Add label modular --- source/Localization/en-US.json | 0 source/Localization/zh-CN.json | 0 source/Model/Behavior.ts | 3 +- source/Model/Group.ts | 5 ++- source/Model/Label.ts | 82 ++++++++++++++++++++++++++++++++++ source/Model/Model.ts | 10 ++++- 6 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 source/Localization/en-US.json create mode 100644 source/Localization/zh-CN.json create mode 100644 source/Model/Label.ts diff --git a/source/Localization/en-US.json b/source/Localization/en-US.json new file mode 100644 index 0000000..e69de29 diff --git a/source/Localization/zh-CN.json b/source/Localization/zh-CN.json new file mode 100644 index 0000000..e69de29 diff --git a/source/Model/Behavior.ts b/source/Model/Behavior.ts index d0186f6..33c7e3b 100644 --- a/source/Model/Behavior.ts +++ b/source/Model/Behavior.ts @@ -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; } diff --git a/source/Model/Group.ts b/source/Model/Group.ts index 386e2c0..39a7e0c 100644 --- a/source/Model/Group.ts +++ b/source/Model/Group.ts @@ -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); } }); } diff --git a/source/Model/Label.ts b/source/Model/Label.ts new file mode 100644 index 0000000..79fac66 --- /dev/null +++ b/source/Model/Label.ts @@ -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