Skip to content

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.

fix(sdk): close API gaps surfaced while documenting

esengine991c6c68b9bf
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index d548bea68..2dce22756 100644
--- a/sdk/etc/index.api.md
+++ b/sdk/etc/index.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 1238 stable · 17 beta · 0 deprecated
+Symbols: 1245 stable · 17 beta · 0 deprecated
## ABI_LAYOUT_HASH — const
```
@@ -320,6 +320,17 @@ type: AnimatorParamType
Readonly<Record<string, number | boolean>>
```
+## AnimatorPathEvalResult — interface
+```
+consumedTriggers: string[]
+nextPath: string | null
+```
+
+## AnimatorScope — type
+```
+Pick<AnimatorControllerDef, 'states' | 'initialState' | 'anyStateTransitions'>
+```
+
## AnimatorSpineMotion — interface
```
animation: string
@@ -338,6 +349,13 @@ stateMachine: AnimatorSubMachine | undefined
transitions: AnimatorTransition[]
```
+## AnimatorSubMachine — interface
+```
+anyStateTransitions: AnimatorTransition[] | undefined
+initialState: string
+states: AnimatorState[]
+```
+
## AnimatorTransition — interface
```
conditions: AnimatorCondition[]
@@ -5109,6 +5127,11 @@ Record<SideModuleId, SideModuleDescriptor>
readonly SpineVersion[]
```
+## STATE_PATH_SEP — const
+```
+"/"
+```
+
## SafeArea — const
```
ComponentDef<SafeAreaData>
@@ -8120,6 +8143,11 @@ DragPlugin
(def: BtDefinition): BtDefinition
```
+## enterStatePath — function
+```
+(scope: AnimatorScope, name: string): string[]
+```
+
## enumOptions — function
```
(obj: Record<string, unknown>, only?: readonly string[]): ReadonlyArray<{ label: string; value: number; }>
@@ -8140,6 +8168,11 @@ DragPlugin
(bb: Blackboard, guards: BlackboardGuard | BlackboardGuard[]): boolean
```
+## evaluateAnimatorPath — function
+```
+(def: AnimatorControllerDef, currentPath: string, params: AnimatorParamValues, triggers: ReadonlySet<string>, clipFinished?: boolean): AnimatorPathEvalResult
+```
+
## evaluateAnimatorTransitions — function
```
(def: AnimatorControllerDef, currentState: string, params: AnimatorParamValues, triggers: ReadonlySet<string>, clipFinished?: boolean): AnimatorEvalResult
@@ -8590,6 +8623,11 @@ InputRouter
(): boolean
```
+## leafStateOf — function
+```
+(def: AnimatorControllerDef, path: string): AnimatorState | null
+```
+
## lifecyclePlugin — const
```
(options?: LifecyclePluginOptions) => Plugin
@@ -9297,7 +9335,7 @@ Plugin
## setViewTarget — function
```
-(app: App, entity: number, opts?: { time?: number; curve?: number; }): void
+(host: CameraDirectorHost, entity: number, opts?: { time?: number; curve?: number; }): void
```
## setWasmErrorHandler — function
@@ -9307,7 +9345,7 @@ Plugin
## shakeCamera — function
```
-(app: App, opts?: { amplitude?: number; rotation?: number; frequency?: number; duration?: number; }): void
+(host: CameraDirectorHost, opts?: { amplitude?: number; rotation?: number; frequency?: number; duration?: number; }): void
```
## shapeCenter — function
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index ba76fcb4a..1150ddddd 100644
--- a/sdk/etc/index.node.api.md
+++ b/sdk/etc/index.node.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index.node
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 1237 stable · 19 beta · 0 deprecated
+Symbols: 1244 stable · 19 beta · 0 deprecated
## ANCHOR_AXES — const
```
@@ -315,6 +315,17 @@ type: AnimatorParamType
Readonly<Record<string, number | boolean>>
```
+## AnimatorPathEvalResult — interface
+```
+consumedTriggers: string[]
+nextPath: string | null
+```
+
+## AnimatorScope — type
+```
+Pick<AnimatorControllerDef, 'states' | 'initialState' | 'anyStateTransitions'>
+```
+
## AnimatorSpineMotion — interface
```
animation: string
@@ -333,6 +344,13 @@ stateMachine: AnimatorSubMachine | undefined
transitions: AnimatorTransition[]
```
+## AnimatorSubMachine — interface
+```
+anyStateTransitions: AnimatorTransition[] | undefined
+initialState: string
+states: AnimatorState[]
+```
+
## AnimatorTransition — interface
```
conditions: AnimatorCondition[]
@@ -5104,6 +5122,11 @@ Record<SideModuleId, SideModuleDescriptor>
readonly SpineVersion[]
```
+## STATE_PATH_SEP — const
+```
+"/"
+```
+
## SafeArea — const
```
ComponentDef<SafeAreaData>
@@ -8115,6 +8138,11 @@ DragPlugin
(def: BtDefinition): BtDefinition
```
+## enterStatePath — function
+```
+(scope: AnimatorScope, name: string): string[]
+```
+
## enumOptions — function
```
(obj: Record<string, unknown>, only?: readonly string[]): ReadonlyArray<{ label: string; value: number; }>
@@ -8135,6 +8163,11 @@ DragPlugin
(bb: Blackboard, guards: BlackboardGuard | BlackboardGuard[]): boolean
```
+## evaluateAnimatorPath — function
+```
+(def: AnimatorControllerDef, currentPath: string, params: AnimatorParamValues, triggers: ReadonlySet<string>, clipFinished?: boolean): AnimatorPathEvalResult
+```
+
## evaluateAnimatorTransitions — function
```
(def: AnimatorControllerDef, currentState: string, params: AnimatorParamValues, triggers: ReadonlySet<string>, clipFinished?: boolean): AnimatorEvalResult
@@ -8585,6 +8618,11 @@ InputRouter
(): boolean
```
+## leafStateOf — function
+```
+(def: AnimatorControllerDef, path: string): AnimatorState | null
+```
+
## lifecyclePlugin — const
```
(options?: LifecyclePluginOptions) => Plugin
@@ -9302,7 +9340,7 @@ Plugin
## setViewTarget — function
```
-(app: App, entity: number, opts?: { time?: number; curve?: number; }): void
+(host: CameraDirectorHost, entity: number, opts?: { time?: number; curve?: number; }): void
```
## setWasmErrorHandler — function
@@ -9312,7 +9350,7 @@ Plugin
## shakeCamera — function
```
-(app: App, opts?: { amplitude?: number; rotation?: number; frequency?: number; duration?: number; }): void
+(host: CameraDirectorHost, opts?: { amplitude?: number; rotation?: number; frequency?: number; duration?: number; }): void
```
## shapeCenter — function
diff --git a/sdk/src/camera/CameraDirector.ts b/sdk/src/camera/CameraDirector.ts
index 9fe6ea1f3..33a485b4f 100644
--- a/sdk/src/camera/CameraDirector.ts
+++ b/sdk/src/camera/CameraDirector.ts
@@ -123,18 +123,31 @@ export const CameraDirector = defineResource<CameraDirectorState>(
'CameraDirector',
);
+/**
+ * Where director commands land: the App (host code) or the CameraDirector
+ * resource state itself (systems — `Res(CameraDirector)`).
+ */
+export type CameraDirectorHost = App | CameraDirectorState;
+
+function directorOf(host: CameraDirectorHost): CameraDirectorState {
+ return typeof (host as App).getResource === 'function'
+ ? (host as App).getResource(CameraDirector)
+ : (host as CameraDirectorState);
+}
+
/**
* Switch the active view target, optionally blending over `time` seconds with an
* easing `curve`. Records intent; the director applies it on the next frame
* (snapshotting the current view as the blend start). `time<=0` (or no prior
- * view) is an instant cut.
+ * view) is an instant cut. Pass the App from host code, or the
+ * `Res(CameraDirector)` state from inside a system.
*/
export function setViewTarget(
- app: App,
+ host: CameraDirectorHost,
entity: number,
opts?: { time?: number; curve?: number },
): void {
- const dir = app.getResource(CameraDirector);
+ const dir = directorOf(host);
dir.hasPending = true;
dir.pendingTarget = entity;
dir.pendingTime = opts?.time ?? 0;
@@ -145,12 +158,13 @@ export function setViewTarget(
* Trigger a transient camera shake on the active view — a decaying perturbation
* applied to the rendered POV only (never to a camera's Transform, so it always
* recovers and never dirties the scene). The UE `StartCameraShake` analog.
+ * Pass the App from host code, or the `Res(CameraDirector)` state from a system.
*/
export function shakeCamera(
- app: App,
+ host: CameraDirectorHost,
opts?: { amplitude?: number; rotation?: number; frequency?: number; duration?: number },
): void {
- const dir = app.getResource(CameraDirector);
+ const dir = directorOf(host);
dir.shakes.push({
amplitude: opts?.amplitude ?? 12,
rotation: opts?.rotation ?? 0,
diff --git a/sdk/src/core-content.ts b/sdk/src/core-content.ts
index 2a7177fd7..4bf9e5d3f 100644
--- a/sdk/src/core-content.ts
+++ b/sdk/src/core-content.ts
@@ -253,6 +253,13 @@ export {
type AnimatorControllerDef,
type AnimatorParamValues,
type AnimatorEvalResult,
+ evaluateAnimatorPath,
+ enterStatePath,
+ leafStateOf,
+ STATE_PATH_SEP,
+ type AnimatorSubMachine,
+ type AnimatorScope,
+ type AnimatorPathEvalResult,
AnimationPlugin,
animationPlugin,
type TweenOptions,
diff --git a/src/esengine/ecs/components/Canvas.hpp b/src/esengine/ecs/components/Canvas.hpp
index 64cab46d9..30e489941 100644
--- a/src/esengine/ecs/components/Canvas.hpp
+++ b/src/esengine/ecs/components/Canvas.hpp
@@ -90,50 +90,6 @@ struct Canvas {
glm::vec4 backgroundColor{0.0f, 0.0f, 0.0f, 1.0f};
Canvas() = default;
-
- /**
- * @brief Calculate orthographic camera size for this canvas
- * @return Half-height in world units for orthographic projection
- */
- f32 getOrthoSize() const {
- return (static_cast<f32>(designResolution.y) * 0.5f) / pixelsPerUnit;
- }
-
- /**
- * @brief Calculate design aspect ratio
- * @return Width / Height ratio
- */
- f32 getDesignAspectRatio() const {
- return static_cast<f32>(designResolution.x) / static_cast<f32>(designResolution.y);
- }
-
- /**
- * @brief Calculate world size of the design resolution
- * @return Size in world units
- */
- glm::vec2 getWorldSize() const {
- return glm::vec2(designResolution) / pixelsPerUnit;
- }
-
- /**
- * @brief Convert pixel position to world position
- * @param pixelPos Position in pixels (origin at bottom-left)
- * @return Position in world units (centered origin)
- */
- glm::vec2 pixelToWorld(const glm::vec2& pixelPos) const {
- glm::vec2 worldSize = getWorldSize();
- return (pixelPos / pixelsPerUnit) - (worldSize * 0.5f);
- }
-
- /**
- * @brief Convert world position to pixel position
- * @param worldPos Position in world units
- * @return Position in pixels (origin at bottom-left)
- */
- glm::vec2 worldToPixel(const glm::vec2& worldPos) const {
- glm::vec2 worldSize = getWorldSize();
- return (worldPos + worldSize * 0.5f) * pixelsPerUnit;
- }
};
} // namespace esengine::ecs