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 enum dropdowns for i32 fields via enum= annotation
yhhe5010f095539
diff --git a/sdk/src/component.generated.ts b/sdk/src/component.generated.tsindex 4c43eb9eb..71a49e333 100644--- a/sdk/src/component.generated.ts+++ b/sdk/src/component.generated.ts@@ -217,7 +217,7 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {colorFields: ['color'],animatableFields: ['color.r', 'color.g', 'color.b', 'color.a', 'intensity', 'radius', 'innerAngle', 'outerAngle', 'shadowSoftness', 'shadowDistance'],fields: {- type: { tooltip: "Point, Directional, Ambient, or Spot." },+ type: { enum: [{ label: 'Point', value: 0 }, { label: 'Directional', value: 1 }, { label: 'Ambient', value: 2 }, { label: 'Spot', value: 3 }], tooltip: "Point, Directional, Ambient, or Spot." },intensity: { min: 0, tooltip: "Brightness multiplier of the light." },radius: { min: 0, tooltip: "Falloff reach in world units (Point / Spot)." },direction: { tooltip: "Aim direction (Directional / Spot).", advanced: true },@@ -294,7 +294,7 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {maxParticles: { min: 1, step: 1, category: "Emission" },lifetimeMin: { min: 0, category: "Lifetime" },lifetimeMax: { min: 0, category: "Lifetime" },- shape: { category: "Shape" },+ shape: { enum: [{ label: 'Point', value: 0 }, { label: 'Circle', value: 1 }, { label: 'Rectangle', value: 2 }, { label: 'Cone', value: 3 }], category: "Shape" },shapeRadius: { min: 0, category: "Shape" },shapeSize: { category: "Shape" },shapeAngle: { unit: "°", category: "Shape" },@@ -324,7 +324,7 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {blendMode: { category: "Rendering" },layer: { step: 1, category: "Rendering", enumSource: "sortingLayers" },material: { category: "Rendering" },- simulationSpace: { category: "Rendering" },+ simulationSpace: { enum: [{ label: 'World', value: 0 }, { label: 'Local', value: 1 }], category: "Rendering" },},},RigidBody: {diff --git a/sdk/src/component.ts b/sdk/src/component.tsindex 12af7c234..f47ff1fad 100644--- a/sdk/src/component.ts+++ b/sdk/src/component.ts@@ -590,9 +590,9 @@ export const ShapeRenderer = defineBuiltin<ShapeRendererData>('ShapeRenderer',{ fields: { shapeType: { enum: enumOptions(ShapeType) } } });+// type's dropdown is generated from the C++ Light2DType enum (ES_PROPERTY enum=).export const Light2D = defineBuiltin<Light2DData>('Light2D',- metaDefaults<Light2DData>('Light2D'),- { fields: { type: { enum: enumOptions(Light2DType) } } }+ metaDefaults<Light2DData>('Light2D'));export const ShadowCaster2D = defineBuiltin<ShadowCaster2DData>('ShadowCaster2D',@@ -691,16 +691,15 @@ export interface ParticleEmitterData extends ParticleEmitterDataCpp {export const ParticleEmitter = defineBuiltin<ParticleEmitterData>('ParticleEmitter',metaDefaults<ParticleEmitterData>('ParticleEmitter', { colorGradient: { stops: [] }, sizeCurve: { keys: [] } }),{- // Field categories + min/step/unit are authored at the C++ ES_PROPERTY site- // (→ COMPONENT_META.fields). Only what an annotation can't express stays here:- // enums built from runtime TS constants, and the two TS-only editor fields- // (sizeCurve / colorGradient have no C++ member, so their metadata lives here).+ // Most field metadata is authored at the C++ ES_PROPERTY site (categories,+ // min/step, and the shape/simulationSpace enum dropdowns via `enum=`). Only+ // what an annotation can't express stays here: enums built from a TS-only+ // constant (ParticleEasing / BlendMode have no component ES_ENUM), and the two+ // TS-only editor fields (sizeCurve / colorGradient have no C++ member).fields: {- shape: { enum: enumOptions(EmitterShape) },sizeEasing: { enum: enumOptions(ParticleEasing) },colorEasing: { enum: enumOptions(ParticleEasing) },blendMode: { enum: enumOptions(BlendMode) },- simulationSpace: { enum: enumOptions(SimulationSpace) },sizeCurve: { curve: true, category: 'Size' },colorGradient: { gradient: true, category: 'Color' },},diff --git a/src/esengine/bindings/EditorAPI.generated.cpp b/src/esengine/bindings/EditorAPI.generated.cppindex 218f2c097..15a3e7c85 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 3f1d7938a00eacb9+ * @schema_hash 4cdc83e88b77776d*/-#define ES_EDITOR_API_SCHEMA_HASH "3f1d7938a00eacb9"+#define ES_EDITOR_API_SCHEMA_HASH "4cdc83e88b77776d"#include <emscripten/bind.h>#include <string>diff --git a/src/esengine/ecs/components/Light2D.hpp b/src/esengine/ecs/components/Light2D.hppindex 69e8a4a17..40af22c18 100644--- a/src/esengine/ecs/components/Light2D.hpp+++ b/src/esengine/ecs/components/Light2D.hpp@@ -48,7 +48,7 @@ enum class Light2DType : i32 {ES_COMPONENT()struct Light2D {/** @brief Light kind: 0 = Point, 1 = Directional, 2 = Ambient (see Light2DType). */- ES_PROPERTY(tooltip="Point, Directional, Ambient, or Spot.")+ ES_PROPERTY(enum=Light2DType, tooltip="Point, Directional, Ambient, or Spot.")i32 type{0};/** @brief Light color, multiplied by intensity. RGBA for editor color-picker consistencydiff --git a/src/esengine/ecs/components/ParticleEmitter.hpp b/src/esengine/ecs/components/ParticleEmitter.hppindex e6c32fe4f..e73d5746a 100644--- a/src/esengine/ecs/components/ParticleEmitter.hpp+++ b/src/esengine/ecs/components/ParticleEmitter.hpp@@ -55,8 +55,8 @@ struct ParticleEmitter {ES_PROPERTY(min=0, category=Lifetime)f32 lifetimeMax{5.0f};- // Shape (shape kind enum stays a TS-side override — runtime enumOptions constant)- ES_PROPERTY(category=Shape)+ // Shape kind — i32 storage, dropdown generated from the EmitterShape enum.+ ES_PROPERTY(enum=EmitterShape, category=Shape)i32 shape{static_cast<i32>(EmitterShape::Cone)};ES_PROPERTY(min=0, category=Shape)@@ -143,7 +143,8 @@ struct ParticleEmitter {ES_PROPERTY(category=Texture)bool spriteLoop{true};- // Rendering (blendMode/simulationSpace enums stay TS-side overrides)+ // Rendering — blendMode keeps a TS override (BlendMode is a renderer-side enum,+ // not a component ES_ENUM); simulationSpace's dropdown is generated (see below).ES_PROPERTY(category=Rendering)i32 blendMode{1};@@ -153,8 +154,8 @@ struct ParticleEmitter {ES_PROPERTY(asset = material, category=Rendering)u32 material{0};- // Space- ES_PROPERTY(category=Rendering)+ // Space — i32 storage, dropdown generated from the SimulationSpace enum.+ ES_PROPERTY(enum=SimulationSpace, category=Rendering)i32 simulationSpace{static_cast<i32>(SimulationSpace::World)};// Statediff --git a/tools/eht/generators/metadata.py b/tools/eht/generators/metadata.pyindex a1f6d27af..e1d3987f6 100644--- a/tools/eht/generators/metadata.py+++ b/tools/eht/generators/metadata.py@@ -58,12 +58,18 @@ class MetadataGenerator: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}]'))+ # The dropdown enum is the field's own enum type, or — for an int field+ # kept as i32 — the `enum=SomeEnum` annotation. A `flags` field is a+ # bitmask (curated bit list lives in TS), so no single-choice dropdown.+ enum_name = (self.types.clean_type(prop.cpp_type)+ if self.types.is_enum(prop.cpp_type) else a.get('enum'))+ if enum_name and 'flags' not in a:+ vals = self.types.get_enum_values(enum_name)+ if vals:+ 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 d8ecba699..e59b8e4e2 100644--- a/tools/eht/parser.py+++ b/tools/eht/parser.py@@ -48,6 +48,10 @@ class CppParser:KV_ANNOTATIONS = frozenset({'asset', 'anim_flag', 'min', 'max', 'step', 'unit', 'label','tooltip', 'category', 'enum_source', 'bitmask_source', 'invalidates',+ # `enum=SomeEnum` links an int field to a C++ ES_ENUM so EHT generates the+ # editor dropdown from that enum's values — for fields kept as i32 (not the+ # enum type) but still single-choice. Enum-TYPED fields need no annotation.+ 'enum',})NUMERIC_ANNOTATIONS = frozenset({'min', 'max', 'step'})VALID_ASSET_TYPES = frozenset({