refactor: 规范化代码注释和更新核心模块 - 移除冗余JSDoc注释,统一代码风格

This commit is contained in:
YHH
2025-06-09 13:24:54 +08:00
parent e219fc47ba
commit 4095f1e946
7 changed files with 995 additions and 95 deletions

View File

@@ -1,5 +1,8 @@
import { Component } from './Component';
import { ComponentRegistry, ComponentType } from './Core/ComponentStorage';
import { EventBus } from './Core/EventBus';
import { ECSEventType } from './CoreEvents';
import { IComponentEventData } from '../Types';
/**
* 实体比较器
@@ -192,6 +195,12 @@ export class Entity {
*/
public static entityComparer: EntityComparer = new EntityComparer();
/**
* 全局事件总线实例
* 用于发射组件相关事件
*/
public static eventBus: EventBus | null = null;
/**
* 实体名称
*
@@ -538,6 +547,19 @@ export class Entity {
// 调用组件的生命周期方法
component.onAddedToEntity();
// 发射组件添加事件
if (Entity.eventBus) {
Entity.eventBus.emitComponentAdded({
timestamp: Date.now(),
source: 'Entity',
entityId: this.id,
entityName: this.name,
entityTag: this.tag?.toString(),
componentType: componentType.name,
component: component
});
}
// 通知场景实体已改变
if (this.scene && this.scene.entityProcessors) {
for (const processor of this.scene.entityProcessors.processors) {
@@ -744,6 +766,19 @@ export class Entity {
// 调用组件的生命周期方法
component.onRemovedFromEntity();
// 发射组件移除事件
if (Entity.eventBus) {
Entity.eventBus.emitComponentRemoved({
timestamp: Date.now(),
source: 'Entity',
entityId: this.id,
entityName: this.name,
entityTag: this.tag?.toString(),
componentType: componentType.name,
component: component
});
}
// 清除组件的实体引用
component.entity = null as any;