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:
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user