Skip to content

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.

fix: sync derived properties on undo/redo for UIRect and Sprite

esengine2100ed380007
diff --git a/editor/src/store/EditorStore.ts b/editor/src/store/EditorStore.ts
index b7f9dcc0d..5532d1106 100644
--- a/editor/src/store/EditorStore.ts
+++ b/editor/src/store/EditorStore.ts
@@ -808,6 +808,7 @@ export class EditorStore {
if (this.history_.undo()) {
this.state_.isDirty = true;
this.rebuildEntityMap();
+ this.syncDerivedProperties();
this.worldTransforms_.setScene(this.state_.scene);
this.sceneLoadVersion_++;
this.notify();
@@ -818,6 +819,7 @@ export class EditorStore {
if (this.history_.redo()) {
this.state_.isDirty = true;
this.rebuildEntityMap();
+ this.syncDerivedProperties();
this.worldTransforms_.setScene(this.state_.scene);
this.sceneLoadVersion_++;
this.notify();
@@ -903,6 +905,20 @@ export class EditorStore {
}
}
+ private syncDerivedProperties(): void {
+ for (const entityData of this.entityMap_.values()) {
+ const uiRect = entityData.components.find(c => c.type === 'UIRect');
+ const sprite = entityData.components.find(c => c.type === 'Sprite');
+ if (uiRect && sprite) {
+ sprite.data.size = uiRect.data.size;
+ }
+ const textInput = entityData.components.find(c => c.type === 'TextInput');
+ if (textInput && sprite) {
+ sprite.data.color = textInput.data.backgroundColor;
+ }
+ }
+ }
+
private notifyHierarchyChange(event: HierarchyChangeEvent): void {
for (const listener of this.hierarchyListeners_) {
listener(event);