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(lighting): type-aware Light2D collection + editor eye/notice/icon for lights
yhhd2011164963e
diff --git a/desktop/src/engine/SceneQuery.ts b/desktop/src/engine/SceneQuery.tsindex 445bdda96..f65a89575 100644--- a/desktop/src/engine/SceneQuery.ts+++ b/desktop/src/engine/SceneQuery.ts@@ -9,6 +9,7 @@ import {inferField,isColorKey,componentEnable,+ componentNotice,modelInspectableComponents,modelKindOf,modelNameOf,@@ -81,7 +82,7 @@ export function buildInspector(const enable = componentEnable(name, cdata) ?? undefined;// The enable field is promoted to the header checkbox — drop it from the body.const fields = inspectorFields(name, cdata, baseOf?.(name)).filter((f) => f.key !== enable?.key);- out.push({ name, label, fields, enable });+ out.push({ name, label, fields, enable, notice: componentNotice(name, e) ?? undefined });}return out;}@@ -127,7 +128,7 @@ export function buildMultiInspector(for (const f of fields) {if (!datas.every((d) => deepEqual(d[f.key], datas[0][f.key]))) f.mixed = true;}- out.push({ name, label, fields, enable });+ out.push({ name, label, fields, enable, notice: componentNotice(name, primary) ?? undefined });}return out;}diff --git a/desktop/src/engine/schema.ts b/desktop/src/engine/schema.tsindex 4990e5d91..f57e1af4d 100644--- a/desktop/src/engine/schema.ts+++ b/desktop/src/engine/schema.ts@@ -1,6 +1,6 @@// SPDX-License-Identifier: Apache-2.0// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team-import { getAllRegisteredComponents, getUserComponents, getComponent, getComponentAssetFieldDescriptors, getComponentFieldMeta } from 'esengine';+import { getAllRegisteredComponents, getUserComponents, getComponent, getComponentAssetFieldDescriptors, getComponentFieldMeta, Light2DType } from 'esengine';import type { App, SceneData } from 'esengine';import type { NodeKind, InspectorField, EnumOption, GradientValue, CurveValue } from '@/types';@@ -36,10 +36,12 @@ export type AnyComp = Parameters<WorldT['has']>[1];const HIDDEN_COMPONENTS = new Set(['Parent', 'Children', 'Name']);// Components whose enable flag drives the entity's RENDER visibility (the Outliner// eye + hidden state). Disabling a non-render component (physics, audio, a script)-// turns that behaviour off without hiding the entity.+// turns that behaviour off without hiding the entity. Light2D/ShadowCaster2D belong+// here too: a hidden entity must stop lighting and shadowing the scene, not just+// stop drawing its own pixels.const RENDER_COMPONENTS = new Set(['Sprite', 'ShapeRenderer', 'SpineAnimation', 'BitmapText', 'TilemapLayer', 'ParticleEmitter',- 'UIVisual', 'Text',+ 'UIVisual', 'Text', 'Light2D', 'ShadowCaster2D',]);/** Whether a component's enable flag participates in the entity's render visibility. */export function isRenderComponent(name: string): boolean {@@ -115,9 +117,13 @@ const RAD2DEG = 180 / Math.PI;const DEG2RAD = Math.PI / 180;const cap = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);+// Word-split identifiers with acronym + digit-suffix awareness, so 'UIVisual'+// reads "UI Visual" (not "U I Visual") and 'Light2D' reads "Light 2D" (not "Light2 D").export const prettyLabel = (key: string) =>key- .replace(/([A-Z])/g, ' $1')+ .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2') // acronym→word: UIVisual → UI Visual+ .replace(/([a-z])([A-Z])/g, '$1 $2') // camelCase: orthoSize → ortho Size+ .replace(/([a-zA-Z])(\d)/g, '$1 $2') // digit run: Light2D → Light 2D.replace(/^./, (c) => c.toUpperCase()).trim();@@ -504,10 +510,32 @@ export function modelAddableComponentEntries(return out.sort((a, b) => a.label.localeCompare(b.label));}+// Light2D types whose contribution samples the entity's world position (the+// engine skips them without a Transform); Ambient/Directional need none.+const POSITIONAL_LIGHT_TYPES = new Set([Light2DType.Point, Light2DType.Spot]);++/**+ * A contextual inspector notice for a component on an entity — an entity state+ * that leaves the component silently inert, surfaced so the silence is+ * explainable (e.g. the render path skips a positional light with no Transform).+ */+export function componentNotice(compType: string, entity: SceneEntityLike): string | null {+ const hasTransform = entity.components.some((c) => c.type === 'Transform');+ if (hasTransform) return null;+ if (compType === 'Light2D') {+ const data = entity.components.find((c) => c.type === compType)?.data as { type?: number } | undefined;+ if (POSITIONAL_LIGHT_TYPES.has(Number(data?.type ?? 0)))+ return 'Point / Spot lights need a Transform for their position — this light is skipped.';+ }+ if (compType === 'ShadowCaster2D') return 'Needs a Transform to place its shadow box — this caster is skipped.';+ return null;+}+/** Outliner icon kind for a source entity (which components it carries). */export function modelKindOf(entity: SceneEntityLike): NodeKind {const types = new Set(entity.components.map((c) => c.type));if (types.has('Camera')) return 'camera';+ if (types.has('Light2D')) return 'light';if (types.has('SpineAnimation')) return 'spine';if (types.has('Canvas') || types.has('BitmapText')) return 'ui';if (types.has('Sprite') || types.has('ShapeRenderer') || types.has('TilemapLayer')) return 'sprite';diff --git a/desktop/src/panels/Details.tsx b/desktop/src/panels/Details.tsxindex 16eb16217..9944997b6 100644--- a/desktop/src/panels/Details.tsx+++ b/desktop/src/panels/Details.tsx@@ -1342,6 +1342,7 @@ function ComponentSection({</header><div className="comp-body"><div className="cinner">+ {comp.notice && <div className="comp-notice">{comp.notice}</div>}<div className="comp-fields">{ungrouped.map(row)}{[...groups].map(([cat, fields]) => (diff --git a/desktop/src/theme/inspector.css b/desktop/src/theme/inspector.cssindex b467b92da..06f0840bc 100644--- a/desktop/src/theme/inspector.css+++ b/desktop/src/theme/inspector.css@@ -88,6 +88,8 @@.comp.open .comp-body { grid-template-rows: 1fr; }.comp-body > .cinner { overflow: hidden; }.comp-fields { padding: 5px 8px 8px; }+/* contextual heads-up under a component header (silently-inert state, not an error) */+.comp-notice { margin: 6px 8px 0; padding: 5px 8px; font-size: var(--fs-2xs); line-height: 1.45; color: var(--warn); background: rgba(214, 166, 90, 0.10); border: 1px solid rgba(214, 166, 90, 0.25); border-radius: var(--r-sm); }/* property rows (label col + value col, reset on right) */.prop { display: grid; grid-template-columns: 38% 1fr 18px; align-items: center; gap: 4px; min-height: var(--h-prop); padding: 1px 0; position: relative; }diff --git a/desktop/src/types.ts b/desktop/src/types.tsindex e9bf35ab2..68bc6cafd 100644--- a/desktop/src/types.ts+++ b/desktop/src/types.ts@@ -130,6 +130,12 @@ export interface InspectorComponent {* disagrees (value is the primary's).*/enable?: { key: string; value: boolean; mixed?: boolean };+ /**+ * A contextual heads-up shown under the component header — an entity state+ * that leaves the component silently inert (e.g. a Point light with no+ * Transform to position it). Informational, not an error.+ */+ notice?: string;}export type AssetType =diff --git a/desktop/tests/schema.test.ts b/desktop/tests/schema.test.tsindex ddd0dd93f..2a115ccd1 100644--- a/desktop/tests/schema.test.ts+++ b/desktop/tests/schema.test.ts@@ -14,6 +14,12 @@ describe('prettyLabel', () => {expect(prettyLabel('position')).toBe('Position');expect(prettyLabel('isActive')).toBe('Is Active');});+ it('keeps acronyms and digit suffixes as words', () => {+ expect(prettyLabel('UIVisual')).toBe('UI Visual');+ expect(prettyLabel('Light2D')).toBe('Light 2D');+ expect(prettyLabel('ShadowCaster2D')).toBe('Shadow Caster 2D');+ expect(prettyLabel('BitmapText')).toBe('Bitmap Text');+ });});describe('hexToRgba', () => {diff --git a/src/esengine/ecs/components/Light2D.hpp b/src/esengine/ecs/components/Light2D.hppindex 4b536b2b7..e2708a669 100644--- a/src/esengine/ecs/components/Light2D.hpp+++ b/src/esengine/ecs/components/Light2D.hpp@@ -5,9 +5,11 @@* @brief 2D light source component for the Lit2D material domain.* @details A scene's Light2D components are gathered by the render collect path into the* per-frame LightConstants UBO (binding 2); Lit2D-domain material shaders read them- * via the injected applyLighting2D() helper. Point/Directional lights occupy a- * light slot; Ambient lights sum into the ambient term. World position comes from the- * entity's Transform — this component carries only the light's intrinsic parameters.+ * via the injected applyLighting2D() helper. Point/Directional/Spot lights occupy a+ * light slot; Ambient lights sum into the ambient term. This component carries only+ * the light's intrinsic parameters; Point/Spot read their world position from the+ * entity's Transform (and are skipped without one), while Ambient/Directional have+ * no spatial anchor and need no Transform.** @author ESEngine Team* @date 2026diff --git a/src/esengine/renderer/RenderFrame.cpp b/src/esengine/renderer/RenderFrame.cppindex bde084905..2b0988337 100644--- a/src/esengine/renderer/RenderFrame.cpp+++ b/src/esengine/renderer/RenderFrame.cpp@@ -512,9 +512,12 @@ void RenderFrame::collectLights(ecs::Registry& registry) {// whichever happened to come last in iteration order. Ambient lights sum without a cap.std::vector<GpuLight2D> collected;- auto view = registry.view<ecs::Transform, ecs::Light2D>();+ // A light's Transform need is type-dependent: Ambient (a flat scene-wide term) and+ // Directional (parallel rays; direction is intrinsic) have no spatial anchor and work+ // without one — only Point/Spot sample a world position.+ auto view = registry.view<ecs::Light2D>();for (auto entity : view) {- const auto& light = view.get<ecs::Light2D>(entity);+ const auto& light = view.get(entity);if (!light.enabled || light.intensity <= 0.0f) continue;const auto type = static_cast<ecs::Light2DType>(light.type);@@ -534,9 +537,10 @@ void RenderFrame::collectLights(ecs::Registry& registry) {// Direction in the 2D plane; z=1 flags directional (no attenuation) in the shader.gpu.posDir = glm::vec4(light.direction.x, light.direction.y, 1.0f, 0.0f);} else { // Point / Spot — world position from the Transform, w=falloff radius.- auto& transform = view.get<ecs::Transform>(entity);- transform.ensureDecomposed();- const glm::vec3 p = transform.worldPosition;+ auto* transform = registry.tryGet<ecs::Transform>(entity);+ if (!transform) continue; // a positional light with no position casts nothing+ transform->ensureDecomposed();+ const glm::vec3 p = transform->worldPosition;const f32 typeId = (type == ecs::Light2DType::Spot) ? 2.0f : 0.0f;gpu.posDir = glm::vec4(p.x, p.y, typeId, light.radius);if (type == ecs::Light2DType::Spot) {