| 22 | } from './tokens'; |
| 23 | |
| 24 | class TilemapRuntimeModule implements IRuntimeModule { |
| 25 | private _tilemapPhysicsSystem: TilemapPhysicsSystem | null = null; |
| 26 | private _loaderRegistered = false; |
| 27 | |
| 28 | registerComponents(registry: IComponentRegistry): void { |
| 29 | registry.register(TilemapComponent); |
| 30 | registry.register(TilemapCollider2DComponent); |
| 31 | } |
| 32 | |
| 33 | createSystems(scene: IScene, context: SystemContext): void { |
| 34 | // 从服务注册表获取依赖 | Get dependencies from service registry |
| 35 | const assetManager = context.services.get(AssetManagerToken); |
| 36 | const renderSystem = context.services.get(RenderSystemToken); |
| 37 | |
| 38 | if (!this._loaderRegistered && assetManager) { |
| 39 | assetManager.registerLoader(TilemapAssetType, new TilemapLoader()); |
| 40 | this._loaderRegistered = true; |
| 41 | } |
| 42 | |
| 43 | const tilemapSystem = new TilemapRenderingSystem(); |
| 44 | scene.addSystem(tilemapSystem); |
| 45 | |
| 46 | if (renderSystem) { |
| 47 | renderSystem.addRenderDataProvider(tilemapSystem); |
| 48 | } |
| 49 | |
| 50 | this._tilemapPhysicsSystem = new TilemapPhysicsSystem(); |
| 51 | scene.addSystem(this._tilemapPhysicsSystem); |
| 52 | |
| 53 | // 注册服务到服务注册表 | Register services to service registry |
| 54 | context.services.register(TilemapSystemToken, tilemapSystem); |
| 55 | context.services.register(TilemapPhysicsSystemToken, this._tilemapPhysicsSystem); |
| 56 | } |
| 57 | |
| 58 | onSystemsCreated(_scene: IScene, context: SystemContext): void { |
| 59 | // 从服务注册表获取物理世界 | Get physics world from service registry |
| 60 | const physics2DWorld = context.services.get(Physics2DWorldToken); |
| 61 | |
| 62 | if (this._tilemapPhysicsSystem && physics2DWorld) { |
| 63 | this._tilemapPhysicsSystem.setPhysicsWorld(physics2DWorld); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | get tilemapPhysicsSystem(): TilemapPhysicsSystem | null { |
| 68 | return this._tilemapPhysicsSystem; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | const manifest: ModuleManifest = { |
| 73 | id: 'tilemap', |
nothing calls this directly
no outgoing calls
no test coverage detected