Feature/tilemap editor (#237)

* feat: 添加 Tilemap 编辑器插件和组件生命周期支持

* feat(editor-core): 添加声明式插件注册 API

* feat(editor-core): 改进tiledmap结构合并tileset进tiledmapeditor

* feat: 添加 editor-runtime SDK 和插件系统改进

* fix(ci): 修复SceneResourceManager里变量未使用问题
This commit is contained in:
YHH
2025-11-25 22:23:19 +08:00
committed by GitHub
parent 551ca7805d
commit 3fb6f919f8
166 changed files with 54691 additions and 8674 deletions

View File

@@ -0,0 +1,113 @@
import { Core, Entity } from '@esengine/ecs-framework';
import { EntityStoreService, MessageHub } from '@esengine/editor-core';
import { TransformComponent } from '@esengine/ecs-components';
import { TilemapComponent } from '@esengine/tilemap';
import { BaseCommand } from '../BaseCommand';
/**
* Tilemap创建选项
*/
export interface TilemapCreationOptions {
/** 地图宽度瓦片数默认10 */
width?: number;
/** 地图高度瓦片数默认10 */
height?: number;
/** 瓦片宽度像素默认32 */
tileWidth?: number;
/** 瓦片高度像素默认32 */
tileHeight?: number;
/** 渲染层级默认0 */
sortingOrder?: number;
/** 初始Tileset源路径 */
tilesetSource?: string;
}
/**
* 创建带Tilemap组件的实体命令
*/
export class CreateTilemapEntityCommand extends BaseCommand {
private entity: Entity | null = null;
private entityId: number | null = null;
constructor(
private entityStore: EntityStoreService,
private messageHub: MessageHub,
private entityName: string,
private parentEntity?: Entity,
private options: TilemapCreationOptions = {}
) {
super();
}
execute(): void {
const scene = Core.scene;
if (!scene) {
throw new Error('场景未初始化');
}
this.entity = scene.createEntity(this.entityName);
this.entityId = this.entity.id;
// 添加Transform组件
this.entity.addComponent(new TransformComponent());
// 创建并配置Tilemap组件
const tilemapComponent = new TilemapComponent();
// 应用配置选项
const {
width = 10,
height = 10,
tileWidth = 32,
tileHeight = 32,
sortingOrder = 0,
tilesetSource
} = this.options;
tilemapComponent.tileWidth = tileWidth;
tilemapComponent.tileHeight = tileHeight;
tilemapComponent.sortingOrder = sortingOrder;
// 初始化空白地图
tilemapComponent.initializeEmpty(width, height);
// 添加初始 Tileset
if (tilesetSource) {
tilemapComponent.addTileset(tilesetSource);
}
this.entity.addComponent(tilemapComponent);
if (this.parentEntity) {
this.parentEntity.addChild(this.entity);
}
this.entityStore.addEntity(this.entity, this.parentEntity);
this.entityStore.selectEntity(this.entity);
this.messageHub.publish('entity:added', { entity: this.entity });
this.messageHub.publish('tilemap:created', {
entity: this.entity,
component: tilemapComponent
});
}
undo(): void {
if (!this.entity) return;
this.entityStore.removeEntity(this.entity);
this.entity.destroy();
this.messageHub.publish('entity:removed', { entityId: this.entityId });
this.entity = null;
}
getDescription(): string {
return `创建Tilemap实体: ${this.entityName}`;
}
getCreatedEntity(): Entity | null {
return this.entity;
}
}

View File

@@ -2,5 +2,6 @@ export { CreateEntityCommand } from './CreateEntityCommand';
export { CreateSpriteEntityCommand } from './CreateSpriteEntityCommand';
export { CreateAnimatedSpriteEntityCommand } from './CreateAnimatedSpriteEntityCommand';
export { CreateCameraEntityCommand } from './CreateCameraEntityCommand';
export { CreateTilemapEntityCommand } from './CreateTilemapEntityCommand';
export { DeleteEntityCommand } from './DeleteEntityCommand';