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
fix(inspector): a dimension written by value gets a unit, because Auto ignores it
yhh301f39490216
diff --git a/desktop/src/engine/EditorControlSurface.ts b/desktop/src/engine/EditorControlSurface.tsindex e4d95f3e9..1603c5fe3 100644--- a/desktop/src/engine/EditorControlSurface.ts+++ b/desktop/src/engine/EditorControlSurface.ts@@ -125,9 +125,23 @@ export function patchFieldMember(? { ...(current as Record<string, unknown>) }: {};obj[at] = n;+ // A dimension whose unit is Auto IGNORES its value — that is what Auto means.+ // So `UINode.insetTop.value = 40` on a fresh node (every dimension defaults to+ // Auto) stored the 40 and moved nothing, and reading the field back showed the+ // 40 sitting there. A dogfood run put a whole HUD at one point that way: three+ // labels with insets of 8, 40 and 260, all drawn on top of each other, and+ // nothing anywhere said why. Naming the member IS the intent, so writing a+ // value gives it a unit; writing `unit` yourself still wins.+ if (type === 'dimension' && at === 'value' && (obj.unit === DIMENSION_AUTO || obj.unit === undefined)) {+ obj.unit = DIMENSION_PX;+ }return obj as InspectorFieldValue;}+/** `DimensionUnit` from the SDK, spelled here so this stays a pure function. */+const DIMENSION_PX = 0;+const DIMENSION_AUTO = 2;+/*** What a field will accept, as the inspector already describes it — structurally* a subset of InspectorField, so the write door hands its field straight in.diff --git a/desktop/tests/inspector-write-values.test.ts b/desktop/tests/inspector-write-values.test.tsindex 285adc75b..3a3eb9ad5 100644--- a/desktop/tests/inspector-write-values.test.ts+++ b/desktop/tests/inspector-write-values.test.ts@@ -146,7 +146,21 @@ describe('structural field members (the "position.x" door)', () => {it('fills a short or missing value rather than writing past its end', () => {expect(patchFieldMember('vec3', [] as unknown as InspectorFieldValue, 'z', 7)).toEqual([0, 0, 7]);- expect(patchFieldMember('dimension', null as never, 'value', 3)).toEqual({ value: 3 });+ // A unit comes with it: a dimension left on Auto ignores its value, so a+ // bare `.value` write would be stored and have no effect.+ expect(patchFieldMember('dimension', null as never, 'value', 3)).toEqual({ value: 3, unit: 0 });+ });++ it('gives a bare dimension value a unit, because Auto ignores the value', () => {+ // `UINode.insetTop.value = 40` on a fresh node stored the 40 and moved+ // nothing — every dimension defaults to Auto, and Auto means "ignore it".+ expect(patchFieldMember('dimension', { value: 0, unit: 2 }, 'value', 40))+ .toEqual({ value: 40, unit: 0 });+ // An explicit unit still wins, in either order.+ expect(patchFieldMember('dimension', { value: 0, unit: 1 }, 'value', 50))+ .toEqual({ value: 50, unit: 1 });+ expect(patchFieldMember('dimension', { value: 40, unit: 0 }, 'unit', 2))+ .toEqual({ value: 40, unit: 2 });});it('refuses a member that is not a number, and one that does not exist', () => {