Feature/runtime cdn and plugin loader (#240)
* feat(ui): 完善 UI 布局系统和编辑器可视化工具 * refactor: 移除 ModuleRegistry,统一使用 PluginManager 插件系统 * fix: 修复 CodeQL 警告并提升测试覆盖率 * refactor: 分离运行时入口点,解决 runtime bundle 包含 React 的问题 * fix(ci): 添加 editor-core 和 editor-runtime 到 CI 依赖构建步骤 * docs: 完善 ServiceContainer 文档,新增 Symbol.for 模式和 @InjectProperty 说明 * fix(ci): 修复 type-check 失败问题 * fix(ci): 修复类型检查失败问题 * fix(ci): 修复类型检查失败问题 * fix(ci): behavior-tree 构建添加 @tauri-apps 外部依赖 * fix(ci): behavior-tree 添加 @tauri-apps/plugin-fs 类型依赖 * fix(ci): platform-web 添加缺失的 behavior-tree 依赖 * fix(lint): 移除正则表达式中不必要的转义字符
This commit is contained in:
@@ -5,17 +5,10 @@
|
||||
*/
|
||||
|
||||
import { injectable } from 'tsyringe';
|
||||
import type { IService, Component, Entity } from '@esengine/ecs-framework';
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
export interface ComponentAction {
|
||||
id: string;
|
||||
componentName: string;
|
||||
label: string;
|
||||
icon?: ReactNode;
|
||||
order?: number;
|
||||
execute: (component: Component, entity: Entity) => void | Promise<void>;
|
||||
}
|
||||
import type { IService } from '@esengine/ecs-framework';
|
||||
import type { ComponentAction } from '../Plugin/IPluginLoader';
|
||||
// Re-export ComponentAction type from Plugin system
|
||||
export type { ComponentAction } from '../Plugin/IPluginLoader';
|
||||
|
||||
@injectable()
|
||||
export class ComponentActionRegistry implements IService {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { IService } from '@esengine/ecs-framework';
|
||||
import { FileActionHandler, FileCreationTemplate } from '../Plugins/IEditorPlugin';
|
||||
import type { FileActionHandler, FileCreationTemplate } from '../Plugin/IPluginLoader';
|
||||
|
||||
// Re-export for backwards compatibility
|
||||
export type { FileCreationTemplate } from '../Plugin/IPluginLoader';
|
||||
|
||||
/**
|
||||
* 文件操作注册表服务
|
||||
|
||||
@@ -6,7 +6,7 @@ import type { IFileAPI } from '../Types/IFileAPI';
|
||||
|
||||
const logger = createLogger('ProjectService');
|
||||
|
||||
export type ProjectType = 'cocos' | 'laya' | 'unknown';
|
||||
export type ProjectType = 'esengine' | 'unknown';
|
||||
|
||||
export interface ProjectInfo {
|
||||
path: string;
|
||||
@@ -15,6 +15,17 @@ export interface ProjectInfo {
|
||||
configPath?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* UI 设计分辨率配置
|
||||
* UI Design Resolution Configuration
|
||||
*/
|
||||
export interface UIDesignResolution {
|
||||
/** 设计宽度 / Design width */
|
||||
width: number;
|
||||
/** 设计高度 / Design height */
|
||||
height: number;
|
||||
}
|
||||
|
||||
export interface ProjectConfig {
|
||||
projectType?: ProjectType;
|
||||
componentsPath?: string;
|
||||
@@ -22,6 +33,8 @@ export interface ProjectConfig {
|
||||
buildOutput?: string;
|
||||
scenesPath?: string;
|
||||
defaultScene?: string;
|
||||
/** UI 设计分辨率 / UI design resolution */
|
||||
uiDesignResolution?: UIDesignResolution;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
@@ -47,11 +60,11 @@ export class ProjectService implements IService {
|
||||
}
|
||||
|
||||
const config: ProjectConfig = {
|
||||
projectType: 'cocos',
|
||||
projectType: 'esengine',
|
||||
componentsPath: 'components',
|
||||
componentPattern: '**/*.ts',
|
||||
buildOutput: 'temp/editor-components',
|
||||
scenesPath: 'ecs-scenes',
|
||||
scenesPath: 'scenes',
|
||||
defaultScene: 'main.ecs'
|
||||
};
|
||||
|
||||
@@ -176,7 +189,7 @@ export class ProjectService implements IService {
|
||||
|
||||
try {
|
||||
projectInfo.configPath = configPath;
|
||||
projectInfo.type = 'cocos';
|
||||
projectInfo.type = 'esengine';
|
||||
} catch (error) {
|
||||
logger.warn('No ecs-editor.config.json found, using defaults');
|
||||
}
|
||||
@@ -185,14 +198,86 @@ export class ProjectService implements IService {
|
||||
}
|
||||
|
||||
private async loadConfig(configPath: string): Promise<ProjectConfig> {
|
||||
return {
|
||||
projectType: 'cocos',
|
||||
componentsPath: '',
|
||||
componentPattern: '**/*.ts',
|
||||
buildOutput: 'temp/editor-components',
|
||||
scenesPath: 'ecs-scenes',
|
||||
defaultScene: 'main.ecs'
|
||||
try {
|
||||
const content = await this.fileAPI.readFileContent(configPath);
|
||||
const config = JSON.parse(content) as ProjectConfig;
|
||||
return {
|
||||
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
|
||||
};
|
||||
} catch (error) {
|
||||
logger.warn('Failed to load config, using defaults', error);
|
||||
return {
|
||||
projectType: 'esengine',
|
||||
componentsPath: '',
|
||||
componentPattern: '**/*.ts',
|
||||
buildOutput: 'temp/editor-components',
|
||||
scenesPath: 'scenes',
|
||||
defaultScene: 'main.ecs'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存项目配置
|
||||
*/
|
||||
public async saveConfig(): Promise<void> {
|
||||
if (!this.currentProject?.configPath || !this.projectConfig) {
|
||||
logger.warn('No project or config to save');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const content = JSON.stringify(this.projectConfig, null, 2);
|
||||
await this.fileAPI.writeFileContent(this.currentProject.configPath, content);
|
||||
logger.info('Project config saved');
|
||||
} catch (error) {
|
||||
logger.error('Failed to save project config', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新项目配置
|
||||
*/
|
||||
public async updateConfig(updates: Partial<ProjectConfig>): Promise<void> {
|
||||
if (!this.projectConfig) {
|
||||
logger.warn('No project config to update');
|
||||
return;
|
||||
}
|
||||
|
||||
this.projectConfig = {
|
||||
...this.projectConfig,
|
||||
...updates
|
||||
};
|
||||
|
||||
await this.saveConfig();
|
||||
await this.messageHub.publish('project:configUpdated', { config: this.projectConfig });
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 UI 设计分辨率
|
||||
* Get UI design resolution
|
||||
*
|
||||
* @returns UI design resolution, defaults to 1920x1080 if not set
|
||||
*/
|
||||
public getUIDesignResolution(): UIDesignResolution {
|
||||
return this.projectConfig?.uiDesignResolution || { width: 1920, height: 1080 };
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 UI 设计分辨率
|
||||
* Set UI design resolution
|
||||
*
|
||||
* @param resolution - The new design resolution
|
||||
*/
|
||||
public async setUIDesignResolution(resolution: UIDesignResolution): Promise<void> {
|
||||
await this.updateConfig({ uiDesignResolution: resolution });
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { MessageHub } from './MessageHub';
|
||||
import type { IFileAPI } from '../Types/IFileAPI';
|
||||
import type { ProjectService } from './ProjectService';
|
||||
import type { EntityStoreService } from './EntityStoreService';
|
||||
import { SceneTemplateRegistry } from './SceneTemplateRegistry';
|
||||
|
||||
const logger = createLogger('SceneManagerService');
|
||||
|
||||
@@ -45,7 +46,13 @@ export class SceneManagerService implements IService {
|
||||
this.sceneResourceManager = manager;
|
||||
}
|
||||
|
||||
public async newScene(): Promise<void> {
|
||||
/**
|
||||
* 创建新场景
|
||||
* Create a new scene
|
||||
*
|
||||
* @param templateName - 场景模板名称,不传则使用默认模板 / Scene template name, uses default if not specified
|
||||
*/
|
||||
public async newScene(templateName?: string): Promise<void> {
|
||||
if (!await this.canClose()) {
|
||||
return;
|
||||
}
|
||||
@@ -54,11 +61,15 @@ export class SceneManagerService implements IService {
|
||||
if (!scene) {
|
||||
throw new Error('No active scene');
|
||||
}
|
||||
|
||||
// 只移除实体,保留系统(系统由模块管理)
|
||||
// Only remove entities, preserve systems (systems managed by modules)
|
||||
scene.entities.removeAllEntities();
|
||||
const systems = [...scene.systems];
|
||||
for (const system of systems) {
|
||||
scene.removeEntityProcessor(system);
|
||||
}
|
||||
|
||||
// 使用场景模板创建默认实体
|
||||
// Create default entities using scene template
|
||||
const createdEntities = SceneTemplateRegistry.createDefaultEntities(scene, templateName);
|
||||
logger.debug(`Created ${createdEntities.length} default entities from template`);
|
||||
|
||||
this.sceneState = {
|
||||
currentScenePath: null,
|
||||
@@ -67,7 +78,16 @@ export class SceneManagerService implements IService {
|
||||
isSaved: false
|
||||
};
|
||||
|
||||
// 同步到 EntityStore
|
||||
// Sync to EntityStore
|
||||
this.entityStore?.syncFromScene();
|
||||
|
||||
// 通知创建的实体
|
||||
// Notify about created entities
|
||||
for (const entity of createdEntities) {
|
||||
await this.messageHub.publish('entity:added', { entity });
|
||||
}
|
||||
|
||||
await this.messageHub.publish('scene:new', {});
|
||||
logger.info('New scene created');
|
||||
}
|
||||
|
||||
128
packages/editor-core/src/Services/SceneTemplateRegistry.ts
Normal file
128
packages/editor-core/src/Services/SceneTemplateRegistry.ts
Normal file
@@ -0,0 +1,128 @@
|
||||
import type { Scene, Entity } from '@esengine/ecs-framework';
|
||||
|
||||
/**
|
||||
* 默认实体创建函数类型
|
||||
* Default entity creator function type
|
||||
*/
|
||||
export type DefaultEntityCreator = (scene: Scene) => Entity | null;
|
||||
|
||||
/**
|
||||
* 场景模板配置
|
||||
* Scene template configuration
|
||||
*/
|
||||
export interface SceneTemplate {
|
||||
/** 模板名称 / Template name */
|
||||
name: string;
|
||||
/** 模板描述 / Template description */
|
||||
description?: string;
|
||||
/** 默认实体创建器列表 / Default entity creators */
|
||||
defaultEntities: DefaultEntityCreator[];
|
||||
}
|
||||
|
||||
/**
|
||||
* 场景模板注册表
|
||||
* Registry for scene templates that define default entities
|
||||
*
|
||||
* This allows the editor-app to register what entities should be created
|
||||
* when a new scene is created, without editor-core needing to know about
|
||||
* specific components like CameraComponent.
|
||||
*
|
||||
* 这允许 editor-app 注册新建场景时应该创建的实体,
|
||||
* 而 editor-core 不需要知道具体的组件如 CameraComponent。
|
||||
*/
|
||||
export class SceneTemplateRegistry {
|
||||
private static templates: Map<string, SceneTemplate> = new Map();
|
||||
private static defaultTemplateName = 'default';
|
||||
|
||||
/**
|
||||
* 注册场景模板
|
||||
* Register a scene template
|
||||
*/
|
||||
static registerTemplate(template: SceneTemplate): void {
|
||||
this.templates.set(template.name, template);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册默认实体创建器到默认模板
|
||||
* Register a default entity creator to the default template
|
||||
*/
|
||||
static registerDefaultEntity(creator: DefaultEntityCreator): void {
|
||||
let defaultTemplate = this.templates.get(this.defaultTemplateName);
|
||||
if (!defaultTemplate) {
|
||||
defaultTemplate = {
|
||||
name: this.defaultTemplateName,
|
||||
description: 'Default scene template',
|
||||
defaultEntities: []
|
||||
};
|
||||
this.templates.set(this.defaultTemplateName, defaultTemplate);
|
||||
}
|
||||
defaultTemplate.defaultEntities.push(creator);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取场景模板
|
||||
* Get a scene template by name
|
||||
*/
|
||||
static getTemplate(name: string): SceneTemplate | undefined {
|
||||
return this.templates.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取默认模板
|
||||
* Get the default template
|
||||
*/
|
||||
static getDefaultTemplate(): SceneTemplate | undefined {
|
||||
return this.templates.get(this.defaultTemplateName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置默认模板名称
|
||||
* Set the default template name
|
||||
*/
|
||||
static setDefaultTemplateName(name: string): void {
|
||||
this.defaultTemplateName = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有模板名称
|
||||
* Get all template names
|
||||
*/
|
||||
static getTemplateNames(): string[] {
|
||||
return Array.from(this.templates.keys());
|
||||
}
|
||||
|
||||
/**
|
||||
* 为场景创建默认实体
|
||||
* Create default entities for a scene using a template
|
||||
*
|
||||
* @param scene - 目标场景 / Target scene
|
||||
* @param templateName - 模板名称,默认使用默认模板 / Template name, uses default if not specified
|
||||
* @returns 创建的实体列表 / List of created entities
|
||||
*/
|
||||
static createDefaultEntities(scene: Scene, templateName?: string): Entity[] {
|
||||
const template = templateName
|
||||
? this.templates.get(templateName)
|
||||
: this.getDefaultTemplate();
|
||||
|
||||
if (!template) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const entities: Entity[] = [];
|
||||
for (const creator of template.defaultEntities) {
|
||||
const entity = creator(scene);
|
||||
if (entity) {
|
||||
entities.push(entity);
|
||||
}
|
||||
}
|
||||
return entities;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除所有模板
|
||||
* Clear all templates
|
||||
*/
|
||||
static clear(): void {
|
||||
this.templates.clear();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { IService } from '@esengine/ecs-framework';
|
||||
import { Injectable } from '@esengine/ecs-framework';
|
||||
import { createLogger } from '@esengine/ecs-framework';
|
||||
import type { ISerializer } from '../Plugins/IEditorPlugin';
|
||||
import type { ISerializer } from '../Plugin/IPluginLoader';
|
||||
|
||||
const logger = createLogger('SerializerRegistry');
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Injectable, IService } from '@esengine/ecs-framework';
|
||||
|
||||
export type SettingType = 'string' | 'number' | 'boolean' | 'select' | 'color' | 'range';
|
||||
export type SettingType = 'string' | 'number' | 'boolean' | 'select' | 'color' | 'range' | 'pluginList';
|
||||
|
||||
export interface SettingOption {
|
||||
label: string;
|
||||
|
||||
Reference in New Issue
Block a user