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,190 @@
/**
* @zh 运行时模式枚举
* @en Runtime mode enumeration
*
* @zh 定义游戏运行时的不同运行模式,每种模式有不同的系统启用策略
* @en Defines different runtime modes with different system enabling strategies
*/
export enum RuntimeMode {
/**
* @zh 编辑器静态模式 - 场景编辑状态
* @en Editor static mode - scene editing state
*
* @zh 特性:
* - 所有游戏逻辑系统禁用(物理、行为树、动画)
* - 显示编辑器 UIGrid、Gizmo、坐标轴
* - 组件生命周期回调被延迟onAwake/onStart 不触发)
* - 输入系统禁用(避免与编辑器操作冲突)
*
* @en Features:
* - All game logic systems disabled (physics, behavior tree, animation)
* - Editor UI visible (grid, gizmos, axis indicator)
* - Component lifecycle callbacks deferred (onAwake/onStart not triggered)
* - Input system disabled (avoid conflict with editor operations)
*/
EditorStatic = 'editor-static',
/**
* @zh 编辑器预览模式 - 在编辑器中播放游戏
* @en Editor preview mode - play game within editor
*
* @zh 特性:
* - 游戏逻辑系统启用(物理、行为树、动画)
* - 可选显示 Gizmo用于调试
* - 组件生命周期回调触发
* - 输入系统可选启用
* - 场景快照用于恢复
*
* @en Features:
* - Game logic systems enabled (physics, behavior tree, animation)
* - Gizmos optionally visible (for debugging)
* - Component lifecycle callbacks triggered
* - Input system optionally enabled
* - Scene snapshot for restoration
*/
EditorPreview = 'editor-preview',
/**
* @zh 独立运行模式 - Web/桌面/小程序完整运行
* @en Standalone mode - full Web/desktop/mini-program runtime
*
* @zh 特性:
* - 所有系统启用
* - 无编辑器 UI
* - 完整的输入处理
* - 生产环境配置
*
* @en Features:
* - All systems enabled
* - No editor UI
* - Full input handling
* - Production configuration
*/
Standalone = 'standalone'
}
/**
* @zh 运行模式配置
* @en Runtime mode configuration
*/
export interface RuntimeModeConfig {
/**
* @zh 是否启用物理系统
* @en Whether to enable physics system
*/
enablePhysics: boolean;
/**
* @zh 是否启用行为树系统
* @en Whether to enable behavior tree system
*/
enableBehaviorTree: boolean;
/**
* @zh 是否启用动画系统
* @en Whether to enable animation system
*/
enableAnimation: boolean;
/**
* @zh 是否启用输入系统
* @en Whether to enable input system
*/
enableInput: boolean;
/**
* @zh 是否显示网格
* @en Whether to show grid
*/
showGrid: boolean;
/**
* @zh 是否显示 Gizmo
* @en Whether to show gizmos
*/
showGizmos: boolean;
/**
* @zh 是否显示坐标轴指示器
* @en Whether to show axis indicator
*/
showAxisIndicator: boolean;
/**
* @zh 是否触发组件生命周期回调
* @en Whether to trigger component lifecycle callbacks
*/
triggerLifecycle: boolean;
/**
* @zh 是否为编辑器环境(影响资产加载等)
* @en Whether in editor environment (affects asset loading, etc.)
*/
isEditorEnvironment: boolean;
}
/**
* @zh 获取指定模式的默认配置
* @en Get default configuration for specified mode
*
* @param mode - @zh 运行模式 @en Runtime mode
* @returns @zh 模式配置 @en Mode configuration
*/
export function getRuntimeModeConfig(mode: RuntimeMode): RuntimeModeConfig {
switch (mode) {
case RuntimeMode.EditorStatic:
return {
enablePhysics: false,
enableBehaviorTree: false,
enableAnimation: false,
enableInput: false,
showGrid: true,
showGizmos: true,
showAxisIndicator: true,
triggerLifecycle: false,
isEditorEnvironment: true
};
case RuntimeMode.EditorPreview:
return {
enablePhysics: true,
enableBehaviorTree: true,
enableAnimation: true,
enableInput: true,
showGrid: false,
showGizmos: false, // 预览时默认隐藏,可通过设置开启
showAxisIndicator: false,
triggerLifecycle: true,
isEditorEnvironment: true
};
case RuntimeMode.Standalone:
return {
enablePhysics: true,
enableBehaviorTree: true,
enableAnimation: true,
enableInput: true,
showGrid: false,
showGizmos: false,
showAxisIndicator: false,
triggerLifecycle: true,
isEditorEnvironment: false
};
}
}
/**
* @zh 检查模式是否为编辑器模式
* @en Check if mode is an editor mode
*/
export function isEditorMode(mode: RuntimeMode): boolean {
return mode === RuntimeMode.EditorStatic || mode === RuntimeMode.EditorPreview;
}
/**
* @zh 检查模式是否应启用游戏逻辑
* @en Check if mode should enable game logic
*/
export function shouldEnableGameLogic(mode: RuntimeMode): boolean {
return mode === RuntimeMode.EditorPreview || mode === RuntimeMode.Standalone;
}