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.

feat: add timeline setWrapMode binding and improve MCP tool descriptions

esengine675a95d4bd8e
diff --git a/sdk/src/wasm.ts b/sdk/src/wasm.ts
index 3696bd5e8..56d6c15fd 100644
--- a/sdk/src/wasm.ts
+++ b/sdk/src/wasm.ts
@@ -337,6 +337,7 @@ export interface ESEngineModule {
_tl_stop(handle: number): void;
_tl_setTime(handle: number, time: number): void;
_tl_setSpeed(handle: number, speed: number): void;
+ _tl_setWrapMode(handle: number, mode: number): void;
_tl_getTime(handle: number): number;
_tl_isPlaying(handle: number): number;
_tl_advance(registry: CppRegistry, handle: number, rootEntity: number,
diff --git a/src/esengine/animation/TimelineSystem.cpp b/src/esengine/animation/TimelineSystem.cpp
index a24710da6..6765c6a0d 100644
--- a/src/esengine/animation/TimelineSystem.cpp
+++ b/src/esengine/animation/TimelineSystem.cpp
@@ -70,6 +70,12 @@ void TimelineSystem::setSpeed(TimelineHandle handle, f32 speed) {
}
}
+void TimelineSystem::setWrapMode(TimelineHandle handle, TimelineWrapMode mode) {
+ if (auto* inst = getInstance(handle)) {
+ inst->data.wrapMode = mode;
+ }
+}
+
f32 TimelineSystem::getTime(TimelineHandle handle) const {
if (auto* inst = getInstance(handle)) {
return inst->currentTime;
diff --git a/src/esengine/animation/TimelineSystem.hpp b/src/esengine/animation/TimelineSystem.hpp
index 416477fb0..3a7f43686 100644
--- a/src/esengine/animation/TimelineSystem.hpp
+++ b/src/esengine/animation/TimelineSystem.hpp
@@ -46,6 +46,7 @@ public:
void stop(TimelineHandle handle);
void setTime(TimelineHandle handle, f32 time);
void setSpeed(TimelineHandle handle, f32 speed);
+ void setWrapMode(TimelineHandle handle, TimelineWrapMode mode);
f32 getTime(TimelineHandle handle) const;
bool isPlaying(TimelineHandle handle) const;
bool isStopped(TimelineHandle handle) const;
diff --git a/src/esengine/bindings/TimelineBindings.cpp b/src/esengine/bindings/TimelineBindings.cpp
index 39e9a4fd0..781b0d9f6 100644
--- a/src/esengine/bindings/TimelineBindings.cpp
+++ b/src/esengine/bindings/TimelineBindings.cpp
@@ -239,6 +239,7 @@ void tl_pause(u32 handle) { if (auto* s = tlSys()) s->pause(handle); }
void tl_stop(u32 handle) { if (auto* s = tlSys()) s->stop(handle); }
void tl_setTime(u32 handle, f32 time) { if (auto* s = tlSys()) s->setTime(handle, time); }
void tl_setSpeed(u32 handle, f32 speed) { if (auto* s = tlSys()) s->setSpeed(handle, speed); }
+void tl_setWrapMode(u32 handle, i32 mode) { if (auto* s = tlSys()) s->setWrapMode(handle, static_cast<animation::TimelineWrapMode>(mode)); }
f32 tl_getTime(u32 handle) { auto* s = tlSys(); return s ? s->getTime(handle) : 0.0f; }
i32 tl_isPlaying(u32 handle) { auto* s = tlSys(); return s && s->isPlaying(handle) ? 1 : 0; }
@@ -368,6 +369,7 @@ EMSCRIPTEN_BINDINGS(esengine_timeline) {
emscripten::function("_tl_stop", &esengine::tl_stop);
emscripten::function("_tl_setTime", &esengine::tl_setTime);
emscripten::function("_tl_setSpeed", &esengine::tl_setSpeed);
+ emscripten::function("_tl_setWrapMode", &esengine::tl_setWrapMode);
emscripten::function("_tl_getTime", &esengine::tl_getTime);
emscripten::function("_tl_isPlaying", &esengine::tl_isPlaying);
emscripten::function("_tl_advance", &esengine::tl_advance);
diff --git a/tools/mcp-server/src/tools/actions.ts b/tools/mcp-server/src/tools/actions.ts
index 540c21ab4..673317a2d 100644
--- a/tools/mcp-server/src/tools/actions.ts
+++ b/tools/mcp-server/src/tools/actions.ts
@@ -19,7 +19,14 @@ export function registerActionTools(
server.tool(
'set_property',
- 'Set a component property on an entity (supports undo)',
+ `Set a component property on an entity (supports undo).
+Common component fields:
+- Transform: position {x,y,z}, rotation {x,y,z,w}, scale {x,y,z}
+- Sprite: texture (UUID), color {r,g,b,a}, size {x,y}, enabled, flipX, flipY
+- TimelinePlayer: timeline (asset UUID), playing (bool), speed (number), wrapMode ("once"|"loop"|"pingPong")
+- SpriteAnimator: clip (esanim asset UUID or registered name), playing (bool)
+- Camera: orthoSize (number)
+Use get_component_schema for full field list of any component.`,
{
entity: z.union([z.number(), z.string()]).describe('Entity ID or name'),
component: z.string().describe('Component type (e.g., "Transform", "Sprite")'),
diff --git a/tools/mcp-server/src/tools/scene.ts b/tools/mcp-server/src/tools/scene.ts
index 15d4d6196..9c3c79e6c 100644
--- a/tools/mcp-server/src/tools/scene.ts
+++ b/tools/mcp-server/src/tools/scene.ts
@@ -113,7 +113,11 @@ export function registerSceneTools(
server.tool(
'add_component',
- 'Add a component to an entity (defaults are auto-filled)',
+ `Add a component to an entity (defaults are auto-filled). Use list_components to see available types.
+Key components for animation:
+- TimelinePlayer: { timeline: "<.estimeline UUID>", playing: false, speed: 1, wrapMode: "once" }
+- SpriteAnimator: { clip: "<.esanim UUID>", playing: false }
+To play esanim via timeline: entity needs both TimelinePlayer and SpriteAnimator, and the timeline must have a spriteAnim track referencing the esanim asset.`,
{
entity: z.union([z.number(), z.string()]).describe('Entity ID or name'),
component: z.string().describe('Component type (e.g., "Transform", "Sprite", "RigidBody")'),
diff --git a/tools/mcp-server/src/tools/state.ts b/tools/mcp-server/src/tools/state.ts
index a6ff0c22c..efb99646d 100644
--- a/tools/mcp-server/src/tools/state.ts
+++ b/tools/mcp-server/src/tools/state.ts
@@ -94,7 +94,8 @@ export function registerStateTools(
server.tool(
'get_timeline_data',
- 'Get timeline asset data (tracks, duration, wrapMode)',
+ `Get timeline asset data. Returns { duration, wrapMode, tracks[] }.
+Use list_assets with type="timeline" to find timeline UUIDs, or get_entity_data to read TimelinePlayer.timeline field.`,
{
uuid: z.string().optional().describe('Timeline asset UUID'),
path: z.string().optional().describe('Timeline asset relative path'),
@@ -108,11 +109,57 @@ export function registerStateTools(
server.tool(
'update_timeline_data',
- 'Update timeline asset: add/modify tracks, keyframes, markers, events, duration',
+ `Update a .estimeline asset file. Provide uuid/path plus any top-level fields to patch (tracks, duration, wrapMode).
+
+IMPORTANT: "tracks" replaces the full array — always read first with get_timeline_data, modify, then write back.
+
+## How timeline works
+- An entity needs a TimelinePlayer component with "timeline" field set to the .estimeline asset UUID.
+- The entity also needs the target components (Transform, Sprite, SpriteAnimator, etc.) that the tracks animate.
+- To control esanim: add a spriteAnim track referencing the .esanim asset UUID. The entity must also have a SpriteAnimator component.
+- Use set_property to change TimelinePlayer fields (wrapMode, playing, speed) on the entity.
+
+## Track type schemas
+
+### property — animate component fields with keyframes
+{ type: "property", name: string, component: "Transform"|"Sprite"|"UIRect"|..., childPath: "" (or "ChildName/GrandChild"),
+ channels: [{ property: "position.x"|"scale.y"|"color.r"|...,
+ keyframes: [{ time: number, value: number, inTangent: 0, outTangent: 0, interpolation: "linear"|"easeIn"|"easeOut"|"easeInOut"|"step"|"hermite" }] }] }
+
+### spine — play spine animations on SpineAnimation component
+{ type: "spine", name: string, childPath: "",
+ clips: [{ start: number, duration: number, animation: "idle"|..., speed: 1, loop: true }], blendIn: 0 }
+
+### spriteAnim — trigger a SpriteAnimator clip (esanim). Entity must have SpriteAnimator component.
+{ type: "spriteAnim", name: string, childPath: "",
+ clip: "<esanim-asset-UUID-or-path>", startTime: 0 }
+
+### audio — play audio clips
+{ type: "audio", name: string, childPath: "",
+ events: [{ time: number, clip: "<audio-asset-UUID>", volume: 1 }] }
+
+### activation — show/hide entity in time ranges
+{ type: "activation", name: string, childPath: "",
+ ranges: [{ start: number, end: number }] }
+
+### marker — named time markers (no runtime effect, for editor use)
+{ type: "marker", name: string, childPath: "",
+ markers: [{ time: number, name: string }] }
+
+### customEvent — custom events with payload
+{ type: "customEvent", name: string, childPath: "",
+ events: [{ time: number, name: string, payload: {} }] }
+
+## Example: add a spriteAnim track to play idle.esanim at t=0
+1. get_timeline_data({ uuid: "..." }) → read existing tracks
+2. Append: { type: "spriteAnim", name: "Idle", childPath: "", clip: "<idle.esanim-uuid>", startTime: 0 }
+3. update_timeline_data({ uuid: "...", tracks: [...existing, newTrack] })
+4. Ensure the entity has SpriteAnimator component: add_component({ entity: id, component: "SpriteAnimator", data: { clip: "<idle.esanim-uuid>" } })
+5. Set loop playback: set_property({ entity: id, component: "TimelinePlayer", field: "wrapMode", value: "loop" })`,
{
uuid: z.string().optional().describe('Timeline asset UUID'),
path: z.string().optional().describe('Timeline asset relative path'),
- tracks: z.array(z.record(z.unknown())).optional().describe('Full tracks array to replace'),
+ tracks: z.array(z.record(z.unknown())).optional().describe('Full tracks array to replace (read first, modify, write back)'),
duration: z.number().optional().describe('Timeline duration in seconds'),
wrapMode: z.string().optional().describe('Wrap mode: once, loop, pingPong'),
},