Feature/editor optimization (#251)
* refactor: 编辑器/运行时架构拆分与构建系统升级 * feat(core): 层级系统重构与UI变换矩阵修复 * refactor: 移除 ecs-components 聚合包并修复跨包组件查找问题 * fix(physics): 修复跨包组件类引用问题 * feat: 统一运行时架构与浏览器运行支持 * feat(asset): 实现浏览器运行时资产加载系统 * fix: 修复文档、CodeQL安全问题和CI类型检查错误 * fix: 修复文档、CodeQL安全问题和CI类型检查错误 * fix: 修复文档、CodeQL安全问题、CI类型检查和测试错误 * test: 补齐核心模块测试用例,修复CI构建配置 * fix: 修复测试用例中的类型错误和断言问题 * fix: 修复 turbo build:npm 任务的依赖顺序问题 * fix: 修复 CI 构建错误并优化构建性能
This commit is contained in:
@@ -33,15 +33,15 @@
|
||||
"build:watch": "tsc --watch",
|
||||
"rebuild": "npm run clean && npm run build",
|
||||
"build:npm": "npm run build && node build-rollup.cjs",
|
||||
"test": "jest --config jest.config.cjs",
|
||||
"test:watch": "jest --watch --config jest.config.cjs",
|
||||
"test:coverage": "jest --coverage --config jest.config.cjs",
|
||||
"lint": "eslint \"src/**/*.{ts,tsx}\"",
|
||||
"lint:fix": "eslint \"src/**/*.{ts,tsx}\" --fix"
|
||||
},
|
||||
"author": "yhh",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@esengine/ecs-framework": "workspace:*",
|
||||
"@esengine/asset-system": "workspace:*",
|
||||
"@esengine/engine-core": "workspace:*",
|
||||
"@babel/core": "^7.28.3",
|
||||
"@babel/plugin-transform-nullish-coalescing-operator": "^7.27.1",
|
||||
"@babel/plugin-transform-optional-chaining": "^7.27.1",
|
||||
@@ -61,11 +61,7 @@
|
||||
"rollup": "^4.42.0",
|
||||
"rollup-plugin-dts": "^6.2.1",
|
||||
"ts-jest": "^29.4.0",
|
||||
"typescript": "^5.8.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@esengine/asset-system": "*",
|
||||
"@esengine/ecs-framework": "^2.2.8",
|
||||
"typescript": "^5.8.3",
|
||||
"react": "^18.2.0",
|
||||
"rxjs": "^7.8.0",
|
||||
"tsyringe": "^4.8.0"
|
||||
|
||||
@@ -15,7 +15,13 @@ const banner = `/**
|
||||
* @license ${pkg.license}
|
||||
*/`;
|
||||
|
||||
const external = ['@esengine/ecs-framework'];
|
||||
const external = [
|
||||
'@esengine/ecs-framework',
|
||||
'react',
|
||||
'react-dom',
|
||||
'react/jsx-runtime',
|
||||
/^@types\//
|
||||
];
|
||||
|
||||
const commonPlugins = [
|
||||
resolve({
|
||||
|
||||
@@ -1,71 +1,29 @@
|
||||
/**
|
||||
* 插件加载器接口
|
||||
* Plugin loader interfaces
|
||||
* 编辑器模块接口
|
||||
* Editor module interfaces
|
||||
*
|
||||
* 定义编辑器专用的模块接口和 UI 描述符类型。
|
||||
* Define editor-specific module interfaces and UI descriptor types.
|
||||
*/
|
||||
|
||||
import type { IScene, ServiceContainer, ComponentRegistry } from '@esengine/ecs-framework';
|
||||
import type { PluginDescriptor } from './PluginDescriptor';
|
||||
import type { ServiceContainer } from '@esengine/ecs-framework';
|
||||
|
||||
/**
|
||||
* 系统创建上下文
|
||||
* System creation context
|
||||
*/
|
||||
export interface SystemContext {
|
||||
/** 是否为编辑器模式 | Is editor mode */
|
||||
isEditor: boolean;
|
||||
// 从 PluginDescriptor 重新导出(来源于 engine-core)
|
||||
export type {
|
||||
PluginCategory,
|
||||
LoadingPhase,
|
||||
ModuleType,
|
||||
ModuleDescriptor,
|
||||
PluginDependency,
|
||||
PluginDescriptor,
|
||||
SystemContext,
|
||||
IRuntimeModule,
|
||||
IPlugin
|
||||
} from './PluginDescriptor';
|
||||
|
||||
/** 引擎桥接(如有) | Engine bridge (if available) */
|
||||
engineBridge?: any;
|
||||
|
||||
/** 渲染系统(如有) | Render system (if available) */
|
||||
renderSystem?: any;
|
||||
|
||||
/** 其他已创建的系统引用 | Other created system references */
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* 运行时模块加载器
|
||||
* Runtime module loader
|
||||
*/
|
||||
export interface IRuntimeModuleLoader {
|
||||
/**
|
||||
* 注册组件到 ComponentRegistry
|
||||
* Register components to ComponentRegistry
|
||||
*/
|
||||
registerComponents(registry: typeof ComponentRegistry): void;
|
||||
|
||||
/**
|
||||
* 注册服务到 ServiceContainer
|
||||
* Register services to ServiceContainer
|
||||
*/
|
||||
registerServices?(services: ServiceContainer): void;
|
||||
|
||||
/**
|
||||
* 为场景创建系统
|
||||
* Create systems for scene
|
||||
*/
|
||||
createSystems?(scene: IScene, context: SystemContext): void;
|
||||
|
||||
/**
|
||||
* 所有系统创建完成后调用
|
||||
* 用于处理跨插件的系统依赖关系
|
||||
* Called after all systems are created, used for cross-plugin system dependencies
|
||||
*/
|
||||
onSystemsCreated?(scene: IScene, context: SystemContext): void;
|
||||
|
||||
/**
|
||||
* 模块初始化完成回调
|
||||
* Module initialization complete callback
|
||||
*/
|
||||
onInitialize?(): Promise<void>;
|
||||
|
||||
/**
|
||||
* 模块销毁回调
|
||||
* Module destroy callback
|
||||
*/
|
||||
onDestroy?(): void;
|
||||
}
|
||||
// ============================================================================
|
||||
// UI 描述符类型 | UI Descriptor Types
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 面板位置
|
||||
@@ -146,8 +104,8 @@ export interface ToolbarItemDescriptor {
|
||||
}
|
||||
|
||||
/**
|
||||
* 组件检视器提供者(简化版)
|
||||
* Component inspector provider (simplified)
|
||||
* 组件检视器提供者
|
||||
* Component inspector provider
|
||||
*/
|
||||
export interface ComponentInspectorProviderDef {
|
||||
/** 组件类型名 | Component type name */
|
||||
@@ -235,6 +193,33 @@ export interface ISerializer<T = any> {
|
||||
deserialize(data: Uint8Array): T;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件创建模板
|
||||
* File creation template
|
||||
*/
|
||||
export interface FileCreationTemplate {
|
||||
/** 模板ID | Template ID */
|
||||
id: string;
|
||||
/** 标签 | Label */
|
||||
label: string;
|
||||
/** 扩展名 | Extension */
|
||||
extension: string;
|
||||
/** 图标 | Icon */
|
||||
icon?: string;
|
||||
/** 分类 | Category */
|
||||
category?: string;
|
||||
/**
|
||||
* 获取文件内容 | Get file content
|
||||
* @param fileName 文件名(不含路径,含扩展名)
|
||||
* @returns 文件内容字符串
|
||||
*/
|
||||
getContent: (fileName: string) => string | Promise<string>;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 编辑器模块接口 | Editor Module Interface
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 编辑器模块加载器
|
||||
* Editor module loader
|
||||
@@ -327,43 +312,22 @@ export interface IEditorModuleLoader {
|
||||
setLocale?(locale: string): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一插件加载器
|
||||
* Unified plugin loader
|
||||
*/
|
||||
export interface IPluginLoader {
|
||||
/** 插件描述符 | Plugin descriptor */
|
||||
readonly descriptor: PluginDescriptor;
|
||||
|
||||
/** 运行时模块(可选) | Runtime module (optional) */
|
||||
readonly runtimeModule?: IRuntimeModuleLoader;
|
||||
|
||||
/** 编辑器模块(可选) | Editor module (optional) */
|
||||
readonly editorModule?: IEditorModuleLoader;
|
||||
}
|
||||
// ============================================================================
|
||||
// 类型别名(向后兼容)| Type Aliases (backward compatibility)
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 文件创建模板
|
||||
* File creation template
|
||||
* IPluginLoader 类型别名
|
||||
*
|
||||
* 插件通过 getContent 提供文件内容,编辑器负责写入文件。
|
||||
* 这样可以避免插件直接访问文件系统带来的权限问题。
|
||||
* @deprecated 使用 IPlugin 代替。IPluginLoader 只是 IPlugin 的别名。
|
||||
* @deprecated Use IPlugin instead. IPluginLoader is just an alias for IPlugin.
|
||||
*/
|
||||
export interface FileCreationTemplate {
|
||||
/** 模板ID | Template ID */
|
||||
id: string;
|
||||
/** 标签 | Label */
|
||||
label: string;
|
||||
/** 扩展名 | Extension */
|
||||
extension: string;
|
||||
/** 图标 | Icon */
|
||||
icon?: string;
|
||||
/** 分类 | Category */
|
||||
category?: string;
|
||||
/**
|
||||
* 获取文件内容 | Get file content
|
||||
* @param fileName 文件名(不含路径,含扩展名)
|
||||
* @returns 文件内容字符串
|
||||
*/
|
||||
getContent: (fileName: string) => string | Promise<string>;
|
||||
}
|
||||
export type { IPlugin as IPluginLoader } from './PluginDescriptor';
|
||||
|
||||
/**
|
||||
* IRuntimeModuleLoader 类型别名
|
||||
*
|
||||
* @deprecated 使用 IRuntimeModule 代替。
|
||||
* @deprecated Use IRuntimeModule instead.
|
||||
*/
|
||||
export type { IRuntimeModule as IRuntimeModuleLoader } from './PluginDescriptor';
|
||||
|
||||
@@ -1,155 +1,23 @@
|
||||
/**
|
||||
* 插件系统类型定义
|
||||
* Plugin system type definitions
|
||||
* 插件描述符类型
|
||||
* Plugin descriptor types
|
||||
*
|
||||
* 从 @esengine/engine-core 重新导出基础类型,并添加编辑器专用类型。
|
||||
* Re-export base types from @esengine/engine-core, and add editor-specific types.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 插件类别
|
||||
* Plugin category
|
||||
*/
|
||||
export type PluginCategory =
|
||||
| 'core' // 核心功能 | Core functionality
|
||||
| 'rendering' // 渲染相关 | Rendering
|
||||
| 'ui' // UI 系统 | UI System
|
||||
| 'ai' // AI/行为树 | AI/Behavior
|
||||
| 'physics' // 物理引擎 | Physics
|
||||
| 'audio' // 音频系统 | Audio
|
||||
| 'networking' // 网络功能 | Networking
|
||||
| 'tools' // 工具/编辑器扩展 | Tools/Editor extensions
|
||||
| 'scripting' // 脚本/蓝图 | Scripting/Blueprint
|
||||
| 'content'; // 内容/资源 | Content/Assets
|
||||
|
||||
/**
|
||||
* 加载阶段 - 控制插件模块的加载顺序
|
||||
* Loading phase - controls the loading order of plugin modules
|
||||
*/
|
||||
export type LoadingPhase =
|
||||
| 'earliest' // 最早加载(核心模块) | Earliest (core modules)
|
||||
| 'preDefault' // 默认之前 | Before default
|
||||
| 'default' // 默认阶段 | Default phase
|
||||
| 'postDefault' // 默认之后 | After default
|
||||
| 'postEngine'; // 引擎初始化后 | After engine init
|
||||
|
||||
/**
|
||||
* 模块类型
|
||||
* Module type
|
||||
*/
|
||||
export type ModuleType = 'runtime' | 'editor';
|
||||
|
||||
/**
|
||||
* 模块描述符 - 描述插件内的一个模块
|
||||
* Module descriptor - describes a module within a plugin
|
||||
*/
|
||||
export interface ModuleDescriptor {
|
||||
/** 模块名称 | Module name */
|
||||
name: string;
|
||||
|
||||
/** 模块类型 | Module type */
|
||||
type: ModuleType;
|
||||
|
||||
/** 加载阶段 | Loading phase */
|
||||
loadingPhase?: LoadingPhase;
|
||||
|
||||
/** 模块入口文件(相对路径) | Module entry file (relative path) */
|
||||
entry?: string;
|
||||
|
||||
// ===== 运行时模块配置 | Runtime module config =====
|
||||
|
||||
/** 导出的组件类名列表 | Exported component class names */
|
||||
components?: string[];
|
||||
|
||||
/** 导出的系统类名列表 | Exported system class names */
|
||||
systems?: string[];
|
||||
|
||||
/** 导出的服务类名列表 | Exported service class names */
|
||||
services?: string[];
|
||||
|
||||
// ===== 编辑器模块配置 | Editor module config =====
|
||||
|
||||
/** 注册的面板ID列表 | Registered panel IDs */
|
||||
panels?: string[];
|
||||
|
||||
/** 注册的检视器类型列表 | Registered inspector types */
|
||||
inspectors?: string[];
|
||||
|
||||
/** 注册的 Gizmo 提供者列表 | Registered Gizmo providers */
|
||||
gizmoProviders?: string[];
|
||||
|
||||
/** 注册的编译器列表 | Registered compilers */
|
||||
compilers?: string[];
|
||||
|
||||
/** 注册的文件处理器扩展名 | Registered file handler extensions */
|
||||
fileHandlers?: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* 插件依赖
|
||||
* Plugin dependency
|
||||
*/
|
||||
export interface PluginDependency {
|
||||
/** 依赖的插件ID | Dependent plugin ID */
|
||||
id: string;
|
||||
|
||||
/** 版本要求(semver) | Version requirement (semver) */
|
||||
version?: string;
|
||||
|
||||
/** 是否可选 | Optional */
|
||||
optional?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 插件描述符 - 对应 plugin.json 文件
|
||||
* Plugin descriptor - corresponds to plugin.json
|
||||
*/
|
||||
export interface PluginDescriptor {
|
||||
/** 插件唯一标识符,如 "@esengine/tilemap" | Unique plugin ID */
|
||||
id: string;
|
||||
|
||||
/** 显示名称 | Display name */
|
||||
name: string;
|
||||
|
||||
/** 版本号 | Version */
|
||||
version: string;
|
||||
|
||||
/** 描述 | Description */
|
||||
description?: string;
|
||||
|
||||
/** 作者 | Author */
|
||||
author?: string;
|
||||
|
||||
/** 许可证 | License */
|
||||
license?: string;
|
||||
|
||||
/** 插件类别 | Plugin category */
|
||||
category: PluginCategory;
|
||||
|
||||
/** 标签(用于搜索) | Tags (for search) */
|
||||
tags?: string[];
|
||||
|
||||
/** 图标(Lucide 图标名) | Icon (Lucide icon name) */
|
||||
icon?: string;
|
||||
|
||||
/** 是否默认启用 | Enabled by default */
|
||||
enabledByDefault: boolean;
|
||||
|
||||
/** 是否可以包含内容资产 | Can contain content assets */
|
||||
canContainContent: boolean;
|
||||
|
||||
/** 是否为引擎内置插件 | Is engine built-in plugin */
|
||||
isEnginePlugin: boolean;
|
||||
|
||||
/** 是否为核心插件(不可禁用) | Is core plugin (cannot be disabled) */
|
||||
isCore?: boolean;
|
||||
|
||||
/** 模块列表 | Module list */
|
||||
modules: ModuleDescriptor[];
|
||||
|
||||
/** 依赖列表 | Dependency list */
|
||||
dependencies?: PluginDependency[];
|
||||
|
||||
/** 平台要求 | Platform requirements */
|
||||
platforms?: ('web' | 'desktop' | 'mobile')[];
|
||||
}
|
||||
// 从 engine-core 重新导出所有插件相关类型
|
||||
export type {
|
||||
PluginCategory,
|
||||
LoadingPhase,
|
||||
ModuleType,
|
||||
ModuleDescriptor,
|
||||
PluginDependency,
|
||||
PluginDescriptor,
|
||||
SystemContext,
|
||||
IRuntimeModule,
|
||||
IPlugin
|
||||
} from '@esengine/engine-core';
|
||||
|
||||
/**
|
||||
* 插件状态
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
650
packages/editor-core/src/Services/AssetRegistryService.ts
Normal file
650
packages/editor-core/src/Services/AssetRegistryService.ts
Normal file
@@ -0,0 +1,650 @@
|
||||
/**
|
||||
* Asset Registry Service
|
||||
* 资产注册表服务
|
||||
*
|
||||
* 负责扫描项目资产目录,为每个资产生成唯一GUID,
|
||||
* 并维护 GUID ↔ 路径 的映射关系。
|
||||
*
|
||||
* Responsible for scanning project asset directories,
|
||||
* generating unique GUIDs for each asset, and maintaining
|
||||
* GUID ↔ path mappings.
|
||||
*/
|
||||
|
||||
import { Core } from '@esengine/ecs-framework';
|
||||
import { MessageHub } from './MessageHub';
|
||||
|
||||
// Simple logger for AssetRegistry
|
||||
const logger = {
|
||||
info: (msg: string, ...args: unknown[]) => console.log(`[AssetRegistry] ${msg}`, ...args),
|
||||
warn: (msg: string, ...args: unknown[]) => console.warn(`[AssetRegistry] ${msg}`, ...args),
|
||||
error: (msg: string, ...args: unknown[]) => console.error(`[AssetRegistry] ${msg}`, ...args),
|
||||
debug: (msg: string, ...args: unknown[]) => console.debug(`[AssetRegistry] ${msg}`, ...args),
|
||||
};
|
||||
|
||||
/**
|
||||
* Asset GUID type (simplified, no dependency on asset-system)
|
||||
*/
|
||||
export type AssetGUID = string;
|
||||
|
||||
/**
|
||||
* Asset type for registry (using different name to avoid conflict)
|
||||
*/
|
||||
export type AssetRegistryType = string;
|
||||
|
||||
/**
|
||||
* Asset metadata (simplified)
|
||||
*/
|
||||
export interface IAssetRegistryMetadata {
|
||||
guid: AssetGUID;
|
||||
path: string;
|
||||
type: AssetRegistryType;
|
||||
name: string;
|
||||
size: number;
|
||||
hash: string;
|
||||
lastModified: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asset catalog entry for export
|
||||
*/
|
||||
export interface IAssetRegistryCatalogEntry {
|
||||
guid: AssetGUID;
|
||||
path: string;
|
||||
type: AssetRegistryType;
|
||||
size: number;
|
||||
hash: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asset file info from filesystem scan
|
||||
*/
|
||||
export interface AssetFileInfo {
|
||||
/** Absolute path to the file */
|
||||
absolutePath: string;
|
||||
/** Path relative to project root */
|
||||
relativePath: string;
|
||||
/** File name without extension */
|
||||
name: string;
|
||||
/** File extension (e.g., '.png', '.btree') */
|
||||
extension: string;
|
||||
/** File size in bytes */
|
||||
size: number;
|
||||
/** Last modified timestamp */
|
||||
lastModified: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asset registry manifest stored in project
|
||||
* 存储在项目中的资产注册表清单
|
||||
*/
|
||||
export interface AssetManifest {
|
||||
version: string;
|
||||
createdAt: number;
|
||||
updatedAt: number;
|
||||
assets: Record<string, AssetManifestEntry>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Single asset entry in manifest
|
||||
*/
|
||||
export interface AssetManifestEntry {
|
||||
guid: AssetGUID;
|
||||
relativePath: string;
|
||||
type: AssetRegistryType;
|
||||
hash?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension to asset type mapping
|
||||
*/
|
||||
const EXTENSION_TYPE_MAP: Record<string, AssetRegistryType> = {
|
||||
// Textures
|
||||
'.png': 'texture',
|
||||
'.jpg': 'texture',
|
||||
'.jpeg': 'texture',
|
||||
'.webp': 'texture',
|
||||
'.gif': 'texture',
|
||||
// Audio
|
||||
'.mp3': 'audio',
|
||||
'.ogg': 'audio',
|
||||
'.wav': 'audio',
|
||||
// Data
|
||||
'.json': 'json',
|
||||
'.txt': 'text',
|
||||
// Custom types
|
||||
'.btree': 'btree',
|
||||
'.ecs': 'scene',
|
||||
'.prefab': 'prefab',
|
||||
'.tmx': 'tilemap',
|
||||
'.tsx': 'tileset',
|
||||
};
|
||||
|
||||
/**
|
||||
* File system interface for asset scanning
|
||||
*/
|
||||
interface IFileSystem {
|
||||
readDir(path: string): Promise<string[]>;
|
||||
readFile(path: string): Promise<string>;
|
||||
writeFile(path: string, content: string): Promise<void>;
|
||||
exists(path: string): Promise<boolean>;
|
||||
stat(path: string): Promise<{ size: number; mtime: number; isDirectory: boolean }>;
|
||||
isDirectory(path: string): Promise<boolean>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple in-memory asset database
|
||||
*/
|
||||
class SimpleAssetDatabase {
|
||||
private readonly _metadata = new Map<AssetGUID, IAssetRegistryMetadata>();
|
||||
private readonly _pathToGuid = new Map<string, AssetGUID>();
|
||||
private readonly _typeToGuids = new Map<AssetRegistryType, Set<AssetGUID>>();
|
||||
|
||||
addAsset(metadata: IAssetRegistryMetadata): void {
|
||||
const { guid, path, type } = metadata;
|
||||
this._metadata.set(guid, metadata);
|
||||
this._pathToGuid.set(path, guid);
|
||||
|
||||
if (!this._typeToGuids.has(type)) {
|
||||
this._typeToGuids.set(type, new Set());
|
||||
}
|
||||
this._typeToGuids.get(type)!.add(guid);
|
||||
}
|
||||
|
||||
removeAsset(guid: AssetGUID): void {
|
||||
const metadata = this._metadata.get(guid);
|
||||
if (!metadata) return;
|
||||
|
||||
this._metadata.delete(guid);
|
||||
this._pathToGuid.delete(metadata.path);
|
||||
|
||||
const typeSet = this._typeToGuids.get(metadata.type);
|
||||
if (typeSet) {
|
||||
typeSet.delete(guid);
|
||||
}
|
||||
}
|
||||
|
||||
getMetadata(guid: AssetGUID): IAssetRegistryMetadata | undefined {
|
||||
return this._metadata.get(guid);
|
||||
}
|
||||
|
||||
getMetadataByPath(path: string): IAssetRegistryMetadata | undefined {
|
||||
const guid = this._pathToGuid.get(path);
|
||||
return guid ? this._metadata.get(guid) : undefined;
|
||||
}
|
||||
|
||||
findAssetsByType(type: AssetRegistryType): AssetGUID[] {
|
||||
const guids = this._typeToGuids.get(type);
|
||||
return guids ? Array.from(guids) : [];
|
||||
}
|
||||
|
||||
exportToCatalog(): IAssetRegistryCatalogEntry[] {
|
||||
const entries: IAssetRegistryCatalogEntry[] = [];
|
||||
this._metadata.forEach((metadata) => {
|
||||
entries.push({
|
||||
guid: metadata.guid,
|
||||
path: metadata.path,
|
||||
type: metadata.type,
|
||||
size: metadata.size,
|
||||
hash: metadata.hash
|
||||
});
|
||||
});
|
||||
return entries;
|
||||
}
|
||||
|
||||
getStatistics(): { totalAssets: number } {
|
||||
return { totalAssets: this._metadata.size };
|
||||
}
|
||||
|
||||
clear(): void {
|
||||
this._metadata.clear();
|
||||
this._pathToGuid.clear();
|
||||
this._typeToGuids.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asset Registry Service
|
||||
*/
|
||||
export class AssetRegistryService {
|
||||
private _database: SimpleAssetDatabase;
|
||||
private _projectPath: string | null = null;
|
||||
private _manifest: AssetManifest | null = null;
|
||||
private _fileSystem: IFileSystem | null = null;
|
||||
private _messageHub: MessageHub | null = null;
|
||||
private _initialized = false;
|
||||
|
||||
/** Manifest file name */
|
||||
static readonly MANIFEST_FILE = 'asset-manifest.json';
|
||||
/** Current manifest version */
|
||||
static readonly MANIFEST_VERSION = '1.0.0';
|
||||
|
||||
constructor() {
|
||||
this._database = new SimpleAssetDatabase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the service
|
||||
*/
|
||||
async initialize(): Promise<void> {
|
||||
if (this._initialized) return;
|
||||
|
||||
// Get file system service
|
||||
const IFileSystemServiceKey = Symbol.for('IFileSystemService');
|
||||
this._fileSystem = Core.services.tryResolve(IFileSystemServiceKey) as IFileSystem | null;
|
||||
|
||||
// Get message hub
|
||||
this._messageHub = Core.services.tryResolve(MessageHub) as MessageHub | null;
|
||||
|
||||
// Subscribe to project events
|
||||
if (this._messageHub) {
|
||||
this._messageHub.subscribe('project:opened', this._onProjectOpened.bind(this));
|
||||
this._messageHub.subscribe('project:closed', this._onProjectClosed.bind(this));
|
||||
}
|
||||
|
||||
this._initialized = true;
|
||||
logger.info('AssetRegistryService initialized');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle project opened event
|
||||
*/
|
||||
private async _onProjectOpened(data: { path: string }): Promise<void> {
|
||||
await this.loadProject(data.path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle project closed event
|
||||
*/
|
||||
private _onProjectClosed(): void {
|
||||
this.unloadProject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load project and scan assets
|
||||
*/
|
||||
async loadProject(projectPath: string): Promise<void> {
|
||||
if (!this._fileSystem) {
|
||||
logger.warn('FileSystem service not available, skipping asset registry');
|
||||
return;
|
||||
}
|
||||
|
||||
this._projectPath = projectPath;
|
||||
this._database.clear();
|
||||
|
||||
// Try to load existing manifest
|
||||
await this._loadManifest();
|
||||
|
||||
// Scan assets directory
|
||||
await this._scanAssetsDirectory();
|
||||
|
||||
// Save updated manifest
|
||||
await this._saveManifest();
|
||||
|
||||
logger.info(`Project assets loaded: ${this._database.getStatistics().totalAssets} assets`);
|
||||
|
||||
// Publish event
|
||||
this._messageHub?.publish('assets:registry:loaded', {
|
||||
projectPath,
|
||||
assetCount: this._database.getStatistics().totalAssets
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Unload current project
|
||||
*/
|
||||
unloadProject(): void {
|
||||
this._projectPath = null;
|
||||
this._manifest = null;
|
||||
this._database.clear();
|
||||
logger.info('Project assets unloaded');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load manifest from project
|
||||
*/
|
||||
private async _loadManifest(): Promise<void> {
|
||||
if (!this._fileSystem || !this._projectPath) return;
|
||||
|
||||
const manifestPath = this._getManifestPath();
|
||||
|
||||
try {
|
||||
const exists = await this._fileSystem.exists(manifestPath);
|
||||
if (exists) {
|
||||
const content = await this._fileSystem.readFile(manifestPath);
|
||||
this._manifest = JSON.parse(content);
|
||||
logger.debug('Loaded existing asset manifest');
|
||||
} else {
|
||||
this._manifest = this._createEmptyManifest();
|
||||
logger.debug('Created new asset manifest');
|
||||
}
|
||||
} catch (error) {
|
||||
logger.warn('Failed to load manifest, creating new one:', error);
|
||||
this._manifest = this._createEmptyManifest();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save manifest to project
|
||||
*/
|
||||
private async _saveManifest(): Promise<void> {
|
||||
if (!this._fileSystem || !this._projectPath || !this._manifest) return;
|
||||
|
||||
const manifestPath = this._getManifestPath();
|
||||
this._manifest.updatedAt = Date.now();
|
||||
|
||||
try {
|
||||
const content = JSON.stringify(this._manifest, null, 2);
|
||||
await this._fileSystem.writeFile(manifestPath, content);
|
||||
logger.debug('Saved asset manifest');
|
||||
} catch (error) {
|
||||
logger.error('Failed to save manifest:', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get manifest file path
|
||||
*/
|
||||
private _getManifestPath(): string {
|
||||
const sep = this._projectPath!.includes('\\') ? '\\' : '/';
|
||||
return `${this._projectPath}${sep}${AssetRegistryService.MANIFEST_FILE}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create empty manifest
|
||||
*/
|
||||
private _createEmptyManifest(): AssetManifest {
|
||||
return {
|
||||
version: AssetRegistryService.MANIFEST_VERSION,
|
||||
createdAt: Date.now(),
|
||||
updatedAt: Date.now(),
|
||||
assets: {}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan assets directory and register all assets
|
||||
*/
|
||||
private async _scanAssetsDirectory(): Promise<void> {
|
||||
if (!this._fileSystem || !this._projectPath) return;
|
||||
|
||||
const sep = this._projectPath.includes('\\') ? '\\' : '/';
|
||||
const assetsPath = `${this._projectPath}${sep}assets`;
|
||||
|
||||
try {
|
||||
const exists = await this._fileSystem.exists(assetsPath);
|
||||
if (!exists) {
|
||||
logger.info('No assets directory found');
|
||||
return;
|
||||
}
|
||||
|
||||
await this._scanDirectory(assetsPath, 'assets');
|
||||
} catch (error) {
|
||||
logger.error('Failed to scan assets directory:', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively scan a directory
|
||||
*/
|
||||
private async _scanDirectory(absolutePath: string, relativePath: string): Promise<void> {
|
||||
if (!this._fileSystem) return;
|
||||
|
||||
try {
|
||||
const entries = await this._fileSystem.readDir(absolutePath);
|
||||
const sep = absolutePath.includes('\\') ? '\\' : '/';
|
||||
|
||||
for (const entry of entries) {
|
||||
const entryAbsPath = `${absolutePath}${sep}${entry}`;
|
||||
const entryRelPath = `${relativePath}/${entry}`;
|
||||
|
||||
try {
|
||||
const isDir = await this._fileSystem.isDirectory(entryAbsPath);
|
||||
|
||||
if (isDir) {
|
||||
// Recursively scan subdirectory
|
||||
await this._scanDirectory(entryAbsPath, entryRelPath);
|
||||
} else {
|
||||
// Register file as asset
|
||||
await this._registerAssetFile(entryAbsPath, entryRelPath);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.warn(`Failed to process entry ${entry}:`, error);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
logger.warn(`Failed to read directory ${absolutePath}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a single asset file
|
||||
*/
|
||||
private async _registerAssetFile(absolutePath: string, relativePath: string): Promise<void> {
|
||||
if (!this._fileSystem || !this._manifest) return;
|
||||
|
||||
// Get file extension
|
||||
const lastDot = relativePath.lastIndexOf('.');
|
||||
if (lastDot === -1) return; // Skip files without extension
|
||||
|
||||
const extension = relativePath.substring(lastDot).toLowerCase();
|
||||
const assetType = EXTENSION_TYPE_MAP[extension];
|
||||
|
||||
// Skip unknown file types
|
||||
if (!assetType) return;
|
||||
|
||||
// Get file info
|
||||
let stat: { size: number; mtime: number };
|
||||
try {
|
||||
stat = await this._fileSystem.stat(absolutePath);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if already in manifest
|
||||
let guid: AssetGUID;
|
||||
const existingEntry = this._manifest.assets[relativePath];
|
||||
|
||||
if (existingEntry) {
|
||||
guid = existingEntry.guid;
|
||||
} else {
|
||||
// Generate new GUID
|
||||
guid = this._generateGUID();
|
||||
this._manifest.assets[relativePath] = {
|
||||
guid,
|
||||
relativePath,
|
||||
type: assetType
|
||||
};
|
||||
}
|
||||
|
||||
// Get file name
|
||||
const lastSlash = relativePath.lastIndexOf('/');
|
||||
const fileName = lastSlash >= 0 ? relativePath.substring(lastSlash + 1) : relativePath;
|
||||
const name = fileName.substring(0, fileName.lastIndexOf('.'));
|
||||
|
||||
// Create metadata
|
||||
const metadata: IAssetRegistryMetadata = {
|
||||
guid,
|
||||
path: relativePath,
|
||||
type: assetType,
|
||||
name,
|
||||
size: stat.size,
|
||||
hash: '', // Could compute hash if needed
|
||||
lastModified: stat.mtime
|
||||
};
|
||||
|
||||
// Register in database
|
||||
this._database.addAsset(metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a unique GUID
|
||||
*/
|
||||
private _generateGUID(): AssetGUID {
|
||||
// Simple UUID v4 generation
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
||||
const r = (Math.random() * 16) | 0;
|
||||
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
|
||||
// ==================== Public API ====================
|
||||
|
||||
/**
|
||||
* Get asset metadata by GUID
|
||||
*/
|
||||
getAsset(guid: AssetGUID): IAssetRegistryMetadata | undefined {
|
||||
return this._database.getMetadata(guid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get asset metadata by relative path
|
||||
*/
|
||||
getAssetByPath(relativePath: string): IAssetRegistryMetadata | undefined {
|
||||
return this._database.getMetadataByPath(relativePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get GUID for a relative path
|
||||
*/
|
||||
getGuidByPath(relativePath: string): AssetGUID | undefined {
|
||||
const metadata = this._database.getMetadataByPath(relativePath);
|
||||
return metadata?.guid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get relative path for a GUID
|
||||
*/
|
||||
getPathByGuid(guid: AssetGUID): string | undefined {
|
||||
const metadata = this._database.getMetadata(guid);
|
||||
return metadata?.path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert absolute path to relative path
|
||||
*/
|
||||
absoluteToRelative(absolutePath: string): string | null {
|
||||
if (!this._projectPath) return null;
|
||||
|
||||
const normalizedAbs = absolutePath.replace(/\\/g, '/');
|
||||
const normalizedProject = this._projectPath.replace(/\\/g, '/');
|
||||
|
||||
if (normalizedAbs.startsWith(normalizedProject)) {
|
||||
return normalizedAbs.substring(normalizedProject.length + 1);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert relative path to absolute path
|
||||
*/
|
||||
relativeToAbsolute(relativePath: string): string | null {
|
||||
if (!this._projectPath) return null;
|
||||
|
||||
const sep = this._projectPath.includes('\\') ? '\\' : '/';
|
||||
return `${this._projectPath}${sep}${relativePath.replace(/\//g, sep)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find assets by type
|
||||
*/
|
||||
findAssetsByType(type: AssetRegistryType): IAssetRegistryMetadata[] {
|
||||
const guids = this._database.findAssetsByType(type);
|
||||
return guids
|
||||
.map(guid => this._database.getMetadata(guid))
|
||||
.filter((m): m is IAssetRegistryMetadata => m !== undefined);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all registered assets
|
||||
*/
|
||||
getAllAssets(): IAssetRegistryMetadata[] {
|
||||
const entries = this._database.exportToCatalog();
|
||||
return entries.map(entry => this._database.getMetadata(entry.guid))
|
||||
.filter((m): m is IAssetRegistryMetadata => m !== undefined);
|
||||
}
|
||||
|
||||
/**
|
||||
* Export catalog for runtime use
|
||||
* 导出运行时使用的资产目录
|
||||
*/
|
||||
exportCatalog(): IAssetRegistryCatalogEntry[] {
|
||||
return this._database.exportToCatalog();
|
||||
}
|
||||
|
||||
/**
|
||||
* Export catalog as JSON string
|
||||
*/
|
||||
exportCatalogJSON(): string {
|
||||
const entries = this._database.exportToCatalog();
|
||||
const catalog = {
|
||||
version: '1.0.0',
|
||||
createdAt: Date.now(),
|
||||
entries: Object.fromEntries(entries.map(e => [e.guid, e]))
|
||||
};
|
||||
return JSON.stringify(catalog, null, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new asset (e.g., when a file is created)
|
||||
*/
|
||||
async registerAsset(absolutePath: string): Promise<AssetGUID | null> {
|
||||
const relativePath = this.absoluteToRelative(absolutePath);
|
||||
if (!relativePath) return null;
|
||||
|
||||
await this._registerAssetFile(absolutePath, relativePath);
|
||||
await this._saveManifest();
|
||||
|
||||
const metadata = this._database.getMetadataByPath(relativePath);
|
||||
return metadata?.guid ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister an asset (e.g., when a file is deleted)
|
||||
*/
|
||||
async unregisterAsset(absolutePath: string): Promise<void> {
|
||||
const relativePath = this.absoluteToRelative(absolutePath);
|
||||
if (!relativePath || !this._manifest) return;
|
||||
|
||||
const metadata = this._database.getMetadataByPath(relativePath);
|
||||
if (metadata) {
|
||||
this._database.removeAsset(metadata.guid);
|
||||
delete this._manifest.assets[relativePath];
|
||||
await this._saveManifest();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh a single asset (e.g., when file is modified)
|
||||
*/
|
||||
async refreshAsset(absolutePath: string): Promise<void> {
|
||||
const relativePath = this.absoluteToRelative(absolutePath);
|
||||
if (!relativePath) return;
|
||||
|
||||
// Re-register the asset
|
||||
await this._registerAssetFile(absolutePath, relativePath);
|
||||
await this._saveManifest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get database statistics
|
||||
*/
|
||||
getStatistics() {
|
||||
return this._database.getStatistics();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if service is ready
|
||||
*/
|
||||
get isReady(): boolean {
|
||||
return this._initialized && this._projectPath !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current project path
|
||||
*/
|
||||
get projectPath(): string | null {
|
||||
return this._projectPath;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable, IService, Entity, Core } from '@esengine/ecs-framework';
|
||||
import { Injectable, IService, Entity, Core, HierarchyComponent } from '@esengine/ecs-framework';
|
||||
import { MessageHub } from './MessageHub';
|
||||
|
||||
export interface EntityTreeNode {
|
||||
@@ -68,6 +68,10 @@ export class EntityStoreService implements IService {
|
||||
.filter((e): e is Entity => e !== undefined);
|
||||
}
|
||||
|
||||
public getRootEntityIds(): number[] {
|
||||
return [...this.rootEntityIds];
|
||||
}
|
||||
|
||||
public getEntity(id: number): Entity | undefined {
|
||||
return this.entities.get(id);
|
||||
}
|
||||
@@ -88,7 +92,9 @@ export class EntityStoreService implements IService {
|
||||
|
||||
scene.entities.forEach((entity) => {
|
||||
this.entities.set(entity.id, entity);
|
||||
if (!entity.parent) {
|
||||
const hierarchy = entity.getComponent(HierarchyComponent);
|
||||
const bHasNoParent = hierarchy?.parentId === null || hierarchy?.parentId === undefined;
|
||||
if (bHasNoParent) {
|
||||
this.rootEntityIds.push(entity.id);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -19,6 +19,12 @@ export interface AssetCreationMapping {
|
||||
canCreate?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* FileActionRegistry 服务标识符
|
||||
* FileActionRegistry service identifier
|
||||
*/
|
||||
export const IFileActionRegistry = Symbol.for('IFileActionRegistry');
|
||||
|
||||
/**
|
||||
* 文件操作注册表服务
|
||||
*
|
||||
|
||||
@@ -8,6 +8,7 @@ export interface LogEntry {
|
||||
source: string;
|
||||
message: string;
|
||||
args: unknown[];
|
||||
stack?: string; // 调用堆栈
|
||||
clientId?: string; // 远程客户端ID
|
||||
}
|
||||
|
||||
@@ -59,12 +60,12 @@ export class LogService implements IService {
|
||||
};
|
||||
|
||||
console.warn = (...args: unknown[]) => {
|
||||
this.addLog(LogLevel.Warn, 'console', this.formatMessage(args), args);
|
||||
this.addLog(LogLevel.Warn, 'console', this.formatMessage(args), args, true);
|
||||
this.originalConsole.warn(...args);
|
||||
};
|
||||
|
||||
console.error = (...args: unknown[]) => {
|
||||
this.addLog(LogLevel.Error, 'console', this.formatMessage(args), args);
|
||||
this.addLog(LogLevel.Error, 'console', this.formatMessage(args), args, true);
|
||||
this.originalConsole.error(...args);
|
||||
};
|
||||
|
||||
@@ -93,7 +94,10 @@ export class LogService implements IService {
|
||||
private formatMessage(args: unknown[]): string {
|
||||
return args.map((arg) => {
|
||||
if (typeof arg === 'string') return arg;
|
||||
if (arg instanceof Error) return arg.message;
|
||||
if (arg instanceof Error) {
|
||||
// 包含错误消息和堆栈
|
||||
return arg.stack || arg.message;
|
||||
}
|
||||
try {
|
||||
return JSON.stringify(arg);
|
||||
} catch {
|
||||
@@ -102,17 +106,30 @@ export class LogService implements IService {
|
||||
}).join(' ');
|
||||
}
|
||||
|
||||
/**
|
||||
* 捕获当前调用堆栈
|
||||
*/
|
||||
private captureStack(): string {
|
||||
const stack = new Error().stack;
|
||||
if (!stack) return '';
|
||||
|
||||
// 移除前几行(Error、captureStack、addLog、console.xxx)
|
||||
const lines = stack.split('\n');
|
||||
return lines.slice(4).join('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加日志
|
||||
*/
|
||||
private addLog(level: LogLevel, source: string, message: string, args: unknown[]): void {
|
||||
private addLog(level: LogLevel, source: string, message: string, args: unknown[], includeStack = false): void {
|
||||
const entry: LogEntry = {
|
||||
id: this.nextId++,
|
||||
timestamp: new Date(),
|
||||
level,
|
||||
source,
|
||||
message,
|
||||
args
|
||||
args,
|
||||
stack: includeStack ? this.captureStack() : undefined
|
||||
};
|
||||
|
||||
this.logs.push(entry);
|
||||
|
||||
@@ -26,6 +26,15 @@ export interface UIDesignResolution {
|
||||
height: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 插件配置
|
||||
* Plugin Configuration
|
||||
*/
|
||||
export interface PluginSettings {
|
||||
/** 启用的插件 ID 列表 / Enabled plugin IDs */
|
||||
enabledPlugins: string[];
|
||||
}
|
||||
|
||||
export interface ProjectConfig {
|
||||
projectType?: ProjectType;
|
||||
componentsPath?: string;
|
||||
@@ -35,6 +44,8 @@ export interface ProjectConfig {
|
||||
defaultScene?: string;
|
||||
/** UI 设计分辨率 / UI design resolution */
|
||||
uiDesignResolution?: UIDesignResolution;
|
||||
/** 插件配置 / Plugin settings */
|
||||
plugins?: PluginSettings;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
@@ -200,16 +211,21 @@ export class ProjectService implements IService {
|
||||
private async loadConfig(configPath: string): Promise<ProjectConfig> {
|
||||
try {
|
||||
const content = await this.fileAPI.readFileContent(configPath);
|
||||
logger.debug('Raw config content:', content);
|
||||
const config = JSON.parse(content) as ProjectConfig;
|
||||
return {
|
||||
logger.debug('Parsed config plugins:', config.plugins);
|
||||
const result = {
|
||||
projectType: config.projectType || 'esengine',
|
||||
componentsPath: config.componentsPath || '',
|
||||
componentPattern: config.componentPattern || '**/*.ts',
|
||||
buildOutput: config.buildOutput || 'temp/editor-components',
|
||||
scenesPath: config.scenesPath || 'scenes',
|
||||
defaultScene: config.defaultScene || 'main.ecs',
|
||||
uiDesignResolution: config.uiDesignResolution
|
||||
uiDesignResolution: config.uiDesignResolution,
|
||||
plugins: config.plugins
|
||||
};
|
||||
logger.debug('Loaded config result:', result);
|
||||
return result;
|
||||
} catch (error) {
|
||||
logger.warn('Failed to load config, using defaults', error);
|
||||
return {
|
||||
@@ -280,6 +296,60 @@ export class ProjectService implements IService {
|
||||
await this.updateConfig({ uiDesignResolution: resolution });
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取启用的插件列表
|
||||
* Get enabled plugins list
|
||||
*/
|
||||
public getEnabledPlugins(): string[] {
|
||||
return this.projectConfig?.plugins?.enabledPlugins || [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取插件配置
|
||||
* Get plugin settings
|
||||
*/
|
||||
public getPluginSettings(): PluginSettings | null {
|
||||
logger.debug('getPluginSettings called, projectConfig:', this.projectConfig);
|
||||
logger.debug('getPluginSettings plugins:', this.projectConfig?.plugins);
|
||||
return this.projectConfig?.plugins || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置启用的插件列表
|
||||
* Set enabled plugins list
|
||||
*
|
||||
* @param enabledPlugins - Array of enabled plugin IDs
|
||||
*/
|
||||
public async setEnabledPlugins(enabledPlugins: string[]): Promise<void> {
|
||||
await this.updateConfig({
|
||||
plugins: {
|
||||
enabledPlugins
|
||||
}
|
||||
});
|
||||
await this.messageHub.publish('project:pluginsChanged', { enabledPlugins });
|
||||
logger.info('Plugin settings saved', { count: enabledPlugins.length });
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用插件
|
||||
* Enable a plugin
|
||||
*/
|
||||
public async enablePlugin(pluginId: string): Promise<void> {
|
||||
const current = this.getEnabledPlugins();
|
||||
if (!current.includes(pluginId)) {
|
||||
await this.setEnabledPlugins([...current, pluginId]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用插件
|
||||
* Disable a plugin
|
||||
*/
|
||||
public async disablePlugin(pluginId: string): Promise<void> {
|
||||
const current = this.getEnabledPlugins();
|
||||
await this.setEnabledPlugins(current.filter(id => id !== pluginId));
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this.currentProject = null;
|
||||
this.projectConfig = null;
|
||||
|
||||
@@ -4,6 +4,14 @@ import { createLogger } from '@esengine/ecs-framework';
|
||||
|
||||
const logger = createLogger('PropertyMetadata');
|
||||
|
||||
/**
|
||||
* 不需要在 Inspector 中显示的内部组件类型
|
||||
* 这些组件不使用 @Property 装饰器,因为它们的属性不应该被手动编辑
|
||||
*/
|
||||
const INTERNAL_COMPONENTS = new Set([
|
||||
'HierarchyComponent'
|
||||
]);
|
||||
|
||||
export type { PropertyOptions, PropertyAction, PropertyControl, AssetType, EnumOption };
|
||||
export type PropertyMetadata = PropertyOptions;
|
||||
export type PropertyType = 'number' | 'integer' | 'string' | 'boolean' | 'color' | 'vector2' | 'vector3' | 'enum' | 'asset' | 'animationClips';
|
||||
@@ -53,7 +61,10 @@ export class PropertyMetadataService implements IService {
|
||||
}
|
||||
|
||||
// 没有元数据时返回空对象
|
||||
logger.warn(`No property metadata found for component: ${component.constructor.name}`);
|
||||
// 内部组件(如 HierarchyComponent)不需要警告
|
||||
if (!INTERNAL_COMPONENTS.has(component.constructor.name)) {
|
||||
logger.warn(`No property metadata found for component: ${component.constructor.name}`);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ export class SettingsRegistry implements IService {
|
||||
if (this.categories.has(category.id)) {
|
||||
console.warn(`[SettingsRegistry] Category ${category.id} already registered, overwriting`);
|
||||
}
|
||||
console.log(`[SettingsRegistry] Registering category: ${category.id} (${category.title}), sections: ${category.sections.map(s => s.id).join(', ')}`);
|
||||
this.categories.set(category.id, category);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ export * from './Services/IFieldEditor';
|
||||
export * from './Services/FieldEditorRegistry';
|
||||
export * from './Services/ComponentInspectorRegistry';
|
||||
export * from './Services/ComponentActionRegistry';
|
||||
export * from './Services/AssetRegistryService';
|
||||
|
||||
export * from './Gizmos';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user