Compare commits
5 Commits
@esengine/
...
@esengine/
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
094133a71a | ||
|
|
3e5b7783be | ||
|
|
ebcb4d00a8 | ||
|
|
d2af9caae9 | ||
|
|
bb696c6a60 |
Submodule examples/lawn-mower-demo updated: 5a4976b192...6c5d682f3a
@@ -1,5 +1,37 @@
|
|||||||
# @esengine/behavior-tree
|
# @esengine/behavior-tree
|
||||||
|
|
||||||
|
## 4.1.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`3e5b778`](https://github.com/esengine/esengine/commit/3e5b7783beec08e247f7525184935401923ecde8)]:
|
||||||
|
- @esengine/ecs-framework@2.7.1
|
||||||
|
|
||||||
|
## 4.1.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- [#400](https://github.com/esengine/esengine/pull/400) [`d2af9ca`](https://github.com/esengine/esengine/commit/d2af9caae9d5620c5f690272ab80dc246e9b7e10) Thanks [@esengine](https://github.com/esengine)! - feat(behavior-tree): add pure BehaviorTreePlugin class for Cocos/Laya integration
|
||||||
|
- Added `BehaviorTreePlugin` class that only depends on `@esengine/ecs-framework`
|
||||||
|
- Implements `IPlugin` interface with `install()`, `uninstall()`, and `setupScene()` methods
|
||||||
|
- Removed `esengine/` subdirectory that incorrectly depended on `@esengine/engine-core`
|
||||||
|
- Updated package documentation with correct usage examples
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { Core, Scene } from '@esengine/ecs-framework';
|
||||||
|
import { BehaviorTreePlugin, BehaviorTreeBuilder, BehaviorTreeStarter } from '@esengine/behavior-tree';
|
||||||
|
|
||||||
|
Core.create();
|
||||||
|
const plugin = new BehaviorTreePlugin();
|
||||||
|
await Core.installPlugin(plugin);
|
||||||
|
|
||||||
|
const scene = new Scene();
|
||||||
|
plugin.setupScene(scene);
|
||||||
|
Core.setScene(scene);
|
||||||
|
```
|
||||||
|
|
||||||
## 4.0.0
|
## 4.0.0
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@esengine/behavior-tree",
|
"name": "@esengine/behavior-tree",
|
||||||
"version": "4.0.0",
|
"version": "4.1.1",
|
||||||
"description": "ECS-based AI behavior tree system - works with any ECS framework (ESEngine, Cocos, Laya, etc.)",
|
"description": "ECS-based AI behavior tree system - works with any ECS framework (ESEngine, Cocos, Laya, etc.)",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"module": "dist/index.js",
|
"module": "dist/index.js",
|
||||||
|
|||||||
118
packages/framework/behavior-tree/src/BehaviorTreePlugin.ts
Normal file
118
packages/framework/behavior-tree/src/BehaviorTreePlugin.ts
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
import type { Core, ServiceContainer, IPlugin, IScene } from '@esengine/ecs-framework';
|
||||||
|
import { BehaviorTreeExecutionSystem } from './execution/BehaviorTreeExecutionSystem';
|
||||||
|
import { BehaviorTreeAssetManager } from './execution/BehaviorTreeAssetManager';
|
||||||
|
import { GlobalBlackboardService } from './Services/GlobalBlackboardService';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @zh 行为树插件
|
||||||
|
* @en Behavior Tree Plugin
|
||||||
|
*
|
||||||
|
* @zh 为 ECS 框架提供行为树支持的插件。
|
||||||
|
* 可与任何基于 @esengine/ecs-framework 的引擎集成(Cocos、Laya、Node.js 等)。
|
||||||
|
*
|
||||||
|
* @en Plugin that provides behavior tree support for ECS framework.
|
||||||
|
* Can be integrated with any engine based on @esengine/ecs-framework (Cocos, Laya, Node.js, etc.).
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```typescript
|
||||||
|
* import { Core, Scene } from '@esengine/ecs-framework';
|
||||||
|
* import { BehaviorTreePlugin, BehaviorTreeBuilder, BehaviorTreeStarter } from '@esengine/behavior-tree';
|
||||||
|
*
|
||||||
|
* // Initialize
|
||||||
|
* Core.create();
|
||||||
|
* const plugin = new BehaviorTreePlugin();
|
||||||
|
* await Core.installPlugin(plugin);
|
||||||
|
*
|
||||||
|
* // Setup scene
|
||||||
|
* const scene = new Scene();
|
||||||
|
* plugin.setupScene(scene);
|
||||||
|
* Core.setScene(scene);
|
||||||
|
*
|
||||||
|
* // Create and start behavior tree
|
||||||
|
* const tree = BehaviorTreeBuilder.create('MyAI')
|
||||||
|
* .selector('Root')
|
||||||
|
* .log('Hello from behavior tree!')
|
||||||
|
* .end()
|
||||||
|
* .build();
|
||||||
|
*
|
||||||
|
* const entity = scene.createEntity('AIEntity');
|
||||||
|
* BehaviorTreeStarter.start(entity, tree);
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export class BehaviorTreePlugin implements IPlugin {
|
||||||
|
/**
|
||||||
|
* @zh 插件名称
|
||||||
|
* @en Plugin name
|
||||||
|
*/
|
||||||
|
readonly name = '@esengine/behavior-tree';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @zh 插件版本
|
||||||
|
* @en Plugin version
|
||||||
|
*/
|
||||||
|
readonly version = '1.0.0';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @zh 插件依赖
|
||||||
|
* @en Plugin dependencies
|
||||||
|
*/
|
||||||
|
readonly dependencies: readonly string[] = [];
|
||||||
|
|
||||||
|
private _services: ServiceContainer | null = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @zh 安装插件
|
||||||
|
* @en Install plugin
|
||||||
|
*
|
||||||
|
* @param _core - Core 实例
|
||||||
|
* @param services - 服务容器
|
||||||
|
*/
|
||||||
|
install(_core: Core, services: ServiceContainer): void {
|
||||||
|
this._services = services;
|
||||||
|
|
||||||
|
// Register services
|
||||||
|
if (!services.isRegistered(GlobalBlackboardService)) {
|
||||||
|
services.registerSingleton(GlobalBlackboardService);
|
||||||
|
}
|
||||||
|
if (!services.isRegistered(BehaviorTreeAssetManager)) {
|
||||||
|
services.registerSingleton(BehaviorTreeAssetManager);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @zh 卸载插件
|
||||||
|
* @en Uninstall plugin
|
||||||
|
*/
|
||||||
|
uninstall(): void {
|
||||||
|
if (this._services) {
|
||||||
|
const assetManager = this._services.tryResolve(BehaviorTreeAssetManager);
|
||||||
|
if (assetManager) {
|
||||||
|
assetManager.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
const blackboardService = this._services.tryResolve(GlobalBlackboardService);
|
||||||
|
if (blackboardService) {
|
||||||
|
blackboardService.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this._services = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @zh 设置场景,添加行为树执行系统
|
||||||
|
* @en Setup scene, add behavior tree execution system
|
||||||
|
*
|
||||||
|
* @param scene - 要设置的场景
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```typescript
|
||||||
|
* const scene = new Scene();
|
||||||
|
* plugin.setupScene(scene);
|
||||||
|
* Core.setScene(scene);
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
setupScene(scene: IScene): void {
|
||||||
|
const system = new BehaviorTreeExecutionSystem(this._services ?? undefined);
|
||||||
|
scene.addSystem(system);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
/**
|
|
||||||
* @zh ESEngine 资产加载器
|
|
||||||
* @en ESEngine asset loader
|
|
||||||
*
|
|
||||||
* @zh 实现 IAssetLoader 接口,用于通过 AssetManager 加载行为树文件。
|
|
||||||
* 此文件仅在使用 ESEngine 时需要。
|
|
||||||
*
|
|
||||||
* @en Implements IAssetLoader interface for loading behavior tree files via AssetManager.
|
|
||||||
* This file is only needed when using ESEngine.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import type {
|
|
||||||
IAssetLoader,
|
|
||||||
IAssetParseContext,
|
|
||||||
IAssetContent,
|
|
||||||
AssetContentType
|
|
||||||
} from '@esengine/asset-system';
|
|
||||||
import { Core } from '@esengine/ecs-framework';
|
|
||||||
import { BehaviorTreeData } from '../execution/BehaviorTreeData';
|
|
||||||
import { BehaviorTreeAssetManager } from '../execution/BehaviorTreeAssetManager';
|
|
||||||
import { EditorToBehaviorTreeDataConverter } from '../Serialization/EditorToBehaviorTreeDataConverter';
|
|
||||||
import { BehaviorTreeAssetType } from '../constants';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @zh 行为树资产接口
|
|
||||||
* @en Behavior tree asset interface
|
|
||||||
*/
|
|
||||||
export interface IBehaviorTreeAsset {
|
|
||||||
/** @zh 行为树数据 @en Behavior tree data */
|
|
||||||
data: BehaviorTreeData;
|
|
||||||
/** @zh 文件路径 @en File path */
|
|
||||||
path: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @zh 行为树加载器
|
|
||||||
* @en Behavior tree loader implementing IAssetLoader interface
|
|
||||||
*/
|
|
||||||
export class BehaviorTreeLoader implements IAssetLoader<IBehaviorTreeAsset> {
|
|
||||||
readonly supportedType = BehaviorTreeAssetType;
|
|
||||||
readonly supportedExtensions = ['.btree'];
|
|
||||||
readonly contentType: AssetContentType = 'text';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @zh 从内容解析行为树资产
|
|
||||||
* @en Parse behavior tree asset from content
|
|
||||||
*/
|
|
||||||
async parse(content: IAssetContent, context: IAssetParseContext): Promise<IBehaviorTreeAsset> {
|
|
||||||
if (!content.text) {
|
|
||||||
throw new Error('Behavior tree content is empty');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert to runtime data
|
|
||||||
const treeData = EditorToBehaviorTreeDataConverter.fromEditorJSON(content.text);
|
|
||||||
|
|
||||||
// Use file path as ID
|
|
||||||
const assetPath = context.metadata.path;
|
|
||||||
treeData.id = assetPath;
|
|
||||||
|
|
||||||
// Also register to BehaviorTreeAssetManager for legacy code
|
|
||||||
const btAssetManager = Core.services.tryResolve(BehaviorTreeAssetManager);
|
|
||||||
if (btAssetManager) {
|
|
||||||
btAssetManager.loadAsset(treeData);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
data: treeData,
|
|
||||||
path: assetPath
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @zh 释放资产
|
|
||||||
* @en Dispose asset
|
|
||||||
*/
|
|
||||||
dispose(asset: IBehaviorTreeAsset): void {
|
|
||||||
const btAssetManager = Core.services.tryResolve(BehaviorTreeAssetManager);
|
|
||||||
if (btAssetManager && asset.data) {
|
|
||||||
btAssetManager.unloadAsset(asset.data.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
/**
|
|
||||||
* @zh ESEngine 集成模块
|
|
||||||
* @en ESEngine integration module
|
|
||||||
*
|
|
||||||
* @zh 此文件包含与 ESEngine 引擎核心集成的代码。
|
|
||||||
* 使用 Cocos/Laya 等其他引擎时不需要此文件。
|
|
||||||
*
|
|
||||||
* @en This file contains code for integrating with ESEngine engine-core.
|
|
||||||
* Not needed when using other engines like Cocos/Laya.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import type { IScene, ServiceContainer, IComponentRegistry } from '@esengine/ecs-framework';
|
|
||||||
import type { IRuntimeModule, IRuntimePlugin, ModuleManifest, SystemContext } from '@esengine/engine-core';
|
|
||||||
import { AssetManagerToken } from '@esengine/asset-system';
|
|
||||||
|
|
||||||
import { BehaviorTreeRuntimeComponent } from '../execution/BehaviorTreeRuntimeComponent';
|
|
||||||
import { BehaviorTreeExecutionSystem } from '../execution/BehaviorTreeExecutionSystem';
|
|
||||||
import { BehaviorTreeAssetManager } from '../execution/BehaviorTreeAssetManager';
|
|
||||||
import { GlobalBlackboardService } from '../Services/GlobalBlackboardService';
|
|
||||||
import { BehaviorTreeLoader } from './BehaviorTreeLoader';
|
|
||||||
import { BehaviorTreeAssetType } from '../constants';
|
|
||||||
import { BehaviorTreeSystemToken } from '../tokens';
|
|
||||||
|
|
||||||
// Re-export tokens for ESEngine users
|
|
||||||
export { BehaviorTreeSystemToken } from '../tokens';
|
|
||||||
|
|
||||||
class BehaviorTreeRuntimeModule implements IRuntimeModule {
|
|
||||||
private _loaderRegistered = false;
|
|
||||||
|
|
||||||
registerComponents(registry: IComponentRegistry): void {
|
|
||||||
registry.register(BehaviorTreeRuntimeComponent);
|
|
||||||
}
|
|
||||||
|
|
||||||
registerServices(services: ServiceContainer): void {
|
|
||||||
if (!services.isRegistered(GlobalBlackboardService)) {
|
|
||||||
services.registerSingleton(GlobalBlackboardService);
|
|
||||||
}
|
|
||||||
if (!services.isRegistered(BehaviorTreeAssetManager)) {
|
|
||||||
services.registerSingleton(BehaviorTreeAssetManager);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
createSystems(scene: IScene, context: SystemContext): void {
|
|
||||||
// Get dependencies from service registry
|
|
||||||
const assetManager = context.services.get(AssetManagerToken);
|
|
||||||
|
|
||||||
if (!this._loaderRegistered && assetManager) {
|
|
||||||
assetManager.registerLoader(BehaviorTreeAssetType, new BehaviorTreeLoader());
|
|
||||||
this._loaderRegistered = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use ECS service container from context.services
|
|
||||||
const ecsServices = (context as { ecsServices?: ServiceContainer }).ecsServices;
|
|
||||||
const behaviorTreeSystem = new BehaviorTreeExecutionSystem(ecsServices);
|
|
||||||
|
|
||||||
if (assetManager) {
|
|
||||||
behaviorTreeSystem.setAssetManager(assetManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (context.isEditor) {
|
|
||||||
behaviorTreeSystem.enabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
scene.addSystem(behaviorTreeSystem);
|
|
||||||
|
|
||||||
// Register service to service registry
|
|
||||||
context.services.register(BehaviorTreeSystemToken, behaviorTreeSystem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const manifest: ModuleManifest = {
|
|
||||||
id: 'behavior-tree',
|
|
||||||
name: '@esengine/behavior-tree',
|
|
||||||
displayName: 'Behavior Tree',
|
|
||||||
version: '1.0.0',
|
|
||||||
description: 'AI behavior tree system',
|
|
||||||
category: 'AI',
|
|
||||||
icon: 'GitBranch',
|
|
||||||
isCore: false,
|
|
||||||
defaultEnabled: false,
|
|
||||||
isEngineModule: true,
|
|
||||||
canContainContent: true,
|
|
||||||
dependencies: ['core'],
|
|
||||||
exports: { components: ['BehaviorTreeComponent'] },
|
|
||||||
editorPackage: '@esengine/behavior-tree-editor'
|
|
||||||
};
|
|
||||||
|
|
||||||
export const BehaviorTreePlugin: IRuntimePlugin = {
|
|
||||||
manifest,
|
|
||||||
runtimeModule: new BehaviorTreeRuntimeModule()
|
|
||||||
};
|
|
||||||
|
|
||||||
export { BehaviorTreeRuntimeModule };
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
/**
|
|
||||||
* @zh ESEngine 集成入口
|
|
||||||
* @en ESEngine integration entry point
|
|
||||||
*
|
|
||||||
* @zh 此模块包含与 ESEngine 引擎核心集成所需的所有代码。
|
|
||||||
* 使用 Cocos/Laya 等其他引擎时,只需导入主模块即可。
|
|
||||||
*
|
|
||||||
* @en This module contains all code required for ESEngine engine-core integration.
|
|
||||||
* When using other engines like Cocos/Laya, just import the main module.
|
|
||||||
*
|
|
||||||
* @example ESEngine 使用方式 / ESEngine usage:
|
|
||||||
* ```typescript
|
|
||||||
* import { BehaviorTreePlugin } from '@esengine/behavior-tree/esengine';
|
|
||||||
*
|
|
||||||
* // Register with ESEngine plugin system
|
|
||||||
* engine.registerPlugin(BehaviorTreePlugin);
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* @example Cocos/Laya 使用方式 / Cocos/Laya usage:
|
|
||||||
* ```typescript
|
|
||||||
* import {
|
|
||||||
* BehaviorTreeAssetManager,
|
|
||||||
* BehaviorTreeExecutionSystem
|
|
||||||
* } from '@esengine/behavior-tree';
|
|
||||||
*
|
|
||||||
* // Load behavior tree from JSON
|
|
||||||
* const assetManager = new BehaviorTreeAssetManager();
|
|
||||||
* assetManager.loadFromEditorJSON(jsonContent);
|
|
||||||
*
|
|
||||||
* // Add system to your ECS world
|
|
||||||
* world.addSystem(new BehaviorTreeExecutionSystem());
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Runtime module and plugin
|
|
||||||
export { BehaviorTreeRuntimeModule, BehaviorTreePlugin, BehaviorTreeSystemToken } from './BehaviorTreeRuntimeModule';
|
|
||||||
|
|
||||||
// Asset loader for ESEngine asset-system
|
|
||||||
export { BehaviorTreeLoader, type IBehaviorTreeAsset } from './BehaviorTreeLoader';
|
|
||||||
@@ -4,32 +4,44 @@
|
|||||||
* @zh AI 行为树系统,支持运行时执行和可视化编辑
|
* @zh AI 行为树系统,支持运行时执行和可视化编辑
|
||||||
* @en AI Behavior Tree System with runtime execution and visual editor support
|
* @en AI Behavior Tree System with runtime execution and visual editor support
|
||||||
*
|
*
|
||||||
* @zh 此包是通用的行为树实现,可以与任何 ECS 框架配合使用。
|
* @zh 此包是通用的行为树实现,可以与任何基于 @esengine/ecs-framework 的引擎集成
|
||||||
* 对于 ESEngine 集成,请从 '@esengine/behavior-tree/esengine' 导入插件。
|
* (Cocos Creator、LayaAir、Node.js 等)。
|
||||||
*
|
*
|
||||||
* @en This package is a generic behavior tree implementation that works with any ECS framework.
|
* @en This package is a generic behavior tree implementation that works with any engine
|
||||||
* For ESEngine integration, import the plugin from '@esengine/behavior-tree/esengine'.
|
* based on @esengine/ecs-framework (Cocos Creator, LayaAir, Node.js, etc.).
|
||||||
*
|
*
|
||||||
* @example Cocos/Laya/通用 ECS 使用方式:
|
* @example
|
||||||
* ```typescript
|
* ```typescript
|
||||||
|
* import { Core, Scene } from '@esengine/ecs-framework';
|
||||||
* import {
|
* import {
|
||||||
* BehaviorTreeAssetManager,
|
* BehaviorTreePlugin,
|
||||||
* BehaviorTreeExecutionSystem,
|
* BehaviorTreeBuilder,
|
||||||
* BehaviorTreeRuntimeComponent
|
* BehaviorTreeStarter
|
||||||
* } from '@esengine/behavior-tree';
|
* } from '@esengine/behavior-tree';
|
||||||
*
|
*
|
||||||
* // 1. Register service
|
* // 1. Initialize Core and install plugin
|
||||||
* Core.services.registerSingleton(BehaviorTreeAssetManager);
|
* Core.create();
|
||||||
|
* const plugin = new BehaviorTreePlugin();
|
||||||
|
* await Core.installPlugin(plugin);
|
||||||
*
|
*
|
||||||
* // 2. Load behavior tree from JSON
|
* // 2. Create scene and setup behavior tree system
|
||||||
* const assetManager = Core.services.resolve(BehaviorTreeAssetManager);
|
* const scene = new Scene();
|
||||||
* assetManager.loadFromEditorJSON(jsonContent);
|
* plugin.setupScene(scene);
|
||||||
|
* Core.setScene(scene);
|
||||||
*
|
*
|
||||||
* // 3. Add component to entity
|
* // 3. Build behavior tree
|
||||||
* entity.addComponent(new BehaviorTreeRuntimeComponent());
|
* const tree = BehaviorTreeBuilder.create('MyAI')
|
||||||
|
* .selector('Root')
|
||||||
|
* .log('Hello!')
|
||||||
|
* .end()
|
||||||
|
* .build();
|
||||||
*
|
*
|
||||||
* // 4. Add system to scene
|
* // 4. Start behavior tree on entity
|
||||||
* scene.addSystem(new BehaviorTreeExecutionSystem());
|
* const entity = scene.createEntity('AIEntity');
|
||||||
|
* BehaviorTreeStarter.start(entity, tree);
|
||||||
|
*
|
||||||
|
* // 5. Run game loop
|
||||||
|
* setInterval(() => Core.update(0.016), 16);
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @packageDocumentation
|
* @packageDocumentation
|
||||||
@@ -65,3 +77,6 @@ export { BlackboardTypes } from './Blackboard/BlackboardTypes';
|
|||||||
|
|
||||||
// Service tokens (using ecs-framework's createServiceToken, not engine-core)
|
// Service tokens (using ecs-framework's createServiceToken, not engine-core)
|
||||||
export { BehaviorTreeSystemToken } from './tokens';
|
export { BehaviorTreeSystemToken } from './tokens';
|
||||||
|
|
||||||
|
// Plugin
|
||||||
|
export { BehaviorTreePlugin } from './BehaviorTreePlugin';
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
# @esengine/blueprint
|
# @esengine/blueprint
|
||||||
|
|
||||||
|
## 4.0.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`3e5b778`](https://github.com/esengine/esengine/commit/3e5b7783beec08e247f7525184935401923ecde8)]:
|
||||||
|
- @esengine/ecs-framework@2.7.1
|
||||||
|
|
||||||
## 4.0.0
|
## 4.0.0
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@esengine/blueprint",
|
"name": "@esengine/blueprint",
|
||||||
"version": "4.0.0",
|
"version": "4.0.1",
|
||||||
"description": "Visual scripting system - works with any ECS framework (ESEngine, Cocos, Laya, etc.)",
|
"description": "Visual scripting system - works with any ECS framework (ESEngine, Cocos, Laya, etc.)",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"module": "dist/index.js",
|
"module": "dist/index.js",
|
||||||
|
|||||||
@@ -1,5 +1,16 @@
|
|||||||
# @esengine/ecs-framework
|
# @esengine/ecs-framework
|
||||||
|
|
||||||
|
## 2.7.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#402](https://github.com/esengine/esengine/pull/402) [`3e5b778`](https://github.com/esengine/esengine/commit/3e5b7783beec08e247f7525184935401923ecde8) Thanks [@esengine](https://github.com/esengine)! - fix(ecs): 修复 ESM 环境下 require 不存在的问题
|
||||||
|
- 新增 `RuntimeConfig` 模块,作为运行时环境配置的独立存储
|
||||||
|
- `Core.runtimeEnvironment` 和 `Scene.runtimeEnvironment` 现在都从 `RuntimeConfig` 读取
|
||||||
|
- 移除 `Scene.ts` 中的 `require()` 调用,解决 Node.js ESM 环境下的兼容性问题
|
||||||
|
|
||||||
|
此修复解决了在 Node.js ESM 环境(如游戏服务端)中使用 `scene.isServer` 时报错 `ReferenceError: require is not defined` 的问题。
|
||||||
|
|
||||||
## 2.7.0
|
## 2.7.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@esengine/ecs-framework",
|
"name": "@esengine/ecs-framework",
|
||||||
"version": "2.7.0",
|
"version": "2.7.1",
|
||||||
"description": "用于Laya、Cocos Creator等JavaScript游戏引擎的高性能ECS框架",
|
"description": "用于Laya、Cocos Creator等JavaScript游戏引擎的高性能ECS框架",
|
||||||
"main": "dist/index.cjs",
|
"main": "dist/index.cjs",
|
||||||
"module": "dist/index.mjs",
|
"module": "dist/index.mjs",
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import { IPlugin } from './Core/Plugin';
|
|||||||
import { WorldManager } from './ECS/WorldManager';
|
import { WorldManager } from './ECS/WorldManager';
|
||||||
import { DebugConfigService } from './Utils/Debug/DebugConfigService';
|
import { DebugConfigService } from './Utils/Debug/DebugConfigService';
|
||||||
import { createInstance } from './Core/DI/Decorators';
|
import { createInstance } from './Core/DI/Decorators';
|
||||||
|
import { RuntimeConfig } from './RuntimeConfig';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @zh 游戏引擎核心类
|
* @zh 游戏引擎核心类
|
||||||
@@ -86,14 +87,20 @@ export class Core {
|
|||||||
* Core.create({ runtimeEnvironment: 'server' });
|
* Core.create({ runtimeEnvironment: 'server' });
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
public static runtimeEnvironment: RuntimeEnvironment = 'standalone';
|
public static get runtimeEnvironment(): RuntimeEnvironment {
|
||||||
|
return RuntimeConfig.runtimeEnvironment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static set runtimeEnvironment(value: RuntimeEnvironment) {
|
||||||
|
RuntimeConfig.runtimeEnvironment = value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @zh 是否在服务端运行
|
* @zh 是否在服务端运行
|
||||||
* @en Whether running on server
|
* @en Whether running on server
|
||||||
*/
|
*/
|
||||||
public static get isServer(): boolean {
|
public static get isServer(): boolean {
|
||||||
return Core.runtimeEnvironment === 'server';
|
return RuntimeConfig.isServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -101,7 +108,7 @@ export class Core {
|
|||||||
* @en Whether running on client
|
* @en Whether running on client
|
||||||
*/
|
*/
|
||||||
public static get isClient(): boolean {
|
public static get isClient(): boolean {
|
||||||
return Core.runtimeEnvironment === 'client';
|
return RuntimeConfig.isClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { QuerySystem } from './Core/QuerySystem';
|
|||||||
import { TypeSafeEventSystem } from './Core/EventSystem';
|
import { TypeSafeEventSystem } from './Core/EventSystem';
|
||||||
import { ReferenceTracker } from './Core/ReferenceTracker';
|
import { ReferenceTracker } from './Core/ReferenceTracker';
|
||||||
import { IScene, ISceneConfig, RuntimeEnvironment } from './IScene';
|
import { IScene, ISceneConfig, RuntimeEnvironment } from './IScene';
|
||||||
|
import { RuntimeConfig } from '../RuntimeConfig';
|
||||||
import { getComponentInstanceTypeName, getSystemInstanceTypeName, getSystemMetadata, getSystemInstanceMetadata } from './Decorators';
|
import { getComponentInstanceTypeName, getSystemInstanceTypeName, getSystemMetadata, getSystemInstanceMetadata } from './Decorators';
|
||||||
import { TypedQueryBuilder } from './Core/Query/TypedQuery';
|
import { TypedQueryBuilder } from './Core/Query/TypedQuery';
|
||||||
import {
|
import {
|
||||||
@@ -200,10 +201,7 @@ export class Scene implements IScene {
|
|||||||
if (this._runtimeEnvironmentOverride) {
|
if (this._runtimeEnvironmentOverride) {
|
||||||
return this._runtimeEnvironmentOverride;
|
return this._runtimeEnvironmentOverride;
|
||||||
}
|
}
|
||||||
// 动态导入避免循环依赖
|
return RuntimeConfig.runtimeEnvironment;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
||||||
const { Core } = require('../Core') as typeof import('../Core');
|
|
||||||
return Core.runtimeEnvironment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
50
packages/framework/core/src/RuntimeConfig.ts
Normal file
50
packages/framework/core/src/RuntimeConfig.ts
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import type { RuntimeEnvironment } from './Types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @zh 全局运行时配置
|
||||||
|
* @en Global runtime configuration
|
||||||
|
*
|
||||||
|
* @zh 独立模块,避免 Core 和 Scene 之间的循环依赖
|
||||||
|
* @en Standalone module to avoid circular dependency between Core and Scene
|
||||||
|
*/
|
||||||
|
class RuntimeConfigClass {
|
||||||
|
private _runtimeEnvironment: RuntimeEnvironment = 'standalone';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @zh 获取运行时环境
|
||||||
|
* @en Get runtime environment
|
||||||
|
*/
|
||||||
|
get runtimeEnvironment(): RuntimeEnvironment {
|
||||||
|
return this._runtimeEnvironment;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @zh 设置运行时环境
|
||||||
|
* @en Set runtime environment
|
||||||
|
*/
|
||||||
|
set runtimeEnvironment(value: RuntimeEnvironment) {
|
||||||
|
this._runtimeEnvironment = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @zh 是否在服务端运行
|
||||||
|
* @en Whether running on server
|
||||||
|
*/
|
||||||
|
get isServer(): boolean {
|
||||||
|
return this._runtimeEnvironment === 'server';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @zh 是否在客户端运行
|
||||||
|
* @en Whether running on client
|
||||||
|
*/
|
||||||
|
get isClient(): boolean {
|
||||||
|
return this._runtimeEnvironment === 'client';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @zh 全局运行时配置单例
|
||||||
|
* @en Global runtime configuration singleton
|
||||||
|
*/
|
||||||
|
export const RuntimeConfig = new RuntimeConfigClass();
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
// 核心模块
|
// 核心模块
|
||||||
export { Core } from './Core';
|
export { Core } from './Core';
|
||||||
|
export { RuntimeConfig } from './RuntimeConfig';
|
||||||
export { ServiceContainer, ServiceLifetime } from './Core/ServiceContainer';
|
export { ServiceContainer, ServiceLifetime } from './Core/ServiceContainer';
|
||||||
export type { IService, ServiceType, ServiceIdentifier } from './Core/ServiceContainer';
|
export type { IService, ServiceType, ServiceIdentifier } from './Core/ServiceContainer';
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
# @esengine/fsm
|
# @esengine/fsm
|
||||||
|
|
||||||
|
## 4.0.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`3e5b778`](https://github.com/esengine/esengine/commit/3e5b7783beec08e247f7525184935401923ecde8)]:
|
||||||
|
- @esengine/ecs-framework@2.7.1
|
||||||
|
- @esengine/blueprint@4.0.1
|
||||||
|
|
||||||
## 4.0.0
|
## 4.0.0
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@esengine/fsm",
|
"name": "@esengine/fsm",
|
||||||
"version": "4.0.0",
|
"version": "4.0.1",
|
||||||
"description": "Finite State Machine for ECS Framework / ECS 框架的有限状态机",
|
"description": "Finite State Machine for ECS Framework / ECS 框架的有限状态机",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
# @esengine/network
|
# @esengine/network
|
||||||
|
|
||||||
|
## 5.0.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`3e5b778`](https://github.com/esengine/esengine/commit/3e5b7783beec08e247f7525184935401923ecde8)]:
|
||||||
|
- @esengine/ecs-framework@2.7.1
|
||||||
|
- @esengine/blueprint@4.0.1
|
||||||
|
|
||||||
## 5.0.0
|
## 5.0.0
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@esengine/network",
|
"name": "@esengine/network",
|
||||||
"version": "5.0.0",
|
"version": "5.0.1",
|
||||||
"description": "Network synchronization for multiplayer games",
|
"description": "Network synchronization for multiplayer games",
|
||||||
"esengine": {
|
"esengine": {
|
||||||
"plugin": true,
|
"plugin": true,
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
# @esengine/pathfinding
|
# @esengine/pathfinding
|
||||||
|
|
||||||
|
## 4.0.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`3e5b778`](https://github.com/esengine/esengine/commit/3e5b7783beec08e247f7525184935401923ecde8)]:
|
||||||
|
- @esengine/ecs-framework@2.7.1
|
||||||
|
- @esengine/blueprint@4.0.1
|
||||||
|
|
||||||
## 4.0.0
|
## 4.0.0
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@esengine/pathfinding",
|
"name": "@esengine/pathfinding",
|
||||||
"version": "4.0.0",
|
"version": "4.0.1",
|
||||||
"description": "寻路系统 | Pathfinding System - A*, Grid, NavMesh",
|
"description": "寻路系统 | Pathfinding System - A*, Grid, NavMesh",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
# @esengine/procgen
|
# @esengine/procgen
|
||||||
|
|
||||||
|
## 4.0.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`3e5b778`](https://github.com/esengine/esengine/commit/3e5b7783beec08e247f7525184935401923ecde8)]:
|
||||||
|
- @esengine/ecs-framework@2.7.1
|
||||||
|
- @esengine/blueprint@4.0.1
|
||||||
|
|
||||||
## 4.0.0
|
## 4.0.0
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@esengine/procgen",
|
"name": "@esengine/procgen",
|
||||||
"version": "4.0.0",
|
"version": "4.0.1",
|
||||||
"description": "Procedural generation tools for ECS Framework / ECS 框架的程序化生成工具",
|
"description": "Procedural generation tools for ECS Framework / ECS 框架的程序化生成工具",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"ws": ">=8.0.0",
|
"ws": ">=8.0.0",
|
||||||
"jsonwebtoken": ">=9.0.0",
|
"jsonwebtoken": ">=9.0.0",
|
||||||
"@esengine/ecs-framework": ">=2.7.0"
|
"@esengine/ecs-framework": ">=2.7.1"
|
||||||
},
|
},
|
||||||
"peerDependenciesMeta": {
|
"peerDependenciesMeta": {
|
||||||
"jsonwebtoken": {
|
"jsonwebtoken": {
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
# @esengine/spatial
|
# @esengine/spatial
|
||||||
|
|
||||||
|
## 4.0.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`3e5b778`](https://github.com/esengine/esengine/commit/3e5b7783beec08e247f7525184935401923ecde8)]:
|
||||||
|
- @esengine/ecs-framework@2.7.1
|
||||||
|
- @esengine/blueprint@4.0.1
|
||||||
|
|
||||||
## 4.0.0
|
## 4.0.0
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@esengine/spatial",
|
"name": "@esengine/spatial",
|
||||||
"version": "4.0.0",
|
"version": "4.0.1",
|
||||||
"description": "Spatial query and indexing system for ECS Framework / ECS 框架的空间查询和索引系统",
|
"description": "Spatial query and indexing system for ECS Framework / ECS 框架的空间查询和索引系统",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
# @esengine/timer
|
# @esengine/timer
|
||||||
|
|
||||||
|
## 4.0.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`3e5b778`](https://github.com/esengine/esengine/commit/3e5b7783beec08e247f7525184935401923ecde8)]:
|
||||||
|
- @esengine/ecs-framework@2.7.1
|
||||||
|
- @esengine/blueprint@4.0.1
|
||||||
|
|
||||||
## 4.0.0
|
## 4.0.0
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@esengine/timer",
|
"name": "@esengine/timer",
|
||||||
"version": "4.0.0",
|
"version": "4.0.1",
|
||||||
"description": "Timer and cooldown system for ECS Framework / ECS 框架的定时器和冷却系统",
|
"description": "Timer and cooldown system for ECS Framework / ECS 框架的定时器和冷却系统",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
|
|||||||
@@ -1,5 +1,16 @@
|
|||||||
# @esengine/demos
|
# @esengine/demos
|
||||||
|
|
||||||
|
## 1.0.10
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies []:
|
||||||
|
- @esengine/fsm@4.0.1
|
||||||
|
- @esengine/pathfinding@4.0.1
|
||||||
|
- @esengine/procgen@4.0.1
|
||||||
|
- @esengine/spatial@4.0.1
|
||||||
|
- @esengine/timer@4.0.1
|
||||||
|
|
||||||
## 1.0.9
|
## 1.0.9
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@esengine/demos",
|
"name": "@esengine/demos",
|
||||||
"version": "1.0.9",
|
"version": "1.0.10",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Demo tests for ESEngine modules documentation",
|
"description": "Demo tests for ESEngine modules documentation",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
Reference in New Issue
Block a user