feat(editor-core): 改进编辑器核心服务

- EntityStoreService 添加调试日志
- AssetRegistryService 优化资产注册
- PluginManager 改进插件管理
- IFileAPI 添加 getFileMtime 接口
This commit is contained in:
yhh
2025-12-16 11:23:50 +08:00
parent b236b729b4
commit 01293590e8
4 changed files with 35 additions and 11 deletions

View File

@@ -3,7 +3,7 @@
* Unified Plugin Manager
*/
import { createLogger, ComponentRegistry } from '@esengine/ecs-framework';
import { createLogger, GlobalComponentRegistry } from '@esengine/ecs-framework';
import type { IScene, ServiceContainer, IService } from '@esengine/ecs-framework';
import type {
ModuleManifest,
@@ -670,9 +670,9 @@ export class PluginManager implements IService {
// 注册组件(使用包装的 Registry 来跟踪)
// Register components (use wrapped registry to track)
if (runtimeModule.registerComponents) {
const componentsBefore = new Set(ComponentRegistry.getRegisteredComponents().map(c => c.name));
runtimeModule.registerComponents(ComponentRegistry);
const componentsAfter = ComponentRegistry.getRegisteredComponents();
const componentsBefore = new Set(GlobalComponentRegistry.getRegisteredComponents().map(c => c.name));
runtimeModule.registerComponents(GlobalComponentRegistry);
const componentsAfter = GlobalComponentRegistry.getRegisteredComponents();
// 跟踪新注册的组件
// Track newly registered components
@@ -779,7 +779,7 @@ export class PluginManager implements IService {
if (resources.componentTypeNames.length > 0) {
for (const componentName of resources.componentTypeNames) {
try {
ComponentRegistry.unregister(componentName);
GlobalComponentRegistry.unregister(componentName);
logger.debug(`Component unregistered: ${componentName}`);
} catch (e) {
logger.error(`Failed to unregister component ${componentName}:`, e);
@@ -900,7 +900,7 @@ export class PluginManager implements IService {
const runtimeModule = plugin.plugin.runtimeModule;
if (runtimeModule?.registerComponents) {
try {
runtimeModule.registerComponents(ComponentRegistry);
runtimeModule.registerComponents(GlobalComponentRegistry);
logger.debug(`Components registered for: ${pluginId}`);
} catch (e) {
logger.error(`Failed to register components for ${pluginId}:`, e);

View File

@@ -394,8 +394,14 @@ export class AssetRegistryService implements IService {
// 处理文件创建 - 注册新资产并生成 .meta
if (changeType === 'create' || changeType === 'modify') {
for (const absolutePath of paths) {
// Skip .meta files
if (absolutePath.endsWith('.meta')) continue;
// Handle .meta file changes - invalidate cache
// 处理 .meta 文件变化 - 使缓存失效
if (absolutePath.endsWith('.meta')) {
const assetPath = absolutePath.slice(0, -5); // Remove '.meta' suffix
this._metaManager.invalidateCache(assetPath);
logger.debug(`Meta file changed, invalidated cache for: ${assetPath}`);
continue;
}
// Only process files in managed directories
// 只处理托管目录中的文件
@@ -406,8 +412,14 @@ export class AssetRegistryService implements IService {
}
} else if (changeType === 'remove') {
for (const absolutePath of paths) {
// Skip .meta files
if (absolutePath.endsWith('.meta')) continue;
// Handle .meta file deletion - invalidate cache
// 处理 .meta 文件删除 - 使缓存失效
if (absolutePath.endsWith('.meta')) {
const assetPath = absolutePath.slice(0, -5);
this._metaManager.invalidateCache(assetPath);
logger.debug(`Meta file removed, invalidated cache for: ${assetPath}`);
continue;
}
// Only process files in managed directories
// 只处理托管目录中的文件

View File

@@ -95,6 +95,9 @@ export class EntityStoreService implements IService {
this.entities.clear();
this.rootEntityIds = [];
// 调试:打印场景实体信息 | Debug: print scene entity info
logger.info(`[syncFromScene] Scene name: ${scene.name}, entities.count: ${scene.entities.count}`);
let entityCount = 0;
scene.entities.forEach((entity) => {
entityCount++;
@@ -106,7 +109,7 @@ export class EntityStoreService implements IService {
}
});
logger.debug(`syncFromScene: synced ${entityCount} entities, ${this.rootEntityIds.length} root entities`);
logger.info(`[syncFromScene] Synced ${entityCount} entities, ${this.rootEntityIds.length} root entities`);
if (this.rootEntityIds.length > 0) {
const rootNames = this.rootEntityIds
.map(id => this.entities.get(id)?.name)

View File

@@ -61,4 +61,13 @@ export interface IFileAPI {
* @returns 路径是否存在
*/
pathExists(path: string): Promise<boolean>;
/**
* 获取文件修改时间
* Get file modification time
*
* @param path 文件路径 | File path
* @returns 文件修改时间(毫秒时间戳)| File modification time (milliseconds timestamp)
*/
getFileMtime?(path: string): Promise<number>;
}