raea/time

The frame being drawn and the composition's time: useCurrentFrame, useVideoConfig and the Clock.

View as Markdown

Time in raea is frames. useCurrentFrame() is the frame being drawn, counted from the start of the nearest <Sequence>; it's Bevy's Time<Virtual> stepped at the composition's frame rate, so a render and a live play of the same input draw the same frames. useVideoConfig() gives the composition's size, frame rate and length. <Clock> is what steps them; the renderer and the app put one around every composition.

TSX
import { useCurrentFrame, useVideoConfig } from "raea/time";

function Progress() {
  const frame = useCurrentFrame();
  const { durationInFrames, width } = useVideoConfig();
  return <div style={{ width: (frame / durationInFrames) * width, height: 8, background: "#fff" }} />;
}
TS
import { Clock, useCurrentFrame, useLocalTime, useVideoConfig } from "raea/time"

raea/time exports 1 component, 3 hooks, 7 types. Bevy's counterpart: bevy_time. Source: sdk/raea/src/time.ts.

Components

Clock

What time a composition is at: the frame, frame rate, size and length its hooks read, and its words, perception and input. The renderer, the live view and tests put one around every composition; a composition never needs its own.

PropTypeWhat it does
frame (required)numberthe composition frame to draw
fps (required)numberframes a second
width (required)numberin px
height (required)numberin px
durationInFrames (required)numberthe composition's length in frames
idstringthe composition's id ("main" by default)
defaultPropsRecord<string, unknown>the props the composition is rendered with
wordsreadonly TimelineWord[]the transcript, in composition frames, that captions and word cuts read
perceptionPerceptionwhat perception saw at this frame (faces, the safe area)
inputInputTimelinea game's recorded input by frame
childrenReactNodethe composition

Hooks

useCurrentFrame

The frame being rendered, counted from the start of the nearest enclosing Sequence.

TS
function useCurrentFrame(): number

useLocalTime

The time where it's called: the nearest Sequence's (its local frame, where it starts, and the size it gives its children), or the Clock's outside any. caller names the hook in errors. The hook under useCurrentFrame, for components of your own that need more than the frame.

TS
function useLocalTime(caller: string): LocalTime

useVideoConfig

The settings of the composition being rendered (a Sequence's width and height win inside it).

TS
function useVideoConfig(): VideoConfig

Types

ClockProps

The props of Clock, tabled there.

FrameInput

One frame's input for a game.

FieldTypeWhat it is
keys (required)string[]the keys held (KeyboardEvent.key names: "ArrowLeft", "a", " ")
pointer{ x: number; y: number; down: boolean }the primary pointer in composition px, and whether it's pressed
buttonsstring[]the mouse buttons held besides the primary one: "Right", "Middle", "Back", "Forward" (Bevy's MouseButton names)
wheel{ x: number; y: number }the wheel turned this frame, in CSS px, down and right positive (the DOM's deltaX and deltaY)
gamepads{ buttons: string[]; axes: Record<string, number> }[]each connected gamepad: the buttons held and the sticks' and triggers' axes, by Bevy's GamepadButton and GamepadAxis names ("South", "DPadUp", "RightTrigger2"; "LeftStickX" -1..1, "LeftZ")
touches{ id: number; x: number; y: number }[]the fingers down, in composition px

InputTimeline

Recorded input by composition frame; frames without an entry had no input.

TS
type InputTimeline = Record<number, Partial<FrameInput> | undefined>

LocalTime

The local time a subtree sees: its own frame, and the composition frame its frame 0 falls on.

FieldTypeWhat it is
frame (required)numberthe subtree's own frame: the composition's frame minus origin
origin (required)numberthe composition frame the subtree's frame 0 falls on
width (required)numberwidth and height a Sequence overrides for its children
height (required)numberin px, what the Sequence gives its children

Perception

What perception saw at this frame: the largest face, and the platform's safe area (composition px).

FieldTypeWhat it is
faceRectthe largest face's box, when there's one
safe{ top?: number; bottom?: number }px the platform's UI covers at the top and bottom

TimelineWord

FieldTypeWhat it is
text (required)stringthe word as spoken
from (required)numberfirst frame of the word
to (required)numberframe after the word ends (exclusive)

VideoConfig

FieldTypeWhat it is
id (required)stringthe composition's id ("main" by default)
width (required)numberin px
height (required)numberin px
fps (required)numberframes a second
durationInFrames (required)numberits length in frames
defaultProps (required)Record<string, unknown>the props the composition is rendered with