refactor: reorganize package structure and decouple framework packages (#338)

* refactor: reorganize package structure and decouple framework packages

## Package Structure Reorganization
- Reorganized 55 packages into categorized subdirectories:
  - packages/framework/ - Generic framework (Laya/Cocos compatible)
  - packages/engine/ - ESEngine core modules
  - packages/rendering/ - Rendering modules (WASM dependent)
  - packages/physics/ - Physics modules
  - packages/streaming/ - World streaming
  - packages/network-ext/ - Network extensions
  - packages/editor/ - Editor framework and plugins
  - packages/rust/ - Rust WASM engine
  - packages/tools/ - Build tools and SDK

## Framework Package Decoupling
- Decoupled behavior-tree and blueprint packages from ESEngine dependencies
- Created abstracted interfaces (IBTAssetManager, IBehaviorTreeAssetContent)
- ESEngine-specific code moved to esengine/ subpath exports
- Framework packages now usable with Cocos/Laya without ESEngine

## CI Configuration
- Updated CI to only type-check and lint framework packages
- Added type-check:framework and lint:framework scripts

## Breaking Changes
- Package import paths changed due to directory reorganization
- ESEngine integrations now use subpath imports (e.g., '@esengine/behavior-tree/esengine')

* fix: update es-engine file path after directory reorganization

* docs: update README to focus on framework over engine

* ci: only build framework packages, remove Rust/WASM dependencies

* fix: remove esengine subpath from behavior-tree and blueprint builds

ESEngine integration code will only be available in full engine builds.
Framework packages are now purely engine-agnostic.

* fix: move network-protocols to framework, build both in CI

* fix: update workflow paths from packages/core to packages/framework/core

* fix: exclude esengine folder from type-check in behavior-tree and blueprint

* fix: update network tsconfig references to new paths

* fix: add test:ci:framework to only test framework packages in CI

* fix: only build core and math npm packages in CI

* fix: exclude test files from CodeQL and fix string escaping security issue
This commit is contained in:
YHH
2025-12-26 14:50:35 +08:00
committed by GitHub
parent a84ff902e4
commit 155411e743
1936 changed files with 4147 additions and 11578 deletions

View File

@@ -0,0 +1,163 @@
/**
* Platform Adapter Interface
* 平台适配器接口
*
* 定义不同平台(编辑器、浏览器、原生)需要实现的适配器接口
* Defines the adapter interface that different platforms need to implement
*/
import type { IPlatformInputSubsystem } from '@esengine/platform-common';
/**
* 资源路径解析器
* 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;
/**
* 获取输入子系统
* Get input subsystem
*
* 返回平台特定的输入子系统实现
* Returns platform-specific input subsystem implementation
*/
getInputSubsystem?(): IPlatformInputSubsystem | null;
/**
* 释放资源
* 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;
}
}