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(eht): generate editor enum dropdowns from C++ enum-typed fields
yhh821e7447b382
diff --git a/sdk/src/component.generated.ts b/sdk/src/component.generated.tsindex 2a74a7d5d..4c43eb9eb 100644--- a/sdk/src/component.generated.ts+++ b/sdk/src/component.generated.ts@@ -55,6 +55,7 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {animatableFields: ['color.r', 'color.g', 'color.b', 'color.a'],fields: {fontSize: { min: 1 },+ align: { enum: [{ label: 'Left', value: 0 }, { label: 'Center', value: 1 }, { label: 'Right', value: 2 }] },layer: { step: 1 },},},@@ -93,7 +94,7 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {colorFields: [],animatableFields: ['orthoSize'],fields: {- projectionType: { tooltip: "Orthographic (2D) or Perspective projection." },+ projectionType: { enum: [{ label: 'Perspective', value: 0 }, { label: 'Orthographic', value: 1 }], tooltip: "Orthographic (2D) or Perspective projection." },fov: { min: 1, max: 179, unit: "°" },orthoSize: { min: 0, tooltip: "Half the visible height in world units (Orthographic)." },nearPlane: { min: 0, advanced: true },@@ -117,7 +118,7 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {animatableFields: [],fields: {pixelsPerUnit: { min: 1, tooltip: "Texture pixels mapped to one world unit." },- scaleMode: { tooltip: "How the canvas adapts the design resolution to the screen." },+ scaleMode: { enum: [{ label: 'FixedWidth', value: 0 }, { label: 'FixedHeight', value: 1 }, { label: 'Expand', value: 2 }, { label: 'Shrink', value: 3 }, { label: 'Match', value: 4 }], tooltip: "How the canvas adapts the design resolution to the screen." },matchWidthOrHeight: { min: 0, max: 1, slider: true, tooltip: "0 matches width, 1 matches height (Match mode only)." },},},@@ -179,6 +180,13 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {entityFields: [],colorFields: [],animatableFields: [],+ fields: {+ direction: { enum: [{ label: 'Row', value: 0 }, { label: 'Column', value: 1 }, { label: 'RowReverse', value: 2 }, { label: 'ColumnReverse', value: 3 }] },+ wrap: { enum: [{ label: 'NoWrap', value: 0 }, { label: 'Wrap', value: 1 }] },+ justifyContent: { enum: [{ label: 'Start', value: 0 }, { label: 'Center', value: 1 }, { label: 'End', value: 2 }, { label: 'SpaceBetween', value: 3 }, { label: 'SpaceAround', value: 4 }, { label: 'SpaceEvenly', value: 5 }] },+ alignItems: { enum: [{ label: 'Start', value: 0 }, { label: 'Center', value: 1 }, { label: 'End', value: 2 }, { label: 'Stretch', value: 3 }] },+ alignContent: { enum: [{ label: 'Start', value: 0 }, { label: 'Center', value: 1 }, { label: 'End', value: 2 }, { label: 'Stretch', value: 3 }, { label: 'SpaceBetween', value: 4 }, { label: 'SpaceAround', value: 5 }] },+ },},Interactable: {defaults: {@@ -333,6 +341,9 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {entityFields: [],colorFields: [],animatableFields: [],+ fields: {+ bodyType: { enum: [{ label: 'Static', value: 0 }, { label: 'Kinematic', value: 1 }, { label: 'Dynamic', value: 2 }] },+ },},SegmentCollider: {defaults: {@@ -527,6 +538,9 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {entityFields: [],colorFields: [],animatableFields: [],+ fields: {+ mode: { enum: [{ label: 'Scissor', value: 0 }, { label: 'Stencil', value: 1 }] },+ },},UINode: {defaults: {@@ -554,6 +568,10 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {entityFields: [],colorFields: [],animatableFields: [],+ fields: {+ position: { enum: [{ label: 'Relative', value: 0 }, { label: 'Absolute', value: 1 }] },+ alignSelf: { enum: [{ label: 'Auto', value: 0 }, { label: 'Start', value: 1 }, { label: 'Center', value: 2 }, { label: 'End', value: 3 }, { label: 'Stretch', value: 4 }] },+ },},UIVisual: {defaults: {@@ -574,6 +592,11 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {entityFields: [],colorFields: ['color'],animatableFields: ['color.r', 'color.g', 'color.b', 'color.a', 'fillAmount'],+ fields: {+ visualType: { enum: [{ label: 'None', value: 0 }, { label: 'SolidColor', value: 1 }, { label: 'Image', value: 2 }, { label: 'NineSlice', value: 3 }, { label: 'Tiled', value: 4 }, { label: 'Filled', value: 5 }] },+ fillMethod: { enum: [{ label: 'Horizontal', value: 0 }, { label: 'Vertical', value: 1 }] },+ fillOrigin: { enum: [{ label: 'Left', value: 0 }, { label: 'Right', value: 1 }, { label: 'Bottom', value: 2 }, { label: 'Top', value: 3 }] },+ },},Velocity: {defaults: {diff --git a/sdk/src/component.ts b/sdk/src/component.tsindex f3b72e0eb..12af7c234 100644--- a/sdk/src/component.ts+++ b/sdk/src/component.ts@@ -609,8 +609,9 @@ export const Camera = defineBuiltin<CameraData>('Camera',}),{fields: {- projectionType: { enum: enumOptions(ProjectionType) },- // A bitmask (ColorAndDepth = Color | Depth), so a multi-select, not a dropdown.+ // projectionType's dropdown is generated from the C++ ProjectionType enum.+ // clearFlags is a bitmask (ColorAndDepth = Color | Depth) — a curated bit+ // list (the C++ `flags` annotation suppresses the single-choice dropdown).clearFlags: { flags: [{ label: 'Color', value: 1 }, { label: 'Depth', value: 2 }] },// showFrustum is a TS-only editor field (no C++ Camera member), so its// metadata can't come from an annotation.@@ -620,16 +621,12 @@ export const Camera = defineBuiltin<CameraData>('Camera',);export const Canvas = defineBuiltin<CanvasData>('Canvas',+ // scaleMode's dropdown is generated from the C++ CanvasScaleMode enum.metaDefaults<CanvasData>('Canvas', {designResolution: { x: DEFAULT_DESIGN_WIDTH, y: DEFAULT_DESIGN_HEIGHT },pixelsPerUnit: DEFAULT_PIXELS_PER_UNIT,scaleMode: ScaleMode.FixedHeight,- }),- {- fields: {- scaleMode: { enum: enumOptions(ScaleMode, ['FixedWidth', 'FixedHeight', 'Expand', 'Shrink', 'Match']) },- },- }+ }));export const Velocity = defineBuiltin<VelocityData>('Velocity',diff --git a/sdk/src/physics/PhysicsComponents.ts b/sdk/src/physics/PhysicsComponents.tsindex f8bf2f43b..a5ca014cf 100644--- a/sdk/src/physics/PhysicsComponents.ts+++ b/sdk/src/physics/PhysicsComponents.ts@@ -6,7 +6,7 @@*/import type { Vec2 } from '../types';-import { defineBuiltin, defineComponent, enumOptions } from '../component';+import { defineBuiltin, defineComponent } from '../component';// Box2D collision filtering: a body's own layers (category) and the layers it// collides with (mask), as named bitmasks. Bit labels come from the project's@@ -128,7 +128,7 @@ export const RigidBody = defineBuiltin<RigidBodyData>('RigidBody', {enabled: true}, {fields: {- bodyType: { enum: enumOptions(BodyType) },+ // bodyType's dropdown is generated from the C++ BodyType enum.linearDamping: { min: 0, advanced: true },angularDamping: { min: 0, advanced: true },fixedRotation: { advanced: true },diff --git a/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snap b/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snapindex 3950c14f1..4dd8261ab 100644--- a/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snap+++ b/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snap@@ -3,6 +3,22 @@exports[`builtin FieldMeta (RC9-1 equivalence gate) > matches the golden snapshot of every builtin with declared field metadata 1`] = `{"BitmapText": {+ "align": {+ "enum": [+ {+ "label": "Left",+ "value": 0,+ },+ {+ "label": "Center",+ "value": 1,+ },+ {+ "label": "Right",+ "value": 2,+ },+ ],+ },"fontSize": {"min": 1,},diff --git a/src/esengine/bindings/EditorAPI.generated.cpp b/src/esengine/bindings/EditorAPI.generated.cppindex 46b6af222..218f2c097 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 97c7defd8d289607+ * @schema_hash 3f1d7938a00eacb9*/-#define ES_EDITOR_API_SCHEMA_HASH "97c7defd8d289607"+#define ES_EDITOR_API_SCHEMA_HASH "3f1d7938a00eacb9"#include <emscripten/bind.h>#include <string>diff --git a/src/esengine/ecs/components/Camera.hpp b/src/esengine/ecs/components/Camera.hppindex 6ffe79042..4a6bd3732 100644--- a/src/esengine/ecs/components/Camera.hpp+++ b/src/esengine/ecs/components/Camera.hpp@@ -104,7 +104,9 @@ struct Camera {ES_PROPERTY()glm::vec4 viewport{0.0f, 0.0f, 1.0f, 1.0f};- ES_PROPERTY(tooltip="Which buffers to clear before rendering this camera.")+ // A bitmask (ColorAndDepth = Color | Depth) → multi-select, so the curated bit+ // list lives in TS and the single-choice enum dropdown is suppressed (flags).+ ES_PROPERTY(flags, tooltip="Which buffers to clear before rendering this camera.")ClearFlags clearFlags{ClearFlags::ColorAndDepth};Camera() = default;diff --git a/tools/eht/generators/metadata.py b/tools/eht/generators/metadata.pyindex 35fb25c91..a1f6d27af 100644--- a/tools/eht/generators/metadata.py+++ b/tools/eht/generators/metadata.py@@ -48,15 +48,22 @@ class MetadataGenerator:def _get_field_meta(self, comp: Component) -> List[Tuple[str, List[Tuple[str, str]]]]:"""Build per-field editor-presentation metadata (the FieldMeta shape) from- ES_PROPERTY annotations. `enum`/`flags`/`gradient`/`curve` are intentionally- absent — they carry runtime TS constants (e.g. enumOptions(...)) and stay as- TS-side defineBuiltin overrides; everything expressible as a static annotation- is authored at the C++ site. Returns [(field, [(metaKey, jsLiteral), ...])].+ ES_PROPERTY annotations. An enum-TYPED field also gets its `enum` dropdown+ options generated straight from the C++ enum values (single source — no TS+ `enumOptions(...)` mirror); a field annotated `flags` is a bitmask, so its+ curated bit list stays in TS and the dropdown is suppressed. `gradient`/`curve`+ carry TS-only state and stay TS-side. Returns [(field, [(metaKey, jsLiteral), ...])]."""out: List[Tuple[str, List[Tuple[str, str]]]] = []for prop in comp.properties:a = prop.annotationsentries: List[Tuple[str, str]] = []+ if self.types.is_enum(prop.cpp_type) and 'flags' not in a:+ vals = self.types.get_enum_values(prop.cpp_type)+ opts = ', '.join(+ f"{{ label: '{v}', value: {i} }}" for i, v in enumerate(vals)+ )+ entries.append(('enum', f'[{opts}]'))if 'min' in a:entries.append(('min', format_number(a['min'])))if 'max' in a:diff --git a/tools/eht/parser.py b/tools/eht/parser.pyindex 3baa481ae..d8ecba699 100644--- a/tools/eht/parser.py+++ b/tools/eht/parser.py@@ -40,6 +40,10 @@ class CppParser:FLAG_ANNOTATIONS = frozenset({'animatable', 'anim_override', 'entity_ref', 'readonly','slider', 'advanced', 'skip_serialize', 'replicated',+ # An enum-typed field renders as a multi-select bitmask instead of a single-+ # choice dropdown; suppresses the auto-generated `enum` options (the bit list+ # is curated in TS — combined values like ColorAndDepth aren't single bits).+ 'flags',})KV_ANNOTATIONS = frozenset({'asset', 'anim_flag', 'min', 'max', 'step', 'unit', 'label',