Files
esengine/packages/runtime-core/src/IPlatformAdapter.ts

153 lines
3.5 KiB
TypeScript
Raw Normal View History

/**
* Platform Adapter Interface
*
*
*
* Defines the adapter interface that different platforms need to implement
*/
/**
*
* Asset path resolver
*/
export interface IPathResolver {
/**
* URL
* Resolve asset path to a loadable URL
*/
resolve(path: string): string;
}
/**
*
* Platform capability flags
*/
export interface PlatformCapabilities {
/** 是否支持文件系统访问 / Supports file system access */
fileSystem: boolean;
/** 是否支持热重载 / Supports hot reload */
hotReload: boolean;
/** 是否支持 Gizmo 显示 / Supports gizmo display */
gizmos: boolean;
/** 是否支持网格显示 / Supports grid display */
grid: boolean;
/** 是否支持场景编辑 / Supports scene editing */
sceneEditing: boolean;
}
/**
*
* Platform adapter configuration
*/
export interface PlatformAdapterConfig {
/** Canvas 元素 ID */
canvasId: string;
/** 初始宽度 */
width?: number;
/** 初始高度 */
height?: number;
/** 是否为编辑器模式 */
isEditor?: boolean;
}
/**
*
* Platform adapter interface
*
*
* Different platforms implement this interface to provide platform-specific functionality
*/
export interface IPlatformAdapter {
/**
*
* Platform name
*/
readonly name: string;
/**
*
* Platform capabilities
*/
readonly capabilities: PlatformCapabilities;
/**
*
* Path resolver
*/
readonly pathResolver: IPathResolver;
/**
*
* Initialize platform
*/
initialize(config: PlatformAdapterConfig): Promise<void>;
/**
* WASM
* Get WASM module
*
* WASM
* Different platforms may load WASM in different ways
*/
getWasmModule(): Promise<any>;
/**
* Canvas
* Get canvas element
*/
getCanvas(): HTMLCanvasElement | null;
/**
*
* Resize viewport
*/
resize(width: number, height: number): void;
/**
*
* Get current viewport size
*/
getViewportSize(): { width: number; height: number };
/**
*
* Whether in editor mode
*/
isEditorMode(): boolean;
/**
*
* Set whether to show grid (only effective in editor mode)
*/
setShowGrid?(show: boolean): void;
/**
* Gizmos
* Set whether to show gizmos (only effective in editor mode)
*/
setShowGizmos?(show: boolean): void;
/**
*
* Dispose resources
*/
dispose(): void;
}
/**
*
* Default path resolver (returns path as-is)
*/
export class DefaultPathResolver implements IPathResolver {
resolve(path: string): string {
// 如果已经是 URL直接返回
if (path.startsWith('http://') ||
path.startsWith('https://') ||
path.startsWith('data:') ||
path.startsWith('blob:')) {
return path;
}
return path;
}
}