Skip to content

Expose state machine graph, entered state names, and timeline introspection - #8

Merged
jslauthor merged 1 commit into
mainfrom
feat/state-machine-graph-and-playhead
Jul 29, 2026
Merged

Expose state machine graph, entered state names, and timeline introspection#8
jslauthor merged 1 commit into
mainfrom
feat/state-machine-graph-and-playhead

Conversation

@jslauthor

Copy link
Copy Markdown
Contributor

Three read-only surfaces a host needs to let a .riv's state machine own its sequencing while the host still measures and reacts to it — all already present in the runtime and simply not surfaced.

RiveArtboard::stateMachineGraph(name) (+ RiveView passthrough) returns a machine's static structure WITHOUT instantiating it: entry timeline, every AnimationState's timeline name, and transitions resolved from LayerState* to {from, to} name pairs (entry/exit/any/blend report "", matching the stateChanged contract). A host can now derive a clip sequence from the graph itself instead of duplicating it in code — so adding or reordering states in the .riv needs no host change.

RiveStateMachine::stateChanged now carries the entered state's TIMELINE name instead of an empty string. A LayerState has no name of its own — StateMachineLayerComponent extends Core directly and the format has no name property for it — but an AnimationState knows the LinearAnimation it plays, and that name is what the editor shows on the state. States with no single timeline (entry / exit / any / blend) stay unnamed rather than inventing a label callers could come to depend on. The header's contract is updated, including a note that the first argument has always been the change index rather than a layer name: rive reports changes as a flat list across layers with no way to ask which layer each came from. This is also the host's transition-interception point: every handoff is observable as a from -> to pair.

RiveStateMachine::currentStateTime / currentStateTimeline (read-only Q_PROPERTYs, published per advance) expose the live playhead within the state's active clip via currentAnimationByIndex(). Under a state machine RiveView's currentFrame is 0 by design — a graph has no single scrubbable timeline — but a host progress bar still needs to measure playback, and these two give it position-within-state to combine with the graph-derived ordering and per-clip durations.

RiveArtboard::animationDuration(name) / RiveView::animationDuration(name) report a clip's length in seconds WITHOUT instantiating it for playback; animationLoops(name) reports whether it repeats (loop or ping-pong), which is how a host tells a graph spine's loop tail from a one-shot end. Misses and empty names return 0 / false.

Tests: graph shape + endpoints cross-checked against animationNames with miss/mint-after-read contracts; playhead populated after first advance and bounded by the clip's real duration; loop flag cross-checked against each clip's own setting; the state-machine spy asserts at least one emission is named and every name matches an enumerated animation (the regression guard for the empty-string behaviour); render smoke covers the RiveView no-source contract. Full suite: 38/38.

@cursor

cursor Bot commented Jul 29, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

…ection

Three read-only surfaces a host needs to let a .riv's state machine own
its sequencing while the host still measures and reacts to it — all
already present in the runtime and simply not surfaced.

RiveArtboard::stateMachineGraph(name) (+ RiveView passthrough) returns a
machine's static structure WITHOUT instantiating it: entry timeline,
every AnimationState's timeline name, and transitions resolved from
LayerState* to {from, to} name pairs (entry/exit/any/blend report "",
matching the stateChanged contract). A host can now derive a clip
sequence from the graph itself instead of duplicating it in code — so
adding or reordering states in the .riv needs no host change.

RiveStateMachine::stateChanged now carries the entered state's TIMELINE
name instead of an empty string. A LayerState has no name of its own —
StateMachineLayerComponent extends Core directly and the format has no
name property for it — but an AnimationState knows the LinearAnimation
it plays, and that name is what the editor shows on the state. States
with no single timeline (entry / exit / any / blend) stay unnamed rather
than inventing a label callers could come to depend on. The header's
contract is updated, including a note that the first argument has always
been the change index rather than a layer name: rive reports changes as
a flat list across layers with no way to ask which layer each came from.
This is also the host's transition-interception point: every handoff is
observable as a from -> to pair.

RiveStateMachine::currentStateTime / currentStateTimeline (read-only
Q_PROPERTYs, published per advance) expose the live playhead within the
state's active clip via currentAnimationByIndex(). Under a state machine
RiveView's currentFrame is 0 by design — a graph has no single
scrubbable timeline — but a host progress bar still needs to measure
playback, and these two give it position-within-state to combine with
the graph-derived ordering and per-clip durations.

RiveArtboard::animationDuration(name) / RiveView::animationDuration(name)
report a clip's length in seconds WITHOUT instantiating it for playback;
animationLoops(name) reports whether it repeats (loop or ping-pong),
which is how a host tells a graph spine's loop tail from a one-shot end.
Misses and empty names return 0 / false.

Tests: graph shape + endpoints cross-checked against animationNames with
miss/mint-after-read contracts; playhead populated after first advance
and bounded by the clip's real duration; loop flag cross-checked against
each clip's own setting; the state-machine spy asserts at least one
emission is named and every name matches an enumerated animation (the
regression guard for the empty-string behaviour); render smoke covers
the RiveView no-source contract. Full suite: 38/38.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@jslauthor
jslauthor force-pushed the feat/state-machine-graph-and-playhead branch from 9b4b714 to e570d34 Compare July 29, 2026 23:39
@jslauthor
jslauthor merged commit a47d08a into main Jul 29, 2026
4 checks passed
@jslauthor
jslauthor deleted the feat/state-machine-graph-and-playhead branch July 29, 2026 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant