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): variable-length StateVisuals.states[] via codegen vector<struct> (REARCH_GUI F5)
esenginefc06956b9ce1
diff --git a/sdk/src/component.generated.ts b/sdk/src/component.generated.tsindex 59c53bdbd..e7fd675ba 100644--- a/sdk/src/component.generated.ts+++ b/sdk/src/component.generated.ts@@ -12,7 +12,7 @@ import type { AssetFieldType } from './scene';* getAbiLayoutHash(); BuiltinBridge.connect() compares them and refuses to* run on mismatch, because mismatched offsets read the wrong heap bytes.*/-export const ABI_LAYOUT_HASH = 'ea147a61d787f430';+export const ABI_LAYOUT_HASH = 'ffbf3c8be66d1354';export interface AssetFieldMeta {field: string;@@ -331,42 +331,11 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {targetGraphic: 0,transitionFlags: 0,fadeDuration: 0,- slot0Name: '',- slot0Color: { r: 1, g: 1, b: 1, a: 1 },- slot0Sprite: 0,- slot0Scale: 1,- slot1Name: '',- slot1Color: { r: 1, g: 1, b: 1, a: 1 },- slot1Sprite: 0,- slot1Scale: 1,- slot2Name: '',- slot2Color: { r: 1, g: 1, b: 1, a: 1 },- slot2Sprite: 0,- slot2Scale: 1,- slot3Name: '',- slot3Color: { r: 1, g: 1, b: 1, a: 1 },- slot3Sprite: 0,- slot3Scale: 1,- slot4Name: '',- slot4Color: { r: 1, g: 1, b: 1, a: 1 },- slot4Sprite: 0,- slot4Scale: 1,- slot5Name: '',- slot5Color: { r: 1, g: 1, b: 1, a: 1 },- slot5Sprite: 0,- slot5Scale: 1,- slot6Name: '',- slot6Color: { r: 1, g: 1, b: 1, a: 1 },- slot6Sprite: 0,- slot6Scale: 1,- slot7Name: '',- slot7Color: { r: 1, g: 1, b: 1, a: 1 },- slot7Sprite: 0,- slot7Scale: 1,+ states: [],},- assetFields: [{ field: 'slot0Sprite', type: 'texture' as AssetFieldType }, { field: 'slot1Sprite', type: 'texture' as AssetFieldType }, { field: 'slot2Sprite', type: 'texture' as AssetFieldType }, { field: 'slot3Sprite', type: 'texture' as AssetFieldType }, { field: 'slot4Sprite', type: 'texture' as AssetFieldType }, { field: 'slot5Sprite', type: 'texture' as AssetFieldType }, { field: 'slot6Sprite', type: 'texture' as AssetFieldType }, { field: 'slot7Sprite', type: 'texture' as AssetFieldType }],+ assetFields: [],entityFields: ['targetGraphic'],- colorFields: ['slot0Color', 'slot1Color', 'slot2Color', 'slot3Color', 'slot4Color', 'slot5Color', 'slot6Color', 'slot7Color'],+ colorFields: [],animatableFields: [],},TilemapLayer: {diff --git a/sdk/src/ui/behavior/state-visuals.ts b/sdk/src/ui/behavior/state-visuals.tsindex 579f89419..7e4330ae4 100644--- a/sdk/src/ui/behavior/state-visuals.ts+++ b/sdk/src/ui/behavior/state-visuals.ts@@ -1,5 +1,16 @@// SPDX-License-Identifier: LicenseRef-PolyForm-Noncommercial-1.0.0// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file ui/behavior/state-visuals.ts+ * @brief StateVisuals — named state → visual overrides (REARCH_GUI F5).+ *+ * A variable-length `states` list replaced the old 8 hardcoded `slotN*` field+ * quartets + stringly-keyed reflection. The apply system reads the entity's+ * StateMachine.current, finds the matching {@link VisualState} by name, and+ * applies its color/sprite/scale to `targetGraphic`. Mirrors the C+++ * `StateVisuals` builtin; `VisualState` mirrors the C++ POD (flat r/g/b/a so it+ * round-trips through the embind vector path).+ */import { defineBuiltin } from '../../component';import type { Color, Entity } from '../../types';@@ -12,36 +23,42 @@ export const TransitionFlag = {export type TransitionFlag = (typeof TransitionFlag)[keyof typeof TransitionFlag];-export const STATE_VISUALS_SLOT_COUNT = 8;+/** One named visual state (mirrors the C++ VisualState; color is flat r/g/b/a). */+export interface VisualState {+ name: string;+ r: number;+ g: number;+ b: number;+ a: number;+ /** Texture-handle id for sprite swap; 0 = none. */+ sprite: number;+ scale: number;+}export interface StateVisualsData {targetGraphic: Entity;transitionFlags: number;fadeDuration: number;-- slot0Name: string; slot0Color: Color; slot0Sprite: number; slot0Scale: number;- slot1Name: string; slot1Color: Color; slot1Sprite: number; slot1Scale: number;- slot2Name: string; slot2Color: Color; slot2Sprite: number; slot2Scale: number;- slot3Name: string; slot3Color: Color; slot3Sprite: number; slot3Scale: number;- slot4Name: string; slot4Color: Color; slot4Sprite: number; slot4Scale: number;- slot5Name: string; slot5Color: Color; slot5Sprite: number; slot5Scale: number;- slot6Name: string; slot6Color: Color; slot6Sprite: number; slot6Scale: number;- slot7Name: string; slot7Color: Color; slot7Sprite: number; slot7Scale: number;+ states: VisualState[];}-const WHITE = (): Color => ({ r: 1, g: 1, b: 1, a: 1 });+/** Build a {@link VisualState} from a name + Color (+ optional sprite/scale). */+export function visualState(+ name: string,+ color: Color,+ opts: { sprite?: number; scale?: number } = {},+): VisualState {+ return {+ name,+ r: color.r, g: color.g, b: color.b, a: color.a,+ sprite: opts.sprite ?? 0,+ scale: opts.scale ?? 1,+ };+}export const StateVisuals = defineBuiltin<StateVisualsData>('StateVisuals', {targetGraphic: 0 as Entity,transitionFlags: 0,fadeDuration: 0,-- slot0Name: '', slot0Color: WHITE(), slot0Sprite: 0, slot0Scale: 1,- slot1Name: '', slot1Color: WHITE(), slot1Sprite: 0, slot1Scale: 1,- slot2Name: '', slot2Color: WHITE(), slot2Sprite: 0, slot2Scale: 1,- slot3Name: '', slot3Color: WHITE(), slot3Sprite: 0, slot3Scale: 1,- slot4Name: '', slot4Color: WHITE(), slot4Sprite: 0, slot4Scale: 1,- slot5Name: '', slot5Color: WHITE(), slot5Sprite: 0, slot5Scale: 1,- slot6Name: '', slot6Color: WHITE(), slot6Sprite: 0, slot6Scale: 1,- slot7Name: '', slot7Color: WHITE(), slot7Sprite: 0, slot7Scale: 1,+ states: [],});diff --git a/sdk/src/ui/behavior/systems.ts b/sdk/src/ui/behavior/systems.tsindex e313a8171..f68735c9f 100644--- a/sdk/src/ui/behavior/systems.ts+++ b/sdk/src/ui/behavior/systems.ts@@ -11,7 +11,6 @@ import { StateMachine, type StateMachineData } from './state-machine';import {StateVisuals,TransitionFlag,- STATE_VISUALS_SLOT_COUNT,type StateVisualsData,} from './state-visuals';import { UIVisual, type UIVisualData } from '../core/ui-visual';@@ -41,16 +40,12 @@ export function driverStateFor(}/**- * Pure lookup: index of the StateVisuals slot whose name matches `state`.- * Returns -1 if no slot matches (caller should skip applying visuals).+ * Pure lookup: index into `sv.states` of the VisualState whose name matches+ * `state`. Returns -1 if none matches (caller should skip applying visuals).*/export function findStateSlot(sv: StateVisualsData, state: string): number {if (state === '') return -1;- const record = sv as unknown as Record<string, unknown>;- for (let i = 0; i < STATE_VISUALS_SLOT_COUNT; i++) {- if (record[`slot${i}Name`] === state) return i;- }- return -1;+ return sv.states.findIndex(s => s.name === state);}/**@@ -162,9 +157,9 @@ export function createStateVisualsApplySystem(world: World): SystemDef {const target = sv.targetGraphic !== 0 ? sv.targetGraphic : e;const flags = sv.transitionFlags;- const record = sv as unknown as Record<string, unknown>;- const targetColor = record[`slot${slot}Color`] as Color;- const targetScale = record[`slot${slot}Scale`] as number;+ const state = sv.states[slot];+ const targetColor: Color = { r: state.r, g: state.g, b: state.b, a: state.a };+ const targetScale = state.scale;const fade = Math.max(0, sv.fadeDuration);// Detect a slot change. If we have no prior entry OR the entry@@ -196,7 +191,7 @@ export function createStateVisualsApplySystem(world: World): SystemDef {if ((flags & TransitionFlag.SpriteSwap) && world.has(target, UIVisual)) {// Sprite swap is discrete: apply immediately at the slot change.const r = world.get(target, UIVisual) as UIVisualData;- r.texture = record[`slot${slot}Sprite`] as number;+ r.texture = state.sprite;world.insert(target, UIVisual, r);}diff --git a/sdk/src/ui/index.ts b/sdk/src/ui/index.tsindex 88d27cb56..b26504c5c 100644--- a/sdk/src/ui/index.ts+++ b/sdk/src/ui/index.ts@@ -110,7 +110,8 @@ export {export {StateVisuals,TransitionFlag,- STATE_VISUALS_SLOT_COUNT,+ visualState,+ type VisualState,type StateVisualsData,} from './behavior/state-visuals';diff --git a/sdk/src/ui/widgets/button.ts b/sdk/src/ui/widgets/button.tsindex 0a21c1903..1984188c2 100644--- a/sdk/src/ui/widgets/button.ts+++ b/sdk/src/ui/widgets/button.ts@@ -8,6 +8,8 @@ import { StateMachine } from '../behavior/state-machine';import {StateVisuals,TransitionFlag,+ visualState,+ type VisualState,type StateVisualsData,} from '../behavior/state-visuals';import { UIEventType, type UIEventQueue } from '../core/events';@@ -55,27 +57,11 @@ export interface ButtonOptions {onClick?: (entity: Entity) => void;}-const MAX_STATE_SLOTS = 8;--function writeSlots(- data: StateVisualsData,- states: Record<string, ButtonStateVisual>,-): void {- const names = Object.keys(states);- if (names.length > MAX_STATE_SLOTS) {- throw new Error(- `[createButton] up to ${MAX_STATE_SLOTS} states are supported, got ${names.length}`,- );- }- const record = data as unknown as Record<string, unknown>;- for (let i = 0; i < names.length; i++) {- const name = names[i];- const slot = states[name]!;- record[`slot${i}Name`] = name;- record[`slot${i}Color`] = slot.color ?? { r: 1, g: 1, b: 1, a: 1 };- record[`slot${i}Sprite`] = slot.sprite ?? 0;- record[`slot${i}Scale`] = slot.scale ?? 1;- }+/** Map the state-name → override record to the VisualState[] list. */+function buildStates(states: Record<string, ButtonStateVisual>): VisualState[] {+ return Object.entries(states).map(([name, v]) =>+ visualState(name, v.color ?? { r: 1, g: 1, b: 1, a: 1 },+ { sprite: v.sprite, scale: v.scale }));}/**@@ -112,16 +98,8 @@ export function createButton(opts: ButtonOptions): Entity {targetGraphic: 0 as Entity,transitionFlags: opts.transitionFlags ?? TransitionFlag.ColorTint,fadeDuration: opts.fadeDuration ?? 0,- slot0Name: '', slot0Color: { r: 1, g: 1, b: 1, a: 1 }, slot0Sprite: 0, slot0Scale: 1,- slot1Name: '', slot1Color: { r: 1, g: 1, b: 1, a: 1 }, slot1Sprite: 0, slot1Scale: 1,- slot2Name: '', slot2Color: { r: 1, g: 1, b: 1, a: 1 }, slot2Sprite: 0, slot2Scale: 1,- slot3Name: '', slot3Color: { r: 1, g: 1, b: 1, a: 1 }, slot3Sprite: 0, slot3Scale: 1,- slot4Name: '', slot4Color: { r: 1, g: 1, b: 1, a: 1 }, slot4Sprite: 0, slot4Scale: 1,- slot5Name: '', slot5Color: { r: 1, g: 1, b: 1, a: 1 }, slot5Sprite: 0, slot5Scale: 1,- slot6Name: '', slot6Color: { r: 1, g: 1, b: 1, a: 1 }, slot6Sprite: 0, slot6Scale: 1,- slot7Name: '', slot7Color: { r: 1, g: 1, b: 1, a: 1 }, slot7Sprite: 0, slot7Scale: 1,+ states: buildStates(opts.states),};- writeSlots(visuals, opts.states);world.insert(entity, StateVisuals, visuals);if (opts.text !== undefined) {diff --git a/sdk/src/ui/widgets/dropdown.ts b/sdk/src/ui/widgets/dropdown.tsindex 78143d87d..faec47833 100644--- a/sdk/src/ui/widgets/dropdown.ts+++ b/sdk/src/ui/widgets/dropdown.ts@@ -5,7 +5,7 @@ import type { World } from '../../world';import { Interactable, UIInteraction } from '../behavior/interactable';import { StateMachine } from '../behavior/state-machine';-import { StateVisuals, TransitionFlag, type StateVisualsData } from '../behavior/state-visuals';+import { StateVisuals, TransitionFlag, visualState, type StateVisualsData } from '../behavior/state-visuals';import { UIEventType, type UIEventQueue } from '../core/events';import { Text, type TextData } from '../core/text';@@ -69,19 +69,15 @@ const INTERACTION_DEFAULT = {function makeStatesSV(colors: {normal: Color; hover: Color; pressed: Color;}): StateVisualsData {- const white = { r: 1, g: 1, b: 1, a: 1 };return {targetGraphic: 0 as Entity,transitionFlags: TransitionFlag.ColorTint,fadeDuration: 0,- slot0Name: 'normal', slot0Color: colors.normal, slot0Sprite: 0, slot0Scale: 1,- slot1Name: 'hover', slot1Color: colors.hover, slot1Sprite: 0, slot1Scale: 1,- slot2Name: 'pressed', slot2Color: colors.pressed, slot2Sprite: 0, slot2Scale: 1,- slot3Name: '', slot3Color: white, slot3Sprite: 0, slot3Scale: 1,- slot4Name: '', slot4Color: white, slot4Sprite: 0, slot4Scale: 1,- slot5Name: '', slot5Color: white, slot5Sprite: 0, slot5Scale: 1,- slot6Name: '', slot6Color: white, slot6Sprite: 0, slot6Scale: 1,- slot7Name: '', slot7Color: white, slot7Sprite: 0, slot7Scale: 1,+ states: [+ visualState('normal', colors.normal),+ visualState('hover', colors.hover),+ visualState('pressed', colors.pressed),+ ],};}diff --git a/sdk/src/wasm.generated.ts b/sdk/src/wasm.generated.tsindex dc0946451..2c9068270 100644--- a/sdk/src/wasm.generated.ts+++ b/sdk/src/wasm.generated.ts@@ -10,6 +10,7 @@ import type { Entity, Vec2, Vec3, Vec4, Quat } from './types';export interface UVec2 { x: number; y: number; }export interface Padding { left: number; top: number; right: number; bottom: number; }export interface Dimension { value: number; unit: number; }+export interface VisualState { name: string; r: number; g: number; b: number; a: number; sprite: number; scale: number; }export type Mat4 = number[];// Emscripten Vector Types@@ -355,38 +356,7 @@ export interface StateVisuals {targetGraphic: number;transitionFlags: number;fadeDuration: number;- slot0Name: string;- slot0Color: Vec4;- slot0Sprite: number;- slot0Scale: number;- slot1Name: string;- slot1Color: Vec4;- slot1Sprite: number;- slot1Scale: number;- slot2Name: string;- slot2Color: Vec4;- slot2Sprite: number;- slot2Scale: number;- slot3Name: string;- slot3Color: Vec4;- slot3Sprite: number;- slot3Scale: number;- slot4Name: string;- slot4Color: Vec4;- slot4Sprite: number;- slot4Scale: number;- slot5Name: string;- slot5Color: Vec4;- slot5Sprite: number;- slot5Scale: number;- slot6Name: string;- slot6Color: Vec4;- slot6Sprite: number;- slot6Scale: number;- slot7Name: string;- slot7Color: Vec4;- slot7Sprite: number;- slot7Scale: number;+ states: VisualState[];}export interface TilemapLayer {diff --git a/sdk/tests/emscripten-wrapper.test.ts b/sdk/tests/emscripten-wrapper.test.tsindex 00ccfb0e4..951abbf5c 100644--- a/sdk/tests/emscripten-wrapper.test.ts+++ b/sdk/tests/emscripten-wrapper.test.ts@@ -114,4 +114,46 @@ describe.skipIf(!HAS_WASM)('Emscripten wrapper diagnostics', () => {registry.destroy(entity);(registry as unknown as { delete(): void }).delete();});++ // REARCH_GUI F5: a std::vector<VisualState> component field must round-trip a+ // plain JS array through embind (register_vector + value_object), incl. the+ // std::string member. This is the path the button/dropdown widgets exercise.+ it('round-trips a std::vector<VisualState> through embind', () => {+ const registry = new module.Registry() as unknown as CppRegistry;+ const entity = registry.create();++ const reg = registry as unknown as {+ addStateVisuals(e: number, c: unknown): void;+ getStateVisuals(e: number): { states: unknown };+ };+ reg.addStateVisuals(entity, {+ targetGraphic: 0,+ transitionFlags: 1,+ fadeDuration: 0.5,+ states: [+ { name: 'normal', r: 1, g: 0, b: 0, a: 1, sprite: 0, scale: 1 },+ { name: 'hover', r: 0, g: 1, b: 0, a: 1, sprite: 7, scale: 1.25 },+ ],+ });++ const states = reg.getStateVisuals(entity).states as+ | Array<Record<string, number | string>>+ | { size(): number; get(i: number): Record<string, number | string> };+ // embind may hand back a plain array or a bound vector — accept both.+ const isArr = Array.isArray(states);+ const len = isArr ? (states as unknown[]).length : (states as { size(): number }).size();+ const at = (i: number) => isArr+ ? (states as Array<Record<string, number | string>>)[i]+ : (states as { get(i: number): Record<string, number | string> }).get(i);++ expect(len).toBe(2);+ expect(at(0).name).toBe('normal');+ expect(at(0).r).toBeCloseTo(1, 5);+ expect(at(1).name).toBe('hover');+ expect(at(1).sprite).toBe(7);+ expect(at(1).scale).toBeCloseTo(1.25, 5);++ registry.destroy(entity);+ (registry as unknown as { delete(): void }).delete();+ });});diff --git a/sdk/tests/ui-behavior.test.ts b/sdk/tests/ui-behavior.test.tsindex e438c6c14..e81c52e6f 100644--- a/sdk/tests/ui-behavior.test.ts+++ b/sdk/tests/ui-behavior.test.ts@@ -5,7 +5,6 @@ import {StateMachine,StateVisuals,TransitionFlag,- STATE_VISUALS_SLOT_COUNT,Interactable,UIInteraction,Focusable,@@ -30,34 +29,16 @@ describe('ui2 behavior components', () => {expect(StateVisuals._name).toBe('StateVisuals');});- it('exposes exactly 8 slots', () => {- expect(STATE_VISUALS_SLOT_COUNT).toBe(8);- const d = StateVisuals._default as Record<string, unknown>;- for (let i = 0; i < 8; i++) {- expect(d[`slot${i}Name`]).toBe('');- expect(d[`slot${i}Color`]).toEqual({ r: 1, g: 1, b: 1, a: 1 });- expect(d[`slot${i}Sprite`]).toBe(0);- expect(d[`slot${i}Scale`]).toBe(1);- }+ it('defaults to an empty states list (variable-length, REARCH_GUI F5)', () => {+ const d = StateVisuals._default as { states: unknown[] };+ expect(Array.isArray(d.states)).toBe(true);+ expect(d.states).toHaveLength(0);});it('declares targetGraphic as an entity reference for serialization', () => {// EHT populates entityFields from ES_PROPERTY(entity_ref)expect(StateVisuals.entityFields).toContain('targetGraphic');});-- it('declares each slot color for editor color-picker detection', () => {- for (let i = 0; i < 8; i++) {- expect(StateVisuals.colorKeys).toContain(`slot${i}Color`);- }- });-- it('declares each slot sprite as a texture asset field', () => {- const fields = StateVisuals.assetFields.map((f) => f.field);- for (let i = 0; i < 8; i++) {- expect(fields).toContain(`slot${i}Sprite`);- }- });});describe('TransitionFlag', () => {diff --git a/sdk/tests/ui-state-visuals-fade.test.ts b/sdk/tests/ui-state-visuals-fade.test.tsindex ca49c51e0..8925c589a 100644--- a/sdk/tests/ui-state-visuals-fade.test.ts+++ b/sdk/tests/ui-state-visuals-fade.test.ts@@ -11,6 +11,7 @@ import { StateMachine, type StateMachineData } from '../src/ui/behavior/state-maimport {StateVisuals,TransitionFlag,+ visualState,type StateVisualsData,} from '../src/ui/behavior/state-visuals';import { UIVisual, type UIVisualData } from '../src/ui/core/ui-visual';@@ -60,14 +61,7 @@ function makeVisuals(overrides: Partial<StateVisualsData>): StateVisualsData {targetGraphic: 0 as Entity,transitionFlags: 0,fadeDuration: 0,- slot0Name: '', slot0Color: { r: 1, g: 1, b: 1, a: 1 }, slot0Sprite: 0, slot0Scale: 1,- slot1Name: '', slot1Color: { r: 1, g: 1, b: 1, a: 1 }, slot1Sprite: 0, slot1Scale: 1,- slot2Name: '', slot2Color: { r: 1, g: 1, b: 1, a: 1 }, slot2Sprite: 0, slot2Scale: 1,- slot3Name: '', slot3Color: { r: 1, g: 1, b: 1, a: 1 }, slot3Sprite: 0, slot3Scale: 1,- slot4Name: '', slot4Color: { r: 1, g: 1, b: 1, a: 1 }, slot4Sprite: 0, slot4Scale: 1,- slot5Name: '', slot5Color: { r: 1, g: 1, b: 1, a: 1 }, slot5Sprite: 0, slot5Scale: 1,- slot6Name: '', slot6Color: { r: 1, g: 1, b: 1, a: 1 }, slot6Sprite: 0, slot6Scale: 1,- slot7Name: '', slot7Color: { r: 1, g: 1, b: 1, a: 1 }, slot7Sprite: 0, slot7Scale: 1,+ states: [],...overrides,} as StateVisualsData;}@@ -110,8 +104,7 @@ describe('StateVisualsApplySystem — color fade', () => {world.insert(entity, StateVisuals, makeVisuals({transitionFlags: TransitionFlag.ColorTint,fadeDuration: 0,- slot0Name: 'pressed',- slot0Color: { r: 0, g: 0, b: 1, a: 1 },+ states: [visualState('pressed', { r: 0, g: 0, b: 1, a: 1 })],}));const sys = createStateVisualsApplySystem(world as never);@@ -126,8 +119,7 @@ describe('StateVisualsApplySystem — color fade', () => {world.insert(entity, StateVisuals, makeVisuals({transitionFlags: TransitionFlag.ColorTint,fadeDuration: 1.0,- slot0Name: 'pressed',- slot0Color: { r: 0, g: 0, b: 0, a: 1 },+ states: [visualState('pressed', { r: 0, g: 0, b: 0, a: 1 })],}));const sys = createStateVisualsApplySystem(world as never);@@ -147,8 +139,7 @@ describe('StateVisualsApplySystem — color fade', () => {world.insert(entity, StateVisuals, makeVisuals({transitionFlags: TransitionFlag.ColorTint,fadeDuration: 0.5,- slot0Name: 'pressed',- slot0Color: { r: 0, g: 0, b: 0, a: 1 },+ states: [visualState('pressed', { r: 0, g: 0, b: 0, a: 1 })],}));const sys = createStateVisualsApplySystem(world as never);@@ -164,8 +155,10 @@ describe('StateVisualsApplySystem — color fade', () => {world.insert(entity, StateVisuals, makeVisuals({transitionFlags: TransitionFlag.ColorTint,fadeDuration: 1.0,- slot0Name: 'a', slot0Color: { r: 0, g: 0, b: 0, a: 1 },- slot1Name: 'b', slot1Color: { r: 1, g: 0, b: 0, a: 1 },+ states: [+ visualState('a', { r: 0, g: 0, b: 0, a: 1 }),+ visualState('b', { r: 1, g: 0, b: 0, a: 1 }),+ ],}));const sys = createStateVisualsApplySystem(world as never);@@ -198,8 +191,7 @@ describe('StateVisualsApplySystem — scale fade', () => {world.insert(entity, StateVisuals, makeVisuals({transitionFlags: TransitionFlag.Scale,fadeDuration: 1.0,- slot0Name: 'pressed',- slot0Scale: 2,+ states: [visualState('pressed', { r: 1, g: 1, b: 1, a: 1 }, { scale: 2 })],}));const sys = createStateVisualsApplySystem(world as never);@@ -221,8 +213,7 @@ describe('StateVisualsApplySystem — sprite swap', () => {world.insert(entity, StateVisuals, makeVisuals({transitionFlags: TransitionFlag.SpriteSwap,fadeDuration: 1.0,- slot0Name: 'pressed',- slot0Sprite: 42,+ states: [visualState('pressed', { r: 1, g: 1, b: 1, a: 1 }, { sprite: 42 })],}));const sys = createStateVisualsApplySystem(world as never);diff --git a/sdk/tests/ui-systems.test.ts b/sdk/tests/ui-systems.test.tsindex 9dd9561fb..5b6a5dba2 100644--- a/sdk/tests/ui-systems.test.ts+++ b/sdk/tests/ui-systems.test.ts@@ -5,22 +5,19 @@ import {driverStateFor,findStateSlot,TransitionFlag,+ visualState,type StateVisualsData,type UIInteractionData,} from '../src/ui';+const WHITE = { r: 1, g: 1, b: 1, a: 1 };+const named = (...names: string[]) => names.map(n => visualState(n, WHITE));+const sv = (overrides: Partial<StateVisualsData> = {}): StateVisualsData => ({targetGraphic: 0 as never,transitionFlags: 0,fadeDuration: 0,- slot0Name: '', slot0Color: { r: 1, g: 1, b: 1, a: 1 }, slot0Sprite: 0, slot0Scale: 1,- slot1Name: '', slot1Color: { r: 1, g: 1, b: 1, a: 1 }, slot1Sprite: 0, slot1Scale: 1,- slot2Name: '', slot2Color: { r: 1, g: 1, b: 1, a: 1 }, slot2Sprite: 0, slot2Scale: 1,- slot3Name: '', slot3Color: { r: 1, g: 1, b: 1, a: 1 }, slot3Sprite: 0, slot3Scale: 1,- slot4Name: '', slot4Color: { r: 1, g: 1, b: 1, a: 1 }, slot4Sprite: 0, slot4Scale: 1,- slot5Name: '', slot5Color: { r: 1, g: 1, b: 1, a: 1 }, slot5Sprite: 0, slot5Scale: 1,- slot6Name: '', slot6Color: { r: 1, g: 1, b: 1, a: 1 }, slot6Sprite: 0, slot6Scale: 1,- slot7Name: '', slot7Color: { r: 1, g: 1, b: 1, a: 1 }, slot7Sprite: 0, slot7Scale: 1,+ states: [],...overrides,});@@ -51,31 +48,27 @@ describe('driverStateFor', () => {describe('findStateSlot', () => {it('returns -1 when state is the empty string', () => {- expect(findStateSlot(sv({ slot0Name: 'normal' }), '')).toBe(-1);+ expect(findStateSlot(sv({ states: named('normal') }), '')).toBe(-1);});- it('returns the index of the matching slot', () => {- const data = sv({- slot0Name: 'normal',- slot1Name: 'hover',- slot2Name: 'pressed',- });+ it('returns the index of the matching state', () => {+ const data = sv({ states: named('normal', 'hover', 'pressed') });expect(findStateSlot(data, 'normal')).toBe(0);expect(findStateSlot(data, 'hover')).toBe(1);expect(findStateSlot(data, 'pressed')).toBe(2);});- it('returns -1 when no slot matches', () => {- expect(findStateSlot(sv({ slot0Name: 'normal' }), 'loading')).toBe(-1);+ it('returns -1 when no state matches', () => {+ expect(findStateSlot(sv({ states: named('normal') }), 'loading')).toBe(-1);});- it('returns -1 for user-defined states in unused slots (all slots empty)', () => {+ it('returns -1 when the states list is empty', () => {expect(findStateSlot(sv(), 'any')).toBe(-1);});it('returns the first match when names collide', () => {- const data = sv({ slot2Name: 'x', slot5Name: 'x' });- expect(findStateSlot(data, 'x')).toBe(2);+ const data = sv({ states: named('a', 'x', 'b', 'x') });+ expect(findStateSlot(data, 'x')).toBe(1);});});diff --git a/sdk/tests/ui-widgets.test.ts b/sdk/tests/ui-widgets.test.tsindex 2768cfd97..c643aa84e 100644--- a/sdk/tests/ui-widgets.test.ts+++ b/sdk/tests/ui-widgets.test.ts@@ -115,7 +115,7 @@ describe('createButton', () => {expect(world.has(btn, StateVisuals)).toBe(true);});- it('populates StateVisuals slots from the `states` map', () => {+ it('populates the StateVisuals states list from the `states` map', () => {const btn = createButton({world: world as unknown as World,events,@@ -126,11 +126,13 @@ describe('createButton', () => {transitionFlags: TransitionFlag.ColorTint,});- const sv = world.get(btn, StateVisuals) as Record<string, unknown>;- expect(sv['slot0Name']).toBe('normal');- expect(sv['slot1Name']).toBe('hover');- expect(sv['slot0Color']).toEqual({ r: 1, g: 0, b: 0, a: 1 });- expect(sv['transitionFlags']).toBe(TransitionFlag.ColorTint);+ const sv = world.get(btn, StateVisuals) as {+ states: Array<{ name: string; r: number; g: number; b: number; a: number }>;+ transitionFlags: number;+ };+ expect(sv.states.map(s => s.name)).toEqual(['normal', 'hover']);+ expect(sv.states[0]).toMatchObject({ r: 1, g: 0, b: 0, a: 1 });+ expect(sv.transitionFlags).toBe(TransitionFlag.ColorTint);});it('starts in "disabled" state when opts.disabled is true', () => {@@ -149,16 +151,16 @@ describe('createButton', () => {expect(i.enabled).toBe(false);});- it('throws when more than 8 states are supplied', () => {- expect(() =>- createButton({- world: world as unknown as World,- events,- states: Object.fromEntries(- Array.from({ length: 9 }, (_, i) => [`s${i}`, {}]),- ),- }),- ).toThrow(/up to 8/);+ it('supports an arbitrary number of states (variable-length, REARCH_GUI F5)', () => {+ const btn = createButton({+ world: world as unknown as World,+ events,+ states: Object.fromEntries(+ Array.from({ length: 12 }, (_, i) => [`s${i}`, {}]),+ ),+ });+ const sv = world.get(btn, StateVisuals) as { states: unknown[] };+ expect(sv.states).toHaveLength(12);});it('fires onClick when the state transitions pressed → hover', () => {diff --git a/src/esengine/bindings/EditorAPI.generated.cpp b/src/esengine/bindings/EditorAPI.generated.cppindex ac15f1d17..367c3e33b 100644--- a/src/esengine/bindings/EditorAPI.generated.cpp+++ b/src/esengine/bindings/EditorAPI.generated.cpp@@ -2,10 +2,10 @@* @file EditorAPI.generated.cpp* @brief Auto-generated editor API with string-dispatched component access* @details Generated by EHT - DO NOT EDIT- * @schema_hash b95550ef1870c19d+ * @schema_hash a1287b16b459bbd1*/-#define ES_EDITOR_API_SCHEMA_HASH "b95550ef1870c19d"+#define ES_EDITOR_API_SCHEMA_HASH "a1287b16b459bbd1"#include <emscripten/bind.h>#include <string>@@ -336,63 +336,7 @@ std::string editor_getComponentSchema(const std::string& name) {return R"JSON([{"key":"targetGraphic","type":"entity","group":"StateVisuals"},{"key":"transitionFlags","type":"int","group":"StateVisuals"},- {"key":"fadeDuration","type":"float","group":"StateVisuals"},- {"key":"slot0Name","type":"string","group":"StateVisuals"},- {"key":"slot0Color.r","type":"color","group":"StateVisuals"},- {"key":"slot0Color.g","type":"color","group":"StateVisuals"},- {"key":"slot0Color.b","type":"color","group":"StateVisuals"},- {"key":"slot0Color.a","type":"color","group":"StateVisuals"},- {"key":"slot0Sprite","type":"asset","group":"StateVisuals"},- {"key":"slot0Scale","type":"float","group":"StateVisuals"},- {"key":"slot1Name","type":"string","group":"StateVisuals"},- {"key":"slot1Color.r","type":"color","group":"StateVisuals"},- {"key":"slot1Color.g","type":"color","group":"StateVisuals"},- {"key":"slot1Color.b","type":"color","group":"StateVisuals"},- {"key":"slot1Color.a","type":"color","group":"StateVisuals"},- {"key":"slot1Sprite","type":"asset","group":"StateVisuals"},- {"key":"slot1Scale","type":"float","group":"StateVisuals"},- {"key":"slot2Name","type":"string","group":"StateVisuals"},- {"key":"slot2Color.r","type":"color","group":"StateVisuals"},- {"key":"slot2Color.g","type":"color","group":"StateVisuals"},- {"key":"slot2Color.b","type":"color","group":"StateVisuals"},- {"key":"slot2Color.a","type":"color","group":"StateVisuals"},- {"key":"slot2Sprite","type":"asset","group":"StateVisuals"},- {"key":"slot2Scale","type":"float","group":"StateVisuals"},- {"key":"slot3Name","type":"string","group":"StateVisuals"},- {"key":"slot3Color.r","type":"color","group":"StateVisuals"},- {"key":"slot3Color.g","type":"color","group":"StateVisuals"},- {"key":"slot3Color.b","type":"color","group":"StateVisuals"},- {"key":"slot3Color.a","type":"color","group":"StateVisuals"},- {"key":"slot3Sprite","type":"asset","group":"StateVisuals"},- {"key":"slot3Scale","type":"float","group":"StateVisuals"},- {"key":"slot4Name","type":"string","group":"StateVisuals"},- {"key":"slot4Color.r","type":"color","group":"StateVisuals"},- {"key":"slot4Color.g","type":"color","group":"StateVisuals"},- {"key":"slot4Color.b","type":"color","group":"StateVisuals"},- {"key":"slot4Color.a","type":"color","group":"StateVisuals"},- {"key":"slot4Sprite","type":"asset","group":"StateVisuals"},- {"key":"slot4Scale","type":"float","group":"StateVisuals"},- {"key":"slot5Name","type":"string","group":"StateVisuals"},- {"key":"slot5Color.r","type":"color","group":"StateVisuals"},- {"key":"slot5Color.g","type":"color","group":"StateVisuals"},- {"key":"slot5Color.b","type":"color","group":"StateVisuals"},- {"key":"slot5Color.a","type":"color","group":"StateVisuals"},- {"key":"slot5Sprite","type":"asset","group":"StateVisuals"},- {"key":"slot5Scale","type":"float","group":"StateVisuals"},- {"key":"slot6Name","type":"string","group":"StateVisuals"},- {"key":"slot6Color.r","type":"color","group":"StateVisuals"},- {"key":"slot6Color.g","type":"color","group":"StateVisuals"},- {"key":"slot6Color.b","type":"color","group":"StateVisuals"},- {"key":"slot6Color.a","type":"color","group":"StateVisuals"},- {"key":"slot6Sprite","type":"asset","group":"StateVisuals"},- {"key":"slot6Scale","type":"float","group":"StateVisuals"},- {"key":"slot7Name","type":"string","group":"StateVisuals"},- {"key":"slot7Color.r","type":"color","group":"StateVisuals"},- {"key":"slot7Color.g","type":"color","group":"StateVisuals"},- {"key":"slot7Color.b","type":"color","group":"StateVisuals"},- {"key":"slot7Color.a","type":"color","group":"StateVisuals"},- {"key":"slot7Sprite","type":"asset","group":"StateVisuals"},- {"key":"slot7Scale","type":"float","group":"StateVisuals"}+ {"key":"fadeDuration","type":"float","group":"StateVisuals"}])JSON";} else if (name == "TilemapLayer") {return R"JSON([@@ -910,46 +854,6 @@ bool editor_setFloat(Registry& reg, u32 e, const std::string& comp, const std::sif (!reg.has<esengine::ecs::StateVisuals>(entity)) return false;auto& c = reg.get<esengine::ecs::StateVisuals>(entity);if (field == "fadeDuration") { c.fadeDuration = value; }- else if (field == "slot0Color.r") { c.slot0Color.r = value; }- else if (field == "slot0Color.g") { c.slot0Color.g = value; }- else if (field == "slot0Color.b") { c.slot0Color.b = value; }- else if (field == "slot0Color.a") { c.slot0Color.a = value; }- else if (field == "slot0Scale") { c.slot0Scale = value; }- else if (field == "slot1Color.r") { c.slot1Color.r = value; }- else if (field == "slot1Color.g") { c.slot1Color.g = value; }- else if (field == "slot1Color.b") { c.slot1Color.b = value; }- else if (field == "slot1Color.a") { c.slot1Color.a = value; }- else if (field == "slot1Scale") { c.slot1Scale = value; }- else if (field == "slot2Color.r") { c.slot2Color.r = value; }- else if (field == "slot2Color.g") { c.slot2Color.g = value; }- else if (field == "slot2Color.b") { c.slot2Color.b = value; }- else if (field == "slot2Color.a") { c.slot2Color.a = value; }- else if (field == "slot2Scale") { c.slot2Scale = value; }- else if (field == "slot3Color.r") { c.slot3Color.r = value; }- else if (field == "slot3Color.g") { c.slot3Color.g = value; }- else if (field == "slot3Color.b") { c.slot3Color.b = value; }- else if (field == "slot3Color.a") { c.slot3Color.a = value; }- else if (field == "slot3Scale") { c.slot3Scale = value; }- else if (field == "slot4Color.r") { c.slot4Color.r = value; }- else if (field == "slot4Color.g") { c.slot4Color.g = value; }- else if (field == "slot4Color.b") { c.slot4Color.b = value; }- else if (field == "slot4Color.a") { c.slot4Color.a = value; }- else if (field == "slot4Scale") { c.slot4Scale = value; }- else if (field == "slot5Color.r") { c.slot5Color.r = value; }- else if (field == "slot5Color.g") { c.slot5Color.g = value; }- else if (field == "slot5Color.b") { c.slot5Color.b = value; }- else if (field == "slot5Color.a") { c.slot5Color.a = value; }- else if (field == "slot5Scale") { c.slot5Scale = value; }- else if (field == "slot6Color.r") { c.slot6Color.r = value; }- else if (field == "slot6Color.g") { c.slot6Color.g = value; }- else if (field == "slot6Color.b") { c.slot6Color.b = value; }- else if (field == "slot6Color.a") { c.slot6Color.a = value; }- else if (field == "slot6Scale") { c.slot6Scale = value; }- else if (field == "slot7Color.r") { c.slot7Color.r = value; }- else if (field == "slot7Color.g") { c.slot7Color.g = value; }- else if (field == "slot7Color.b") { c.slot7Color.b = value; }- else if (field == "slot7Color.a") { c.slot7Color.a = value; }- else if (field == "slot7Scale") { c.slot7Scale = value; }else { return false; }return true;} else if (comp == "TilemapLayer") {@@ -1233,46 +1137,6 @@ f32 editor_getFloat(Registry& reg, u32 e, const std::string& comp, const std::stif (!reg.has<esengine::ecs::StateVisuals>(entity)) return 0.0f;const auto& c = reg.get<esengine::ecs::StateVisuals>(entity);if (field == "fadeDuration") { return c.fadeDuration; }- else if (field == "slot0Color.r") { return c.slot0Color.r; }- else if (field == "slot0Color.g") { return c.slot0Color.g; }- else if (field == "slot0Color.b") { return c.slot0Color.b; }- else if (field == "slot0Color.a") { return c.slot0Color.a; }- else if (field == "slot0Scale") { return c.slot0Scale; }- else if (field == "slot1Color.r") { return c.slot1Color.r; }- else if (field == "slot1Color.g") { return c.slot1Color.g; }- else if (field == "slot1Color.b") { return c.slot1Color.b; }- else if (field == "slot1Color.a") { return c.slot1Color.a; }- else if (field == "slot1Scale") { return c.slot1Scale; }- else if (field == "slot2Color.r") { return c.slot2Color.r; }- else if (field == "slot2Color.g") { return c.slot2Color.g; }- else if (field == "slot2Color.b") { return c.slot2Color.b; }- else if (field == "slot2Color.a") { return c.slot2Color.a; }- else if (field == "slot2Scale") { return c.slot2Scale; }- else if (field == "slot3Color.r") { return c.slot3Color.r; }- else if (field == "slot3Color.g") { return c.slot3Color.g; }- else if (field == "slot3Color.b") { return c.slot3Color.b; }- else if (field == "slot3Color.a") { return c.slot3Color.a; }- else if (field == "slot3Scale") { return c.slot3Scale; }- else if (field == "slot4Color.r") { return c.slot4Color.r; }- else if (field == "slot4Color.g") { return c.slot4Color.g; }- else if (field == "slot4Color.b") { return c.slot4Color.b; }- else if (field == "slot4Color.a") { return c.slot4Color.a; }- else if (field == "slot4Scale") { return c.slot4Scale; }- else if (field == "slot5Color.r") { return c.slot5Color.r; }- else if (field == "slot5Color.g") { return c.slot5Color.g; }- else if (field == "slot5Color.b") { return c.slot5Color.b; }- else if (field == "slot5Color.a") { return c.slot5Color.a; }- else if (field == "slot5Scale") { return c.slot5Scale; }- else if (field == "slot6Color.r") { return c.slot6Color.r; }- else if (field == "slot6Color.g") { return c.slot6Color.g; }- else if (field == "slot6Color.b") { return c.slot6Color.b; }- else if (field == "slot6Color.a") { return c.slot6Color.a; }- else if (field == "slot6Scale") { return c.slot6Scale; }- else if (field == "slot7Color.r") { return c.slot7Color.r; }- else if (field == "slot7Color.g") { return c.slot7Color.g; }- else if (field == "slot7Color.b") { return c.slot7Color.b; }- else if (field == "slot7Color.a") { return c.slot7Color.a; }- else if (field == "slot7Scale") { return c.slot7Scale; }} else if (comp == "TilemapLayer") {if (!reg.has<esengine::ecs::TilemapLayer>(entity)) return 0.0f;const auto& c = reg.get<esengine::ecs::TilemapLayer>(entity);@@ -1486,14 +1350,6 @@ bool editor_setInt(Registry& reg, u32 e, const std::string& comp, const std::strauto& c = reg.get<esengine::ecs::StateVisuals>(entity);if (field == "targetGraphic") { c.targetGraphic = static_cast<Entity>(value); }else if (field == "transitionFlags") { c.transitionFlags = static_cast<u32>(value); }- else if (field == "slot0Sprite") { c.slot0Sprite = resource::TextureHandle(static_cast<u32>(value)); }- else if (field == "slot1Sprite") { c.slot1Sprite = resource::TextureHandle(static_cast<u32>(value)); }- else if (field == "slot2Sprite") { c.slot2Sprite = resource::TextureHandle(static_cast<u32>(value)); }- else if (field == "slot3Sprite") { c.slot3Sprite = resource::TextureHandle(static_cast<u32>(value)); }- else if (field == "slot4Sprite") { c.slot4Sprite = resource::TextureHandle(static_cast<u32>(value)); }- else if (field == "slot5Sprite") { c.slot5Sprite = resource::TextureHandle(static_cast<u32>(value)); }- else if (field == "slot6Sprite") { c.slot6Sprite = resource::TextureHandle(static_cast<u32>(value)); }- else if (field == "slot7Sprite") { c.slot7Sprite = resource::TextureHandle(static_cast<u32>(value)); }else { return false; }return true;} else if (comp == "TilemapLayer") {@@ -1625,14 +1481,6 @@ i32 editor_getInt(Registry& reg, u32 e, const std::string& comp, const std::striconst auto& c = reg.get<esengine::ecs::StateVisuals>(entity);if (field == "targetGraphic") { return static_cast<i32>(static_cast<u32>(c.targetGraphic)); }else if (field == "transitionFlags") { return static_cast<i32>(c.transitionFlags); }- else if (field == "slot0Sprite") { return static_cast<i32>(c.slot0Sprite.id()); }- else if (field == "slot1Sprite") { return static_cast<i32>(c.slot1Sprite.id()); }- else if (field == "slot2Sprite") { return static_cast<i32>(c.slot2Sprite.id()); }- else if (field == "slot3Sprite") { return static_cast<i32>(c.slot3Sprite.id()); }- else if (field == "slot4Sprite") { return static_cast<i32>(c.slot4Sprite.id()); }- else if (field == "slot5Sprite") { return static_cast<i32>(c.slot5Sprite.id()); }- else if (field == "slot6Sprite") { return static_cast<i32>(c.slot6Sprite.id()); }- else if (field == "slot7Sprite") { return static_cast<i32>(c.slot7Sprite.id()); }} else if (comp == "TilemapLayer") {if (!reg.has<esengine::ecs::TilemapLayer>(entity)) return 0;const auto& c = reg.get<esengine::ecs::TilemapLayer>(entity);@@ -1907,19 +1755,6 @@ bool editor_setString(Registry& reg, u32 e, const std::string& comp, const std::else if (field == "previous") { c.previous = value; }else { return false; }return true;- } else if (comp == "StateVisuals") {- if (!reg.has<esengine::ecs::StateVisuals>(entity)) return false;- auto& c = reg.get<esengine::ecs::StateVisuals>(entity);- if (field == "slot0Name") { c.slot0Name = value; }- else if (field == "slot1Name") { c.slot1Name = value; }- else if (field == "slot2Name") { c.slot2Name = value; }- else if (field == "slot3Name") { c.slot3Name = value; }- else if (field == "slot4Name") { c.slot4Name = value; }- else if (field == "slot5Name") { c.slot5Name = value; }- else if (field == "slot6Name") { c.slot6Name = value; }- else if (field == "slot7Name") { c.slot7Name = value; }- else { return false; }- return true;}return false;}@@ -1945,17 +1780,6 @@ std::string editor_getString(Registry& reg, u32 e, const std::string& comp, consconst auto& c = reg.get<esengine::ecs::StateMachine>(entity);if (field == "current") { return c.current; }else if (field == "previous") { return c.previous; }- } else if (comp == "StateVisuals") {- if (!reg.has<esengine::ecs::StateVisuals>(entity)) return std::string{};- const auto& c = reg.get<esengine::ecs::StateVisuals>(entity);- if (field == "slot0Name") { return c.slot0Name; }- else if (field == "slot1Name") { return c.slot1Name; }- else if (field == "slot2Name") { return c.slot2Name; }- else if (field == "slot3Name") { return c.slot3Name; }- else if (field == "slot4Name") { return c.slot4Name; }- else if (field == "slot5Name") { return c.slot5Name; }- else if (field == "slot6Name") { return c.slot6Name; }- else if (field == "slot7Name") { return c.slot7Name; }}return std::string{};}diff --git a/src/esengine/bindings/WebBindings.generated.cpp b/src/esengine/bindings/WebBindings.generated.cppindex 92bebc578..385ed757f 100644--- a/src/esengine/bindings/WebBindings.generated.cpp+++ b/src/esengine/bindings/WebBindings.generated.cpp@@ -76,6 +76,15 @@ EMSCRIPTEN_BINDINGS(esengine_math) {value_object<esengine::Dimension>("Dimension").field("value", &esengine::Dimension::value).field("unit", &esengine::Dimension::unit);++ value_object<esengine::VisualState>("VisualState")+ .field("name", &esengine::VisualState::name)+ .field("r", &esengine::VisualState::r)+ .field("g", &esengine::VisualState::g)+ .field("b", &esengine::VisualState::b)+ .field("a", &esengine::VisualState::a)+ .field("sprite", &esengine::VisualState::sprite)+ .field("scale", &esengine::VisualState::scale);}// =============================================================================@@ -593,38 +602,7 @@ struct StateVisualsJS {u32 targetGraphic;u32 transitionFlags;f32 fadeDuration;- std::string slot0Name;- glm::vec4 slot0Color;- u32 slot0Sprite;- f32 slot0Scale;- std::string slot1Name;- glm::vec4 slot1Color;- u32 slot1Sprite;- f32 slot1Scale;- std::string slot2Name;- glm::vec4 slot2Color;- u32 slot2Sprite;- f32 slot2Scale;- std::string slot3Name;- glm::vec4 slot3Color;- u32 slot3Sprite;- f32 slot3Scale;- std::string slot4Name;- glm::vec4 slot4Color;- u32 slot4Sprite;- f32 slot4Scale;- std::string slot5Name;- glm::vec4 slot5Color;- u32 slot5Sprite;- f32 slot5Scale;- std::string slot6Name;- glm::vec4 slot6Color;- u32 slot6Sprite;- f32 slot6Scale;- std::string slot7Name;- glm::vec4 slot7Color;- u32 slot7Sprite;- f32 slot7Scale;+ emscripten::val states = emscripten::val::array();};esengine::ecs::StateVisuals statevisualsFromJS(const StateVisualsJS& js) {@@ -632,38 +610,9 @@ esengine::ecs::StateVisuals statevisualsFromJS(const StateVisualsJS& js) {c.targetGraphic = Entity(js.targetGraphic);c.transitionFlags = js.transitionFlags;c.fadeDuration = js.fadeDuration;- c.slot0Name = js.slot0Name;- c.slot0Color = js.slot0Color;- c.slot0Sprite = resource::TextureHandle(js.slot0Sprite);- c.slot0Scale = js.slot0Scale;- c.slot1Name = js.slot1Name;- c.slot1Color = js.slot1Color;- c.slot1Sprite = resource::TextureHandle(js.slot1Sprite);- c.slot1Scale = js.slot1Scale;- c.slot2Name = js.slot2Name;- c.slot2Color = js.slot2Color;- c.slot2Sprite = resource::TextureHandle(js.slot2Sprite);- c.slot2Scale = js.slot2Scale;- c.slot3Name = js.slot3Name;- c.slot3Color = js.slot3Color;- c.slot3Sprite = resource::TextureHandle(js.slot3Sprite);- c.slot3Scale = js.slot3Scale;- c.slot4Name = js.slot4Name;- c.slot4Color = js.slot4Color;- c.slot4Sprite = resource::TextureHandle(js.slot4Sprite);- c.slot4Scale = js.slot4Scale;- c.slot5Name = js.slot5Name;- c.slot5Color = js.slot5Color;- c.slot5Sprite = resource::TextureHandle(js.slot5Sprite);- c.slot5Scale = js.slot5Scale;- c.slot6Name = js.slot6Name;- c.slot6Color = js.slot6Color;- c.slot6Sprite = resource::TextureHandle(js.slot6Sprite);- c.slot6Scale = js.slot6Scale;- c.slot7Name = js.slot7Name;- c.slot7Color = js.slot7Color;- c.slot7Sprite = resource::TextureHandle(js.slot7Sprite);- c.slot7Scale = js.slot7Scale;+ { const size_t n = js.states["length"].as<size_t>();+ c.states.clear(); c.states.reserve(n);+ for (size_t i = 0; i < n; ++i) c.states.push_back(js.states[i].as<esengine::VisualState>()); }return c;}@@ -672,38 +621,8 @@ StateVisualsJS statevisualsToJS(const esengine::ecs::StateVisuals& c) {js.targetGraphic = static_cast<u32>(c.targetGraphic);js.transitionFlags = c.transitionFlags;js.fadeDuration = c.fadeDuration;- js.slot0Name = c.slot0Name;- js.slot0Color = c.slot0Color;- js.slot0Sprite = c.slot0Sprite.id();- js.slot0Scale = c.slot0Scale;- js.slot1Name = c.slot1Name;- js.slot1Color = c.slot1Color;- js.slot1Sprite = c.slot1Sprite.id();- js.slot1Scale = c.slot1Scale;- js.slot2Name = c.slot2Name;- js.slot2Color = c.slot2Color;- js.slot2Sprite = c.slot2Sprite.id();- js.slot2Scale = c.slot2Scale;- js.slot3Name = c.slot3Name;- js.slot3Color = c.slot3Color;- js.slot3Sprite = c.slot3Sprite.id();- js.slot3Scale = c.slot3Scale;- js.slot4Name = c.slot4Name;- js.slot4Color = c.slot4Color;- js.slot4Sprite = c.slot4Sprite.id();- js.slot4Scale = c.slot4Scale;- js.slot5Name = c.slot5Name;- js.slot5Color = c.slot5Color;- js.slot5Sprite = c.slot5Sprite.id();- js.slot5Scale = c.slot5Scale;- js.slot6Name = c.slot6Name;- js.slot6Color = c.slot6Color;- js.slot6Sprite = c.slot6Sprite.id();- js.slot6Scale = c.slot6Scale;- js.slot7Name = c.slot7Name;- js.slot7Color = c.slot7Color;- js.slot7Sprite = c.slot7Sprite.id();- js.slot7Scale = c.slot7Scale;+ js.states = emscripten::val::array();+ for (size_t i = 0; i < c.states.size(); ++i) js.states.set(i, emscripten::val(c.states[i]));return js;}@@ -1084,38 +1003,7 @@ EMSCRIPTEN_BINDINGS(esengine_components) {.field("targetGraphic", &StateVisualsJS::targetGraphic).field("transitionFlags", &StateVisualsJS::transitionFlags).field("fadeDuration", &StateVisualsJS::fadeDuration)- .field("slot0Name", &StateVisualsJS::slot0Name)- .field("slot0Color", &StateVisualsJS::slot0Color)- .field("slot0Sprite", &StateVisualsJS::slot0Sprite)- .field("slot0Scale", &StateVisualsJS::slot0Scale)- .field("slot1Name", &StateVisualsJS::slot1Name)- .field("slot1Color", &StateVisualsJS::slot1Color)- .field("slot1Sprite", &StateVisualsJS::slot1Sprite)- .field("slot1Scale", &StateVisualsJS::slot1Scale)- .field("slot2Name", &StateVisualsJS::slot2Name)- .field("slot2Color", &StateVisualsJS::slot2Color)- .field("slot2Sprite", &StateVisualsJS::slot2Sprite)- .field("slot2Scale", &StateVisualsJS::slot2Scale)- .field("slot3Name", &StateVisualsJS::slot3Name)- .field("slot3Color", &StateVisualsJS::slot3Color)- .field("slot3Sprite", &StateVisualsJS::slot3Sprite)- .field("slot3Scale", &StateVisualsJS::slot3Scale)- .field("slot4Name", &StateVisualsJS::slot4Name)- .field("slot4Color", &StateVisualsJS::slot4Color)- .field("slot4Sprite", &StateVisualsJS::slot4Sprite)- .field("slot4Scale", &StateVisualsJS::slot4Scale)- .field("slot5Name", &StateVisualsJS::slot5Name)- .field("slot5Color", &StateVisualsJS::slot5Color)- .field("slot5Sprite", &StateVisualsJS::slot5Sprite)- .field("slot5Scale", &StateVisualsJS::slot5Scale)- .field("slot6Name", &StateVisualsJS::slot6Name)- .field("slot6Color", &StateVisualsJS::slot6Color)- .field("slot6Sprite", &StateVisualsJS::slot6Sprite)- .field("slot6Scale", &StateVisualsJS::slot6Scale)- .field("slot7Name", &StateVisualsJS::slot7Name)- .field("slot7Color", &StateVisualsJS::slot7Color)- .field("slot7Sprite", &StateVisualsJS::slot7Sprite)- .field("slot7Scale", &StateVisualsJS::slot7Scale);+ .field("states", &StateVisualsJS::states);value_object<TilemapLayerJS>("TilemapLayer").field("cellSize", &TilemapLayerJS::cellSize)@@ -1965,7 +1853,7 @@ static_assert(offsetof(esengine::ecs::Velocity, angular) == 12, "ABI offset drif// ABI Hash -- runtime handshake against the SDK bundle// =============================================================================-static const char* kEsAbiLayoutHash = "ea147a61d787f430";+static const char* kEsAbiLayoutHash = "ffbf3c8be66d1354";std::string esengineGetAbiLayoutHash() {return std::string(kEsAbiLayoutHash);diff --git a/src/esengine/core/UITypes.hpp b/src/esengine/core/UITypes.hppindex e27295a6a..6efd7671a 100644--- a/src/esengine/core/UITypes.hpp+++ b/src/esengine/core/UITypes.hpp@@ -4,6 +4,8 @@#include "Types.hpp"+#include <string>+namespace esengine {struct Padding {@@ -28,4 +30,25 @@ struct Dimension {u8 unit{0}; // 0=Px, 1=Percent, 2=Auto};+/**+ * @brief One named visual state for StateVisuals (REARCH_GUI F5).+ *+ * The element type of `StateVisuals.states` — a variable-length list that+ * replaced the old 8 hardcoded `slotN*` field quartets + stringly-keyed+ * reflection. Carried only inside `std::vector<VisualState>` (never a direct+ * pointer-accessed component field), so it may hold a std::string; it marshals+ * to JS 1:1 via embind value_object + register_vector. Colour is flat r/g/b/a+ * (not glm::vec4) so it round-trips cleanly through the vector path. `sprite` is+ * a raw texture-handle id (0 = none).+ */+struct VisualState {+ std::string name;+ f32 r{1.0f};+ f32 g{1.0f};+ f32 b{1.0f};+ f32 a{1.0f};+ u32 sprite{0};+ f32 scale{1.0f};+};+} // namespace esenginediff --git a/src/esengine/ecs/components/StateVisuals.hpp b/src/esengine/ecs/components/StateVisuals.hppindex efbbf99ea..7ba68cb47 100644--- a/src/esengine/ecs/components/StateVisuals.hpp+++ b/src/esengine/ecs/components/StateVisuals.hpp@@ -4,10 +4,9 @@#include "../../core/Types.hpp"#include "../../core/Reflection.hpp"-#include "../../math/Math.hpp"-#include "../../resource/Handle.hpp"+#include "../../core/UITypes.hpp" // VisualState-#include <string>+#include <vector>namespace esengine::ecs {@@ -28,11 +27,11 @@ namespace StateVisualsTransition {/*** @brief Maps state names to visual overrides on a target entity.*- * @details Eight open slots, each labelled by `slotNName`. The visual- * system reads the owning entity's StateMachine.current, looks- * up the matching slot (empty names are treated as unused), and- * applies `color` / `sprite` / `scale` to `targetGraphic`- * according to `transitionFlags`.+ * @details A variable-length `states` list (REARCH_GUI F5 — replaced the old 8+ * hardcoded `slotN*` field quartets + stringly-keyed reflection). The+ * visual system reads the owning entity's StateMachine.current, finds+ * the matching VisualState by name, and applies its color / sprite /+ * scale to `targetGraphic` according to `transitionFlags`.** `targetGraphic == INVALID_ENTITY` means "apply to self".*/@@ -49,47 +48,9 @@ struct StateVisuals {ES_PROPERTY()f32 fadeDuration{0.0f};- // -- slots (8 × 4 = 32 fields) ---- ES_PROPERTY() std::string slot0Name;- ES_PROPERTY() glm::vec4 slot0Color{1.0f, 1.0f, 1.0f, 1.0f};- ES_PROPERTY(asset = texture) resource::TextureHandle slot0Sprite;- ES_PROPERTY() f32 slot0Scale{1.0f};-- ES_PROPERTY() std::string slot1Name;- ES_PROPERTY() glm::vec4 slot1Color{1.0f, 1.0f, 1.0f, 1.0f};- ES_PROPERTY(asset = texture) resource::TextureHandle slot1Sprite;- ES_PROPERTY() f32 slot1Scale{1.0f};-- ES_PROPERTY() std::string slot2Name;- ES_PROPERTY() glm::vec4 slot2Color{1.0f, 1.0f, 1.0f, 1.0f};- ES_PROPERTY(asset = texture) resource::TextureHandle slot2Sprite;- ES_PROPERTY() f32 slot2Scale{1.0f};-- ES_PROPERTY() std::string slot3Name;- ES_PROPERTY() glm::vec4 slot3Color{1.0f, 1.0f, 1.0f, 1.0f};- ES_PROPERTY(asset = texture) resource::TextureHandle slot3Sprite;- ES_PROPERTY() f32 slot3Scale{1.0f};-- ES_PROPERTY() std::string slot4Name;- ES_PROPERTY() glm::vec4 slot4Color{1.0f, 1.0f, 1.0f, 1.0f};- ES_PROPERTY(asset = texture) resource::TextureHandle slot4Sprite;- ES_PROPERTY() f32 slot4Scale{1.0f};-- ES_PROPERTY() std::string slot5Name;- ES_PROPERTY() glm::vec4 slot5Color{1.0f, 1.0f, 1.0f, 1.0f};- ES_PROPERTY(asset = texture) resource::TextureHandle slot5Sprite;- ES_PROPERTY() f32 slot5Scale{1.0f};-- ES_PROPERTY() std::string slot6Name;- ES_PROPERTY() glm::vec4 slot6Color{1.0f, 1.0f, 1.0f, 1.0f};- ES_PROPERTY(asset = texture) resource::TextureHandle slot6Sprite;- ES_PROPERTY() f32 slot6Scale{1.0f};-- ES_PROPERTY() std::string slot7Name;- ES_PROPERTY() glm::vec4 slot7Color{1.0f, 1.0f, 1.0f, 1.0f};- ES_PROPERTY(asset = texture) resource::TextureHandle slot7Sprite;- ES_PROPERTY() f32 slot7Scale{1.0f};+ /** @brief Named visual states; looked up by StateMachine.current. */+ ES_PROPERTY()+ std::vector<VisualState> states;};} // namespace esengine::ecsdiff --git a/tools/eht/field_utils.py b/tools/eht/field_utils.pyindex 021b2ca90..1cc412f4f 100644--- a/tools/eht/field_utils.py+++ b/tools/eht/field_utils.py@@ -85,7 +85,7 @@ def get_editor_type(prop: Property, types: TypeSystem) -> str:return 'int'if t in TypeSystem.GLM_TYPES or t in TypeSystem.CUSTOM_STRUCTS:return 'float' # Sub-components are all floats (or ints for uvec2)- if t in TypeSystem.VECTOR_TYPES:+ if types.is_any_vector(t):return 'skip' # Vector types not editable as simple fieldsreturn 'skip'@@ -153,7 +153,7 @@ def convert_default_ts(prop: Property, types: TypeSystem,if raw and raw.startswith('"') and raw.endswith('"'):return rawreturn "''"- if t in types.VECTOR_TYPES:+ if types.is_any_vector(t):return '[]'if t in types.CUSTOM_STRUCTS:members = types.CUSTOM_STRUCTS[t]diff --git a/tools/eht/generators/embind.py b/tools/eht/generators/embind.pyindex db9271e20..f1a6337da 100644--- a/tools/eht/generators/embind.py+++ b/tools/eht/generators/embind.py@@ -177,7 +177,11 @@ class EmbindGenerator:if self.types.is_skip(prop.cpp_type):continuejs_type = self.types.get_js_type(prop.cpp_type)- lines.append(f' {js_type} {prop.name};')+ if self.types.is_struct_vector(prop.cpp_type):+ # val has no default ctor usable for `{}` aggregate init.+ lines.append(f' {js_type} {prop.name} = emscripten::val::array();')+ else:+ lines.append(f' {js_type} {prop.name};')lines.append('};')lines.append('')@@ -196,6 +200,11 @@ class EmbindGenerator:elif t in self.types.VECTOR_TYPES and self.types.VECTOR_TYPES[t][0] == 'u32' and 'Entity' in t:lines.append(f' c.{prop.name}.reserve(js.{prop.name}.size());')lines.append(f' for (auto v : js.{prop.name}) c.{prop.name}.push_back(Entity(v));')+ elif self.types.is_struct_vector(t):+ elem = self.types.vector_elem(t)+ lines.append(f' {{ const size_t n = js.{prop.name}["length"].as<size_t>();')+ lines.append(f' c.{prop.name}.clear(); c.{prop.name}.reserve(n);')+ lines.append(f' for (size_t i = 0; i < n; ++i) c.{prop.name}.push_back(js.{prop.name}[i].as<esengine::{elem}>()); }}')else:lines.append(f' c.{prop.name} = js.{prop.name};')lines.append(' return c;')@@ -217,6 +226,9 @@ class EmbindGenerator:elif t in self.types.VECTOR_TYPES and self.types.VECTOR_TYPES[t][0] == 'u32' and 'Entity' in t:lines.append(f' js.{prop.name}.reserve(c.{prop.name}.size());')lines.append(f' for (auto e : c.{prop.name}) js.{prop.name}.push_back(static_cast<u32>(e));')+ elif self.types.is_struct_vector(t):+ lines.append(f' js.{prop.name} = emscripten::val::array();')+ lines.append(f' for (size_t i = 0; i < c.{prop.name}.size(); ++i) js.{prop.name}.set(i, emscripten::val(c.{prop.name}[i]));')else:lines.append(f' js.{prop.name} = c.{prop.name};')lines.append(' return js;')@@ -235,6 +247,8 @@ class EmbindGenerator:lines.append(f' register_vector<{elem_type}>("{js_name}");')lines.append('')registered_vectors.add(js_name)+ # Struct-vectors (std::vector<VisualState>) marshal as a JS array via+ # emscripten::val in the wrapper from/toJS — no register_vector needed.for comp in self.components:full = f'{comp.namespace}::{comp.name}' if comp.namespace else comp.namediff --git a/tools/eht/type_system.py b/tools/eht/type_system.pyindex 9d1d3b962..f6f975b1d 100644--- a/tools/eht/type_system.py+++ b/tools/eht/type_system.py@@ -1,6 +1,7 @@"""Type classification and C++/TypeScript mapping."""-from typing import Dict, List, Set+import re+from typing import Dict, List, Optional, Setfrom .data import Enum@@ -17,12 +18,23 @@ class TypeSystem:# Small POD structs usable as builtin component fields: serialized via embind,# sized for the pointer cursor, mirrored to a TS interface + editor controls.# Generalizes the former single Padding special case. Each entry maps a struct- # name to its ordered (member_name, member_cpp_type) list; member types must be- # primitives in PtrLayoutGenerator.TYPE_SIZES. The struct must be defined and- # included by WebBindings (core/UITypes.hpp) and be a standard C++ POD.+ # name to its ordered (member_name, member_cpp_type) list; the struct must be+ # defined in the esengine:: namespace and included by WebBindings+ # (core/UITypes.hpp) and be a standard C++ POD.+ #+ # Structs used as a DIRECT component field (Padding/Dimension) must have only+ # primitive members in PtrLayoutGenerator.TYPE_SIZES (they go through the+ # pointer cursor). Structs used ONLY as a `std::vector<Struct>` element+ # (VisualState) are exempt — vectors are never pointer-accessed — so they may+ # carry std::string members.CUSTOM_STRUCTS = {'Padding': [('left', 'f32'), ('top', 'f32'), ('right', 'f32'), ('bottom', 'f32')],'Dimension': [('value', 'f32'), ('unit', 'u8')],+ 'VisualState': [+ ('name', 'std::string'),+ ('r', 'f32'), ('g', 'f32'), ('b', 'f32'), ('a', 'f32'),+ ('sprite', 'u32'), ('scale', 'f32'),+ ],}SKIP_TYPES = {'glm::mat4', 'std::function'}@@ -71,6 +83,26 @@ class TypeSystem:def is_vector(self, cpp_type: str) -> bool:return self.clean_type(cpp_type) in self.VECTOR_TYPES+ def vector_elem(self, cpp_type: str) -> Optional[str]:+ """For `std::vector<X>`, return the element type X (stripped); else None."""+ m = re.fullmatch(r'std::vector<(.+)>', self.clean_type(cpp_type))+ return m.group(1).strip() if m else None++ def is_struct_vector(self, cpp_type: str) -> bool:+ """`std::vector<S>` where S is a registered CUSTOM_STRUCT (REARCH_GUI F5).+ Marshalled via embind register_vector<S> + value_object<S>; never+ pointer-accessed."""+ elem = self.vector_elem(cpp_type)+ return elem is not None and elem in self.CUSTOM_STRUCTS++ def is_any_vector(self, cpp_type: str) -> bool:+ return self.is_vector(cpp_type) or self.is_struct_vector(cpp_type)++ def struct_vector_js_name(self, cpp_type: str) -> str:+ """embind register_vector binding name for a struct-vector, e.g.+ std::vector<VisualState> -> VectorVisualState."""+ return f'Vector{self.vector_elem(cpp_type)}'+def is_skip(self, cpp_type: str) -> bool:t = self.clean_type(cpp_type)return t in self.SKIP_TYPES@@ -100,10 +132,12 @@ class TypeSystem:return t in self.VECTOR_TYPES and 'Entity' in tdef needs_wrapper(self, comp) -> bool:- """Check if a component needs a JS wrapper struct (has enum/handle/entity fields)."""+ """Check if a component needs a JS wrapper struct (has enum/handle/entity/+ struct-vector fields that must be converted at the boundary)."""for prop in comp.properties:if self.is_enum(prop.cpp_type) or self.is_handle(prop.cpp_type) \- or self.is_entity(prop.cpp_type) or self.is_entity_vector(prop.cpp_type):+ or self.is_entity(prop.cpp_type) or self.is_entity_vector(prop.cpp_type) \+ or self.is_struct_vector(prop.cpp_type):return Truereturn False@@ -117,6 +151,11 @@ class TypeSystem:if t in self.VECTOR_TYPES:elem_type = self.VECTOR_TYPES[t][0]return f'std::vector<{elem_type}>'+ if self.is_struct_vector(t):+ # embind can't auto-convert a JS array to a registered std::vector, so+ # the wrapper field is an emscripten::val (a JS array) and from/toJS+ # convert element-by-element via the VisualState value_object.+ return 'emscripten::val'return tdef to_typescript(self, cpp_type: str) -> str:@@ -129,6 +168,8 @@ class TypeSystem:return 'number'if t in self.VECTOR_TYPES:return self.VECTOR_TYPES[t][2]+ if self.is_struct_vector(t):+ return f'{self.vector_elem(t)}[]' # e.g. VisualState[]if t in self.CUSTOM_STRUCTS:return t # the struct name is its own TS interface namereturn 'unknown'