* refactor: 编辑器/运行时架构拆分与构建系统升级 * feat(core): 层级系统重构与UI变换矩阵修复 * refactor: 移除 ecs-components 聚合包并修复跨包组件查找问题 * fix(physics): 修复跨包组件类引用问题 * feat: 统一运行时架构与浏览器运行支持 * feat(asset): 实现浏览器运行时资产加载系统 * fix: 修复文档、CodeQL安全问题和CI类型检查错误 * fix: 修复文档、CodeQL安全问题和CI类型检查错误 * fix: 修复文档、CodeQL安全问题、CI类型检查和测试错误 * test: 补齐核心模块测试用例,修复CI构建配置 * fix: 修复测试用例中的类型错误和断言问题 * fix: 修复 turbo build:npm 任务的依赖顺序问题 * fix: 修复 CI 构建错误并优化构建性能
82 lines
2.9 KiB
TypeScript
82 lines
2.9 KiB
TypeScript
import type { IScene } from '@esengine/ecs-framework';
|
|
import { ComponentRegistry } from '@esengine/ecs-framework';
|
|
import type { IRuntimeModule, IPlugin, PluginDescriptor, SystemContext } from '@esengine/engine-core';
|
|
import type { AssetManager } from '@esengine/asset-system';
|
|
|
|
import { TilemapComponent } from './TilemapComponent';
|
|
import { TilemapRenderingSystem } from './systems/TilemapRenderingSystem';
|
|
import { TilemapCollider2DComponent } from './physics/TilemapCollider2DComponent';
|
|
import { TilemapPhysicsSystem, type IPhysicsWorld } from './physics/TilemapPhysicsSystem';
|
|
import { TilemapLoader } from './loaders/TilemapLoader';
|
|
import { TilemapAssetType } from './constants';
|
|
|
|
export interface TilemapSystemContext extends SystemContext {
|
|
tilemapSystem?: TilemapRenderingSystem;
|
|
tilemapPhysicsSystem?: TilemapPhysicsSystem;
|
|
physics2DWorld?: IPhysicsWorld;
|
|
assetManager?: AssetManager;
|
|
renderSystem?: any;
|
|
}
|
|
|
|
class TilemapRuntimeModule implements IRuntimeModule {
|
|
private _tilemapPhysicsSystem: TilemapPhysicsSystem | null = null;
|
|
private _loaderRegistered = false;
|
|
|
|
registerComponents(registry: typeof ComponentRegistry): void {
|
|
registry.register(TilemapComponent);
|
|
registry.register(TilemapCollider2DComponent);
|
|
}
|
|
|
|
createSystems(scene: IScene, context: SystemContext): void {
|
|
const tilemapContext = context as TilemapSystemContext;
|
|
|
|
if (!this._loaderRegistered && tilemapContext.assetManager) {
|
|
tilemapContext.assetManager.registerLoader(TilemapAssetType, new TilemapLoader());
|
|
this._loaderRegistered = true;
|
|
}
|
|
|
|
const tilemapSystem = new TilemapRenderingSystem();
|
|
scene.addSystem(tilemapSystem);
|
|
|
|
if (tilemapContext.renderSystem) {
|
|
tilemapContext.renderSystem.addRenderDataProvider(tilemapSystem);
|
|
}
|
|
|
|
tilemapContext.tilemapSystem = tilemapSystem;
|
|
|
|
this._tilemapPhysicsSystem = new TilemapPhysicsSystem();
|
|
scene.addSystem(this._tilemapPhysicsSystem);
|
|
|
|
tilemapContext.tilemapPhysicsSystem = this._tilemapPhysicsSystem;
|
|
}
|
|
|
|
onSystemsCreated(_scene: IScene, context: SystemContext): void {
|
|
const tilemapContext = context as TilemapSystemContext;
|
|
|
|
if (this._tilemapPhysicsSystem && tilemapContext.physics2DWorld) {
|
|
this._tilemapPhysicsSystem.setPhysicsWorld(tilemapContext.physics2DWorld);
|
|
}
|
|
}
|
|
|
|
get tilemapPhysicsSystem(): TilemapPhysicsSystem | null {
|
|
return this._tilemapPhysicsSystem;
|
|
}
|
|
}
|
|
|
|
const descriptor: PluginDescriptor = {
|
|
id: '@esengine/tilemap',
|
|
name: 'Tilemap',
|
|
version: '1.0.0',
|
|
description: 'Tilemap system with Tiled editor support',
|
|
category: 'tilemap',
|
|
enabledByDefault: false,
|
|
isEnginePlugin: true
|
|
};
|
|
|
|
export const TilemapPlugin: IPlugin = {
|
|
descriptor,
|
|
runtimeModule: new TilemapRuntimeModule()
|
|
};
|
|
|
|
export { TilemapRuntimeModule };
|