From e90d5d5d82764bd96d5769c5efb8b83de29d039d Mon Sep 17 00:00:00 2001 From: Davide Tantillo Date: Thu, 6 Nov 2025 10:48:25 +0100 Subject: [PATCH] Add set-animation-time. --- spine-ts/spine-construct3/src/aces.json | 23 +++++++++++++++++++ .../spine-construct3/src/c3runtime/actions.ts | 4 ++++ .../src/c3runtime/instance.ts | 21 +++++++++++++++++ spine-ts/spine-construct3/src/lang/en-US.json | 23 +++++++++++++++++++ spine-ts/spine-construct3/src/lang/zh-CN.json | 23 +++++++++++++++++++ 5 files changed, 94 insertions(+) diff --git a/spine-ts/spine-construct3/src/aces.json b/spine-ts/spine-construct3/src/aces.json index 42a551fde..81ac3b657 100644 --- a/spine-ts/spine-construct3/src/aces.json +++ b/spine-ts/spine-construct3/src/aces.json @@ -198,6 +198,29 @@ "type": "number" } ] + }, + { + "id": "set-animation-time", + "scriptName": "SetAnimationTime", + "highlight": false, + "params": [ + { + "id": "units", + "type": "combo", + "items": [ + "seconds", + "ratio" + ] + }, + { + "id": "time", + "type": "number" + }, + { + "id": "track", + "type": "number" + } + ] } ], "expressions": [ diff --git a/spine-ts/spine-construct3/src/c3runtime/actions.ts b/spine-ts/spine-construct3/src/c3runtime/actions.ts index f1817bac5..cf65d94ce 100644 --- a/spine-ts/spine-construct3/src/c3runtime/actions.ts +++ b/spine-ts/spine-construct3/src/c3runtime/actions.ts @@ -55,6 +55,10 @@ C3.Plugins.EsotericSoftware_SpineConstruct3.Acts = SetAnimationSpeed (this: SDKInstanceClass, speed: number) { this.setAnimationSpeed(speed); + }, + + SetAnimationTime (this: SDKInstanceClass, units: 0 | 1, time: number, track: number) { + this.setAnimationTime(units, time, track); } }; diff --git a/spine-ts/spine-construct3/src/c3runtime/instance.ts b/spine-ts/spine-construct3/src/c3runtime/instance.ts index 4e1aa2015..120aa6a61 100644 --- a/spine-ts/spine-construct3/src/c3runtime/instance.ts +++ b/spine-ts/spine-construct3/src/c3runtime/instance.ts @@ -228,6 +228,27 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase { this.animationSpeed = speed; } + public setAnimationTime (units: 0 | 1, time: number, track: number) { + if (!this.state) return; + + const trackEntry = this.state.tracks[track]; + if (!trackEntry) return; + + if (units === 0) { + if (time < trackEntry.animationStart || time > trackEntry.animationEnd) { + console.warn(`[Spine] Animation time ${time} is out of bounds [${trackEntry.animationStart}, ${trackEntry.animationEnd}]`); + return; + } + trackEntry.trackTime = time; + } else { + if (time < 0 || time > 1) { + console.warn(`[Spine] Animation time ratio ${time} is out of bounds [0, 1]`); + return; + } + trackEntry.trackTime = time * (trackEntry.animationEnd - trackEntry.animationStart); + } + } + private _setSkin () { const { skeleton } = this; if (!skeleton) return; diff --git a/spine-ts/spine-construct3/src/lang/en-US.json b/spine-ts/spine-construct3/src/lang/en-US.json index 5210a6c57..8c648f524 100644 --- a/spine-ts/spine-construct3/src/lang/en-US.json +++ b/spine-ts/spine-construct3/src/lang/en-US.json @@ -272,6 +272,29 @@ "desc": "Animation speed multiplier (1.0 is normal speed)" } } + }, + "set-animation-time": { + "list-name": "Set animation time", + "display-text": "Set track {2} animation time to {1} ({0})", + "description": "Set the current time of an animation on a track", + "params": { + "units": { + "name": "Units", + "desc": "Time units", + "items": { + "seconds": "Seconds (absolute time)", + "ratio": "Ratio (0.0 to 1.0)" + } + }, + "time": { + "name": "Time", + "desc": "Time value (in seconds or as a ratio 0.0-1.0)" + }, + "track": { + "name": "Track", + "desc": "Track index" + } + } } }, "expressions": { diff --git a/spine-ts/spine-construct3/src/lang/zh-CN.json b/spine-ts/spine-construct3/src/lang/zh-CN.json index 455df74fb..eb025683e 100644 --- a/spine-ts/spine-construct3/src/lang/zh-CN.json +++ b/spine-ts/spine-construct3/src/lang/zh-CN.json @@ -274,6 +274,29 @@ } } }, + "set-animation-time": { + "list-name": "设置动画时间", + "display-text": "将轨道{2}的动画时间设置为{1}({0})", + "description": "设置轨道上动画的当前时间", + "params": { + "units": { + "name": "单位", + "desc": "时间单位", + "items": { + "seconds": "秒(绝对时间)", + "ratio": "比例(0.0到1.0)" + } + }, + "time": { + "name": "时间", + "desc": "时间值(秒或0.0-1.0的比例)" + }, + "track": { + "name": "轨道", + "desc": "轨道索引" + } + } + }, "expressions": { "double": { "description": "将数字翻倍。",