@@ -68,20 +68,20 @@ export interface INodeTransform {
6868 interpolation ?: 'step' | 'pre-post'
6969
7070 commands ?: string
71- execute_condition ?: string
71+ commands_execute_condition ?: string
7272}
7373
7474export interface IRenderedFrame {
7575 time : number
7676 node_transforms : Record < string , INodeTransform >
77- variant ?: {
78- uuid : string
79- execute_condition ?: string
80- }
81- commands ?: {
82- commands : string
83- execute_condition ?: string
84- }
77+ /** A list of Variants (by UUID) to apply this frame */
78+ variants ? : string [ ]
79+ /** The condition to check before applying variants */
80+ variants_execute_condition ?: string
81+ /** A mcfunction to run as the root on this frame. (Supports MCB syntax) */
82+ commands ? : string
83+ /** The condition to check before running commands */
84+ commands_execute_condition ?: string
8585}
8686
8787export interface IRenderedAnimation {
@@ -124,8 +124,8 @@ export function getFrame(
124124 const frame : IRenderedFrame = {
125125 time,
126126 node_transforms : { } ,
127- variant : getVariantKeyframe ( animation , time ) ,
128- commands : getCommandsKeyframe ( animation , time ) ,
127+ ... getVariantKeyframe ( animation , time ) ,
128+ ... getCommandsKeyframe ( animation , time ) ,
129129 }
130130
131131 if ( lastAnimation !== animation ) {
@@ -242,39 +242,52 @@ export function getFrame(
242242 head_rot : threeAxisRotationToTwoAxisRotation ( rot ) ,
243243 interpolation,
244244 commands,
245- execute_condition : executeCondition ,
245+ commands_execute_condition : executeCondition ?. trim ( ) ,
246246 }
247247 }
248248
249249 return frame
250250}
251251
252- function getVariantKeyframe ( animation : _Animation , time : number ) : IRenderedFrame [ 'variant' ] {
252+ function getVariantKeyframe (
253+ animation : _Animation ,
254+ time : number
255+ ) : Pick < IRenderedFrame , 'variants' | 'variants_execute_condition' > {
253256 const variantKeyframes = animation . animators . effects ?. variant as _Keyframe [ ]
254- if ( ! variantKeyframes ) return
255- for ( const kf of variantKeyframes ) {
256- if ( kf . time !== time ) continue
257- const uuid = getKeyframeVariant ( kf )
258- if ( ! uuid ) return
259- return {
260- uuid,
261- execute_condition : getKeyframeExecuteCondition ( kf ) ,
257+ if ( variantKeyframes ) {
258+ const kf = variantKeyframes . find ( kf => kf . time === time )
259+ if ( kf ) {
260+ // REVIEW - Variant keyframes do not support multiple variants yet.
261+ const uuid = getKeyframeVariant ( kf )
262+ if ( uuid ) {
263+ return {
264+ variants : [ uuid ] ,
265+ variants_execute_condition : getKeyframeExecuteCondition ( kf ) ?. trim ( ) ,
266+ }
267+ }
262268 }
263269 }
270+ return { }
264271}
265272
266- function getCommandsKeyframe ( animation : _Animation , time : number ) : IRenderedFrame [ 'commands' ] {
273+ function getCommandsKeyframe (
274+ animation : _Animation ,
275+ time : number
276+ ) : Pick < IRenderedFrame , 'commands' | 'commands_execute_condition' > {
267277 const commandsKeyframes = animation . animators . effects ?. commands as _Keyframe [ ]
268- if ( ! commandsKeyframes ) return
269- for ( const kf of commandsKeyframes ) {
270- if ( kf . time !== time ) continue
271- const commands = getKeyframeCommands ( kf )
272- if ( ! commands ) return
273- return {
274- commands,
275- execute_condition : getKeyframeExecuteCondition ( kf ) ,
278+ if ( commandsKeyframes ) {
279+ const kf = commandsKeyframes . find ( kf => kf . time === time )
280+ if ( kf ) {
281+ const commands = getKeyframeCommands ( kf ) ?. trim ( )
282+ if ( commands ) {
283+ return {
284+ commands,
285+ commands_execute_condition : getKeyframeExecuteCondition ( kf ) ?. trim ( ) ,
286+ }
287+ }
276288 }
277289 }
290+ return { }
278291}
279292
280293export function updatePreview ( animation : _Animation , time : number ) {
@@ -348,13 +361,17 @@ export function hashAnimations(animations: IRenderedAnimation[]) {
348361 hash . update ( ';' + node . scale . join ( ';' ) )
349362 node . interpolation && hash . update ( ';' + node . interpolation )
350363 if ( node . commands ) hash . update ( ';' + node . commands )
351- if ( node . execute_condition ) hash . update ( ';' + node . execute_condition )
364+ if ( node . commands_execute_condition )
365+ hash . update ( ';' + node . commands_execute_condition )
352366 }
353- if ( frame . variant ) {
354- hash . update ( ';' + frame . variant . uuid )
355- if ( frame . variant . execute_condition )
356- hash . update ( ';' + frame . variant . execute_condition )
367+ if ( frame . variants ) {
368+ hash . update ( ';' + frame . variants )
369+ if ( frame . variants_execute_condition )
370+ hash . update ( ';' + frame . variants_execute_condition )
357371 }
372+ if ( frame . commands ) hash . update ( ';' + frame . commands )
373+ if ( frame . commands_execute_condition )
374+ hash . update ( ';' + frame . commands_execute_condition )
358375 }
359376 }
360377 return hash . digest ( 'hex' )
0 commit comments