Feature/physics and tilemap enhancement (#247)

* feat(behavior-tree,tilemap): 修复编辑器连线缩放问题并增强插件系统

* feat(node-editor,blueprint): 新增通用节点编辑器和蓝图可视化脚本系统

* feat(editor,tilemap): 优化编辑器UI样式和Tilemap编辑器功能

* fix: 修复CodeQL安全警告和CI类型检查错误

* fix: 修复CodeQL安全警告和CI类型检查错误

* fix: 修复CodeQL安全警告和CI类型检查错误
This commit is contained in:
YHH
2025-11-29 23:00:48 +08:00
committed by GitHub
parent f03b73b58e
commit 359886c72f
198 changed files with 33879 additions and 13121 deletions

View File

@@ -14,7 +14,7 @@ import type { Entity } from '@esengine/ecs-framework';
* Gizmo type enumeration
* Gizmo 类型枚举
*/
export type GizmoType = 'rect' | 'circle' | 'line' | 'grid';
export type GizmoType = 'rect' | 'circle' | 'line' | 'grid' | 'capsule';
/**
* Color in RGBA format (0-1 range)
@@ -105,11 +105,31 @@ export interface IGridGizmoData {
color: GizmoColor;
}
/**
* Capsule gizmo data
* 胶囊 gizmo 数据
*/
export interface ICapsuleGizmoData {
type: 'capsule';
/** Center X position | 中心 X 位置 */
x: number;
/** Center Y position | 中心 Y 位置 */
y: number;
/** Capsule radius | 胶囊半径 */
radius: number;
/** Half height (distance from center to cap centers) | 半高度(从中心到端帽圆心的距离) */
halfHeight: number;
/** Rotation in radians | 旋转角度(弧度) */
rotation: number;
/** Color | 颜色 */
color: GizmoColor;
}
/**
* Union type for all gizmo data
* 所有 gizmo 数据的联合类型
*/
export type IGizmoRenderData = IRectGizmoData | ICircleGizmoData | ILineGizmoData | IGridGizmoData;
export type IGizmoRenderData = IRectGizmoData | ICircleGizmoData | ILineGizmoData | IGridGizmoData | ICapsuleGizmoData;
/**
* Gizmo Provider Interface

View File

@@ -47,6 +47,13 @@ export interface IRuntimeModuleLoader {
*/
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
@@ -338,6 +345,9 @@ export interface IPluginLoader {
/**
* 文件创建模板
* File creation template
*
* 插件通过 getContent 提供文件内容,编辑器负责写入文件。
* 这样可以避免插件直接访问文件系统带来的权限问题。
*/
export interface FileCreationTemplate {
/** 模板ID | Template ID */
@@ -350,6 +360,10 @@ export interface FileCreationTemplate {
icon?: string;
/** 分类 | Category */
category?: string;
/** 创建函数 | Create function */
create: (filePath: string) => Promise<void>;
/**
* 获取文件内容 | Get file content
* @param fileName 文件名(不含路径,含扩展名)
* @returns 文件内容字符串
*/
getContent: (fileName: string) => string | Promise<string>;
}

View File

@@ -16,6 +16,7 @@ export type PluginCategory =
| 'audio' // 音频系统 | Audio
| 'networking' // 网络功能 | Networking
| 'tools' // 工具/编辑器扩展 | Tools/Editor extensions
| 'scripting' // 脚本/蓝图 | Scripting/Blueprint
| 'content'; // 内容/资源 | Content/Assets
/**

View File

@@ -331,16 +331,22 @@ export class PluginManager implements IService {
*/
createSystemsForScene(scene: IScene, context: SystemContext): void {
logger.info('Creating systems for scene...');
console.log('[PluginManager] createSystemsForScene called, context.assetManager:', context.assetManager ? 'exists' : 'null');
const sortedPlugins = this.sortByLoadingPhase('runtime');
console.log('[PluginManager] Sorted plugins for runtime:', sortedPlugins);
// 第一阶段:创建所有系统
// Phase 1: Create all systems
for (const pluginId of sortedPlugins) {
const plugin = this.plugins.get(pluginId);
console.log(`[PluginManager] Plugin ${pluginId}: enabled=${plugin?.enabled}, state=${plugin?.state}, hasRuntimeModule=${!!plugin?.loader.runtimeModule}`);
if (!plugin?.enabled || plugin.state === 'error') continue;
const runtimeModule = plugin.loader.runtimeModule;
if (runtimeModule?.createSystems) {
try {
console.log(`[PluginManager] Calling createSystems for: ${pluginId}`);
runtimeModule.createSystems(scene, context);
logger.debug(`Systems created for: ${pluginId}`);
} catch (e) {
@@ -349,6 +355,23 @@ export class PluginManager implements IService {
}
}
// 第二阶段:系统创建完成后的回调(用于跨插件依赖连接)
// Phase 2: Post-creation callbacks (for cross-plugin dependency wiring)
for (const pluginId of sortedPlugins) {
const plugin = this.plugins.get(pluginId);
if (!plugin?.enabled || plugin.state === 'error') continue;
const runtimeModule = plugin.loader.runtimeModule;
if (runtimeModule?.onSystemsCreated) {
try {
runtimeModule.onSystemsCreated(scene, context);
logger.debug(`Systems wired for: ${pluginId}`);
} catch (e) {
logger.error(`Failed to wire systems for ${pluginId}:`, e);
}
}
}
logger.info('Systems created for scene');
}

View File

@@ -4,6 +4,21 @@ import type { FileActionHandler, FileCreationTemplate } from '../Plugin/IPluginL
// Re-export for backwards compatibility
export type { FileCreationTemplate } from '../Plugin/IPluginLoader';
/**
* 资产创建消息映射
* Asset creation message mapping
*
* 定义扩展名到创建消息的映射,用于 PropertyInspector 中的资产字段创建按钮
*/
export interface AssetCreationMapping {
/** 文件扩展名(包含点号,如 '.tilemap'| File extension (with dot) */
extension: string;
/** 创建资产时发送的消息名 | Message name to publish when creating asset */
createMessage: string;
/** 是否支持创建(可选,默认 true| Whether creation is supported */
canCreate?: boolean;
}
/**
* 文件操作注册表服务
*
@@ -12,6 +27,7 @@ export type { FileCreationTemplate } from '../Plugin/IPluginLoader';
export class FileActionRegistry implements IService {
private actionHandlers: Map<string, FileActionHandler[]> = new Map();
private creationTemplates: FileCreationTemplate[] = [];
private assetCreationMappings: Map<string, AssetCreationMapping> = new Map();
/**
* 注册文件操作处理器
@@ -110,12 +126,66 @@ export class FileActionRegistry implements IService {
return false;
}
/**
* 注册资产创建消息映射
* Register asset creation message mapping
*/
registerAssetCreationMapping(mapping: AssetCreationMapping): void {
const normalizedExt = mapping.extension.startsWith('.')
? mapping.extension.toLowerCase()
: `.${mapping.extension.toLowerCase()}`;
this.assetCreationMappings.set(normalizedExt, {
...mapping,
extension: normalizedExt
});
}
/**
* 注销资产创建消息映射
* Unregister asset creation message mapping
*/
unregisterAssetCreationMapping(extension: string): void {
const normalizedExt = extension.startsWith('.')
? extension.toLowerCase()
: `.${extension.toLowerCase()}`;
this.assetCreationMappings.delete(normalizedExt);
}
/**
* 获取扩展名对应的资产创建消息映射
* Get asset creation mapping for extension
*/
getAssetCreationMapping(extension: string): AssetCreationMapping | undefined {
const normalizedExt = extension.startsWith('.')
? extension.toLowerCase()
: `.${extension.toLowerCase()}`;
return this.assetCreationMappings.get(normalizedExt);
}
/**
* 检查扩展名是否支持创建资产
* Check if extension supports asset creation
*/
canCreateAsset(extension: string): boolean {
const mapping = this.getAssetCreationMapping(extension);
return mapping?.canCreate !== false;
}
/**
* 获取所有资产创建映射
* Get all asset creation mappings
*/
getAllAssetCreationMappings(): AssetCreationMapping[] {
return Array.from(this.assetCreationMappings.values());
}
/**
* 清空所有注册
*/
clear(): void {
this.actionHandlers.clear();
this.creationTemplates = [];
this.assetCreationMappings.clear();
}
/**

View File

@@ -9,6 +9,11 @@ const logger = createLogger('MessageHub');
*/
export type MessageHandler<T = any> = (data: T) => void | Promise<void>;
/**
* 请求处理器类型(支持返回值)
*/
export type RequestHandler<TRequest = any, TResponse = any> = (data: TRequest) => TResponse | Promise<TResponse>;
/**
* 消息订阅
*/
@@ -18,6 +23,14 @@ interface MessageSubscription {
once: boolean;
}
/**
* 请求订阅
*/
interface RequestSubscription {
topic: string;
handler: RequestHandler;
}
/**
* 消息总线
*
@@ -26,6 +39,7 @@ interface MessageSubscription {
@Injectable()
export class MessageHub implements IService {
private subscriptions: Map<string, MessageSubscription[]> = new Map();
private requestHandlers: Map<string, RequestSubscription> = new Map();
private subscriptionId: number = 0;
/**
@@ -207,11 +221,112 @@ export class MessageHub implements IService {
return subs ? subs.length : 0;
}
/**
* 注册请求处理器(用于请求-响应模式)
*
* @param topic - 请求主题
* @param handler - 请求处理器,可以返回响应数据
* @returns 取消注册的函数
*/
public onRequest<TRequest = any, TResponse = any>(
topic: string,
handler: RequestHandler<TRequest, TResponse>
): () => void {
if (this.requestHandlers.has(topic)) {
logger.warn(`Request handler for topic "${topic}" already exists, replacing...`);
}
const subscription: RequestSubscription = {
topic,
handler
};
this.requestHandlers.set(topic, subscription);
logger.debug(`Registered request handler for topic: ${topic}`);
return () => {
if (this.requestHandlers.get(topic) === subscription) {
this.requestHandlers.delete(topic);
logger.debug(`Unregistered request handler for topic: ${topic}`);
}
};
}
/**
* 发送请求并等待响应(请求-响应模式)
*
* @param topic - 请求主题
* @param data - 请求数据
* @param timeout - 超时时间(毫秒),默认 5000ms
* @returns 响应数据
* @throws 如果没有处理器或超时则抛出错误
*/
public async request<TRequest = any, TResponse = any>(
topic: string,
data?: TRequest,
timeout: number = 5000
): Promise<TResponse> {
const subscription = this.requestHandlers.get(topic);
if (!subscription) {
throw new Error(`No request handler registered for topic: ${topic}`);
}
logger.debug(`Sending request to topic: ${topic}`);
const timeoutPromise = new Promise<never>((_, reject) => {
setTimeout(() => {
reject(new Error(`Request to topic "${topic}" timed out after ${timeout}ms`));
}, timeout);
});
const responsePromise = Promise.resolve(subscription.handler(data));
return Promise.race([responsePromise, timeoutPromise]);
}
/**
* 尝试发送请求(如果有处理器则发送,否则返回 undefined
*
* @param topic - 请求主题
* @param data - 请求数据
* @param timeout - 超时时间(毫秒),默认 5000ms
* @returns 响应数据或 undefined
*/
public async tryRequest<TRequest = any, TResponse = any>(
topic: string,
data?: TRequest,
timeout: number = 5000
): Promise<TResponse | undefined> {
if (!this.requestHandlers.has(topic)) {
logger.debug(`No request handler for topic: ${topic}, returning undefined`);
return undefined;
}
try {
return await this.request<TRequest, TResponse>(topic, data, timeout);
} catch (error) {
logger.warn(`Request to topic "${topic}" failed:`, error);
return undefined;
}
}
/**
* 检查是否有请求处理器
*
* @param topic - 请求主题
* @returns 是否有处理器
*/
public hasRequestHandler(topic: string): boolean {
return this.requestHandlers.has(topic);
}
/**
* 释放资源
*/
public dispose(): void {
this.subscriptions.clear();
this.requestHandlers.clear();
logger.info('MessageHub disposed');
}
}

View File

@@ -1,6 +1,6 @@
import { Injectable, IService } from '@esengine/ecs-framework';
export type SettingType = 'string' | 'number' | 'boolean' | 'select' | 'color' | 'range' | 'pluginList';
export type SettingType = 'string' | 'number' | 'boolean' | 'select' | 'color' | 'range' | 'pluginList' | 'collisionMatrix';
export interface SettingOption {
label: string;
@@ -24,6 +24,8 @@ export interface SettingDescriptor {
min?: number;
max?: number;
step?: number;
/** 自定义渲染器组件(用于 collisionMatrix 等复杂类型) */
customRenderer?: React.ComponentType<any>;
}
export interface SettingSection {