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(ui): distinguish mutation drafts from borrowed reads
yhhe1822a8ec556
diff --git a/sdk/src/ui/behavior/color-picker-system.ts b/sdk/src/ui/behavior/color-picker-system.tsindex 2198151c4..359f58d01 100644--- a/sdk/src/ui/behavior/color-picker-system.ts+++ b/sdk/src/ui/behavior/color-picker-system.ts@@ -204,10 +204,10 @@ export function installColorPickers(app: App): () => void {color = normalizePickerColor(color, data.alphaEnabled); state.color = { ...color }; state.alpha = color.a;state.editingHSV = false;if (!col.equals(data.color, color)) { world.insert(root, UIColorPicker, { ...data, color }); data = world.get(root, UIColorPicker); }- if (child(root, data.hue, UISlider) && world.get(data.hue, UISlider).value !== state.hsv.h) world.update(data.hue, UISlider, slider => { slider.value = state!.hsv.h; });- if (child(root, data.alpha, UISlider) && world.get(data.alpha, UISlider).value !== color.a) world.update(data.alpha, UISlider, slider => { slider.value = color.a; });+ if (child(root, data.hue, UISlider) && world.get(data.hue, UISlider).value !== state.hsv.h) world.update(data.hue, UISlider, draft => { draft.value = state!.hsv.h; });+ if (child(root, data.alpha, UISlider) && world.get(data.alpha, UISlider).value !== color.a) world.update(data.alpha, UISlider, draft => { draft.value = color.a; });const alphaDisplay = data.alphaEnabled ? UIDisplay.Flex : UIDisplay.None;- if (child(root, data.alpha, UINode) && world.get(data.alpha, UINode).display !== alphaDisplay) world.update(data.alpha, UINode, node => { node.display = alphaDisplay; });+ if (child(root, data.alpha, UINode) && world.get(data.alpha, UINode).display !== alphaDisplay) world.update(data.alpha, UINode, draft => { draft.display = alphaDisplay; });if (owner && !state.plane) {const pixels = new Uint8Array(64 * 64 * 4); paintPlane(pixels, state.hsv.h);// Canvas content means its owner repaints after loss, without@@ -266,7 +266,7 @@ export function installColorPickers(app: App): () => void {state.history = history; state.swatchOff.forEach(off => off()); state.swatchOff = [];state.swatches.forEach(e => { if (world.valid(e)) world.despawn(e); }); state.swatches = [];const colors = data.history.slice(0, Math.max(0, Math.min(32, Math.floor(data.historyLimit) || 0)));- if (child(root, data.rememberButton, UINode)) world.update(data.rememberButton, UINode, node => { node.display = data.rememberColors ? UIDisplay.Flex : UIDisplay.None; });+ if (child(root, data.rememberButton, UINode)) world.update(data.rememberButton, UINode, draft => { draft.display = data.rememberColors ? UIDisplay.Flex : UIDisplay.None; });if (child(root, data.historyRoot, UINode) && data.rememberColors) colors.forEach((value, index) => {const swatch = spawnUIEntity({ world, parent: data.historyRoot,node: { position: 1, width: px(22), height: px(22), insetLeft: px((index % 8) * 29), insetTop: px(Math.floor(index / 8) * 29) }, visual: { color: normalizePickerColor(value) } });diff --git a/sdk/tests/ui-tree-color-wasm.test.ts b/sdk/tests/ui-tree-color-wasm.test.tsindex 77c50c878..2e4ae4809 100644--- a/sdk/tests/ui-tree-color-wasm.test.ts+++ b/sdk/tests/ui-tree-color-wasm.test.ts@@ -187,7 +187,7 @@ describe.skipIf(!HAS_WASM)('TreeView / ColorPicker on real WASM', () => {const color=handle.getColor();app.world.update(data.hex,TextInput,text=>{text.value='#xx';});events.emit(data.hex,'change');await tick();expect(handle.getColor()).toEqual(color);});it('HEX remains independently bindable when a project omits numeric channels',async()=>{- const handle=picker();app.world.update(handle.entity,UIColorPicker,data=>{data.fields=[];});await tick();+ const handle=picker();app.world.update(handle.entity,UIColorPicker,draft=>{draft.fields=[];});await tick();const data=app.world.get(handle.entity,UIColorPicker);app.world.update(data.hex,TextInput,text=>{text.value='#aabbcc';});events.emit(data.hex,'change');await tick();expect(col.toHex(handle.getColor())).toBe('#aabbcc');expect(app.world.get(data.hex,TextInput).value).toBe('#aabbccff');diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex c64ec8134..008051960 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -28,6 +28,7 @@ export const NOTES_FLOOR = 'v0.65.0';* the reader recognises anyway.*/export const NOTED = {+ 'refactor(ui): distinguish mutation drafts from borrowed reads': { internal: 'Names observed World.update drafts distinctly from borrowed snapshots; runtime behavior and public APIs are unchanged.' },'feat: add reusable TreeView and ColorPicker UI controls': { note: 'Reusable UI trees and color pickers.' },'fix(ui): align tree labels with hierarchy indentation': { note: 'Reusable UI trees and color pickers.' },'fix(ui): keep tree selection when toggling disclosure': { note: 'Reusable UI trees and color pickers.' },