2025-12-08 21:10:57 +08:00
|
|
|
|
/**
|
2025-12-13 19:44:08 +08:00
|
|
|
|
* 插件服务令牌(engine-core 特定)
|
|
|
|
|
|
* Plugin Service Tokens (engine-core specific)
|
2025-12-08 21:10:57 +08:00
|
|
|
|
*
|
2025-12-13 19:44:08 +08:00
|
|
|
|
* 核心类型 (PluginServiceRegistry, createServiceToken, ServiceToken) 从 @esengine/ecs-framework 导入。
|
|
|
|
|
|
* 这里只定义 engine-core 特有的服务令牌。
|
2025-12-08 21:10:57 +08:00
|
|
|
|
*
|
2025-12-13 19:44:08 +08:00
|
|
|
|
* Core types (PluginServiceRegistry, createServiceToken, ServiceToken) are imported from @esengine/ecs-framework.
|
|
|
|
|
|
* This file only defines engine-core specific service tokens.
|
2025-12-08 21:10:57 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
2025-12-13 19:44:08 +08:00
|
|
|
|
import { createServiceToken } from '@esengine/ecs-framework';
|
|
|
|
|
|
|
|
|
|
|
|
// Re-export from ecs-framework for backwards compatibility
|
|
|
|
|
|
export { PluginServiceRegistry, createServiceToken, type ServiceToken } from '@esengine/ecs-framework';
|
|
|
|
|
|
|
2025-12-08 21:10:57 +08:00
|
|
|
|
// ============================================================================
|
2025-12-13 19:44:08 +08:00
|
|
|
|
// engine-core 内部 Token | engine-core Internal Tokens
|
2025-12-08 21:10:57 +08:00
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-12-13 19:44:08 +08:00
|
|
|
|
* Transform 组件类型 | Transform component type
|
2025-12-08 21:10:57 +08:00
|
|
|
|
*
|
2025-12-13 19:44:08 +08:00
|
|
|
|
* 使用 any 类型以允许各模块使用自己的 ITransformComponent 接口定义。
|
|
|
|
|
|
* Using any type to allow modules to use their own ITransformComponent interface definition.
|
2025-12-08 21:10:57 +08:00
|
|
|
|
*/
|
2025-12-13 19:44:08 +08:00
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
|
|
export const TransformTypeToken = createServiceToken<new (...args: any[]) => any>('transformType');
|
2025-12-08 21:10:57 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2025-12-13 19:44:08 +08:00
|
|
|
|
* Canvas 元素的服务令牌
|
|
|
|
|
|
* Service token for the canvas element
|
2025-12-08 21:10:57 +08:00
|
|
|
|
*/
|
2025-12-13 19:44:08 +08:00
|
|
|
|
export const CanvasElementToken = createServiceToken<HTMLCanvasElement>('canvasElement');
|
2025-12-08 21:10:57 +08:00
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
2025-12-13 19:44:08 +08:00
|
|
|
|
// 引擎桥接接口 | Engine Bridge Interface
|
2025-12-08 21:10:57 +08:00
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-12-13 19:44:08 +08:00
|
|
|
|
* 引擎桥接接口
|
|
|
|
|
|
* Engine bridge interface
|
2025-12-08 21:10:57 +08:00
|
|
|
|
*
|
2025-12-13 19:44:08 +08:00
|
|
|
|
* 定义 WASM 引擎桥接的核心契约,供各模块使用。
|
|
|
|
|
|
* Defines the core contract of WASM engine bridge for modules to use.
|
2025-12-08 21:10:57 +08:00
|
|
|
|
*/
|
2025-12-13 19:44:08 +08:00
|
|
|
|
export interface IEngineBridge {
|
|
|
|
|
|
/** 加载纹理 | Load texture */
|
|
|
|
|
|
loadTexture(id: number, url: string): Promise<void>;
|
2025-12-08 21:10:57 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2025-12-13 19:44:08 +08:00
|
|
|
|
* 屏幕坐标转世界坐标
|
|
|
|
|
|
* Screen to world coordinate conversion
|
2025-12-08 21:10:57 +08:00
|
|
|
|
*/
|
2025-12-13 19:44:08 +08:00
|
|
|
|
screenToWorld(screenX: number, screenY: number): { x: number; y: number };
|
2025-12-08 21:10:57 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2025-12-13 19:44:08 +08:00
|
|
|
|
* 世界坐标转屏幕坐标
|
|
|
|
|
|
* World to screen coordinate conversion
|
2025-12-08 21:10:57 +08:00
|
|
|
|
*/
|
2025-12-13 19:44:08 +08:00
|
|
|
|
worldToScreen(worldX: number, worldY: number): { x: number; y: number };
|
2025-12-08 21:10:57 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2025-12-13 19:44:08 +08:00
|
|
|
|
* 设置清除颜色
|
|
|
|
|
|
* Set clear color
|
2025-12-08 21:10:57 +08:00
|
|
|
|
*/
|
2025-12-13 19:44:08 +08:00
|
|
|
|
setClearColor(r: number, g: number, b: number, a: number): void;
|
2025-12-16 12:46:14 +08:00
|
|
|
|
|
|
|
|
|
|
// ===== Texture State API (Optional) =====
|
|
|
|
|
|
// ===== 纹理状态 API(可选)=====
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取纹理加载状态
|
|
|
|
|
|
* Get texture loading state
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param id 纹理 ID | Texture ID
|
|
|
|
|
|
* @returns 状态字符串: 'loading', 'ready', 或 'failed:reason'
|
|
|
|
|
|
* State string: 'loading', 'ready', or 'failed:reason'
|
|
|
|
|
|
*/
|
|
|
|
|
|
getTextureState?(id: number): string;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 检查纹理是否就绪
|
|
|
|
|
|
* Check if texture is ready for rendering
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param id 纹理 ID | Texture ID
|
|
|
|
|
|
* @returns 纹理数据已加载则返回 true | true if texture data is loaded
|
|
|
|
|
|
*/
|
|
|
|
|
|
isTextureReady?(id: number): boolean;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取正在加载的纹理数量
|
|
|
|
|
|
* Get count of textures currently loading
|
|
|
|
|
|
*
|
|
|
|
|
|
* @returns 处于加载状态的纹理数量 | Number of textures in loading state
|
|
|
|
|
|
*/
|
|
|
|
|
|
getTextureLoadingCount?(): number;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 异步加载纹理(等待完成)
|
|
|
|
|
|
* Load texture asynchronously (wait for completion)
|
|
|
|
|
|
*
|
|
|
|
|
|
* 与 loadTexture 不同,此方法会等待纹理实际加载完成。
|
|
|
|
|
|
* Unlike loadTexture, this method waits until texture is actually loaded.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param id 纹理 ID | Texture ID
|
|
|
|
|
|
* @param url 图片 URL | Image URL
|
|
|
|
|
|
* @returns 纹理就绪时解析的 Promise | Promise that resolves when texture is ready
|
|
|
|
|
|
*/
|
|
|
|
|
|
loadTextureAsync?(id: number, url: string): Promise<void>;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 等待所有加载中的纹理完成
|
|
|
|
|
|
* Wait for all loading textures to complete
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param timeout 最大等待时间(毫秒,默认30000)| Max wait time in ms (default 30000)
|
|
|
|
|
|
* @returns 所有纹理加载完成时解析 | Resolves when all textures are loaded
|
|
|
|
|
|
*/
|
|
|
|
|
|
waitForAllTextures?(timeout?: number): Promise<void>;
|
2025-12-08 21:10:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-12-13 19:44:08 +08:00
|
|
|
|
* 引擎桥接服务令牌
|
|
|
|
|
|
* Engine bridge service token
|
2025-12-08 21:10:57 +08:00
|
|
|
|
*/
|
2025-12-13 19:44:08 +08:00
|
|
|
|
export const EngineBridgeToken = createServiceToken<IEngineBridge>('engineBridge');
|