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
An activation track can switch a UI node off, which is what it is for
yhh372ecbc8226b
diff --git a/sdk/src/timeline/TimelineRuntime.ts b/sdk/src/timeline/TimelineRuntime.tsindex f5cea03ad..a6336deb7 100644--- a/sdk/src/timeline/TimelineRuntime.ts+++ b/sdk/src/timeline/TimelineRuntime.ts@@ -2,6 +2,9 @@// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Teamimport { getComponent, SpineAnimation } from '../ecs/component';import { SpriteAnimator } from '../animation/SpriteAnimator';+// Straight from the generated enum module (the C++ ES_ENUM is the single source), not+// via the UI barrel: this file is core runtime and must not pull the UI module in.+import { UIDisplay } from '../wasm/wasm.generated';import type { AudioAPI } from '../audio/Audio';import type { Entity } from '../types';import type { World } from '../ecs/world';@@ -128,6 +131,17 @@ export function applyTimelineEvent(world.set(entity, Sprite, { ...current, enabled: active });}}+ // A UI node has no `enabled`: `display` is its show/hide, and the only one+ // that takes the subtree with it — which is what an activation track means+ // when it switches a whole widget off (a closed chest, an idle badge).+ const UINode = getComponent('UINode');+ if (UINode && world.has(entity, UINode)) {+ const current = world.get(entity, UINode);+ const display = active ? UIDisplay.Flex : UIDisplay.None;+ if (current.display !== display) {+ world.insert(entity, UINode, { ...current, display });+ }+ }break;}}diff --git a/sdk/tests/timeline-runtime.test.ts b/sdk/tests/timeline-runtime.test.tsnew file mode 100644index 000000000..19f9f1c05--- /dev/null+++ b/sdk/tests/timeline-runtime.test.ts@@ -0,0 +1,70 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+import { describe, it, expect } from 'vitest';+import { applyTimelineEvent, TimelineEventType } from '../src/timeline/TimelineRuntime';+// Importing the component modules is what puts them in the builtin registry, which is+// where `applyTimelineEvent` looks them up by name.+import { UINode, UIDisplay } from '../src/ui/core/ui-node';+import { Sprite } from '../src/ecs/component';++const ENTITY = 7;++/** The slice of World the event dispatcher touches, with a write counter per component. */+function mockWorld(initial: Array<[object, Record<string, unknown>]>) {+ const store = new Map<object, Record<string, unknown>>(initial);+ const writes = new Map<object, number>();+ return {+ writes,+ store,+ has: (_e: number, def: object) => store.has(def),+ get: (_e: number, def: object) => ({ ...store.get(def)! }),+ set: (_e: number, def: object, data: Record<string, unknown>) => {+ store.set(def, data);+ writes.set(def, (writes.get(def) ?? 0) + 1);+ },+ insert: (_e: number, def: object, data: Record<string, unknown>) => {+ store.set(def, data);+ writes.set(def, (writes.get(def) ?? 0) + 1);+ },+ };+}++const activate = (world: ReturnType<typeof mockWorld>, active: boolean) =>+ applyTimelineEvent(world, null, TimelineEventType.ActivationSet, ENTITY, active ? 1 : 0, 0, '');++describe('applyTimelineEvent — ActivationSet', () => {+ it('drives a UI node through `display`, the only show/hide that takes the subtree', () => {+ const world = mockWorld([[UINode, { display: UIDisplay.Flex, opacity: 1 }]]);++ activate(world, false);+ expect(world.store.get(UINode)!.display).toBe(UIDisplay.None);++ activate(world, true);+ expect(world.store.get(UINode)!.display).toBe(UIDisplay.Flex);+ // The rest of the node is untouched — activation is not a component reset.+ expect(world.store.get(UINode)!.opacity).toBe(1);+ });++ it('writes only when the state flips: it fires every frame the track is evaluated', () => {+ const world = mockWorld([[UINode, { display: UIDisplay.Flex }]]);++ activate(world, true);+ activate(world, true);+ expect(world.writes.get(UINode) ?? 0).toBe(0);++ activate(world, false);+ activate(world, false);+ expect(world.writes.get(UINode)).toBe(1);+ });++ it('still drives a plain sprite through `enabled`, and both when an entity has both', () => {+ const world = mockWorld([+ [Sprite, { enabled: true }],+ [UINode, { display: UIDisplay.Flex }],+ ]);++ activate(world, false);+ expect(world.store.get(Sprite)!.enabled).toBe(false);+ expect(world.store.get(UINode)!.display).toBe(UIDisplay.None);+ });+});