A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
refactor: extract getSizeComponentType helper and optimize scene sync
esenginec2c38a6c4c70
diff --git a/editor/src/panels/SceneViewPanel.ts b/editor/src/panels/SceneViewPanel.tsindex def5bdac8..e9b2e0656 100644--- a/editor/src/panels/SceneViewPanel.ts+++ b/editor/src/panels/SceneViewPanel.ts@@ -117,6 +117,12 @@ export class SceneViewPanel {private settingsDropdown_: HTMLElement | null = null;private settingsDropdownClickHandler_: ((e: MouseEvent) => void) | null = null;+ private getSizeComponentType(entityData: import('../types/SceneTypes').EntityData): 'UIRect' | 'Sprite' | null {+ if (entityData.components.some(c => c.type === 'UIRect')) return 'UIRect';+ if (entityData.components.some(c => c.type === 'Sprite')) return 'Sprite';+ return null;+ }+constructor(container: HTMLElement, store: EditorStore, options?: SceneViewPanelOptions) {this.container_ = container;this.store_ = store;@@ -752,9 +758,9 @@ export class SceneViewPanel {newWidth = Math.max(1, newWidth);newHeight = Math.max(1, newHeight);- const sprite = entityData.components.find(c => c.type === 'Sprite');- if (sprite) {- this.store_.updatePropertyDirect(entity, 'Sprite', 'size', { x: newWidth, y: newHeight });+ const sizeType = this.getSizeComponentType(entityData);+ if (sizeType) {+ this.store_.updatePropertyDirect(entity, sizeType, 'size', { x: newWidth, y: newHeight });}const transform = entityData.components.find(c => c.type === 'LocalTransform');@@ -777,13 +783,14 @@ export class SceneViewPanel {const entityData = this.store_.getSelectedEntityData();if (!entityData) return;- const sprite = entityData.components.find(c => c.type === 'Sprite');- if (sprite && this.rectDragOriginalSize_) {- const currentSize = sprite.data.size as { x: number; y: number };+ const sizeType = this.getSizeComponentType(entityData);+ if (sizeType && this.rectDragOriginalSize_) {+ const comp = entityData.components.find(c => c.type === sizeType)!;+ const currentSize = comp.data.size as { x: number; y: number };if (currentSize && !this.valuesEqual(this.rectDragOriginalSize_, currentSize)) {this.store_.updateProperty(entity,- 'Sprite',+ sizeType,'size',{ ...this.rectDragOriginalSize_ },{ ...currentSize }diff --git a/editor/src/renderer/EditorSceneRenderer.ts b/editor/src/renderer/EditorSceneRenderer.tsindex 8ba1d5a41..a44152eb7 100644--- a/editor/src/renderer/EditorSceneRenderer.ts+++ b/editor/src/renderer/EditorSceneRenderer.ts@@ -36,6 +36,10 @@ export class EditorSceneRenderer {/** Map entity ID to EntityData for fast lookup */private entityDataMap_: Map<number, EntityData> = new Map();+ /** Sync lock to prevent concurrent syncScene calls */+ private syncing_ = false;+ private pendingScene_: SceneData | null = null;+constructor() {this.camera_ = new EditorCamera();}@@ -76,6 +80,29 @@ export class EditorSceneRenderer {async syncScene(scene: SceneData): Promise<void> {if (!this.registry_ || !this.module_) return;+ if (this.syncing_) {+ this.pendingScene_ = scene;+ return;+ }++ this.syncing_ = true;++ try {+ await this.syncSceneInternal(scene);++ if (this.pendingScene_) {+ const latest = this.pendingScene_;+ this.pendingScene_ = null;+ await this.syncSceneInternal(latest);+ }+ } finally {+ this.syncing_ = false;+ }+ }++ private async syncSceneInternal(scene: SceneData): Promise<void> {+ if (!this.registry_ || !this.module_) return;+this.clearRegistry();this.sceneData_ = scene;@@ -210,6 +237,10 @@ export class EditorSceneRenderer {this.registry_.destroy(entity);}this.entityMap_.clear();++ if (this.textRenderer_) {+ this.textRenderer_.releaseAll();+ }}private async syncComponent(entity: Entity, comp: ComponentData, entityId: number): Promise<void> {@@ -220,9 +251,14 @@ export class EditorSceneRenderer {this.syncTransform(entity, comp.data, entityId);break;- case 'Sprite':- await this.syncSprite(entity, comp.data);+ case 'Sprite': {+ const entityData = this.entityDataMap_.get(entityId);+ const hasText = entityData?.components.some(c => c.type === 'Text');+ if (!hasText) {+ await this.syncSprite(entity, comp.data);+ }break;+ }case 'Camera':this.syncCamera(entity, comp.data);