Cinematic file format reference
Every field of a cinematic file (CinematicDef), the built-in lanes, refs and conditions, hooks, lanes of your own, and testing.
Quick start
import intro from './cinematics/td.intro.json'
import { cinematicCode, readCinematic, writeCinematic } from '@v12-engine/client'
const def = readCinematic(intro) // checks it, fills defaults, throws with the path of what is wrong
const json = writeCinematic(def) // JSON that reads well in a diff
const code = cinematicCode(def) // the same as a line of cinematics.defsreadCinematic throws messages like td.intro.lanes[2].items[0].at is a number. A lane of an unknown kind is kept and logged once (it may be yours, or a typo).
Common tasks
Play a clip on a unit, and stop it
const hero = cut.entity('hero')!
await cut.clip(hero, 'Cheer') // waits until it ends: played out, stopped, or cut off by another clip or a death
const dance = cut.clip(hero, 'Dance', { loop: true }) // plays until stopped
await cut.untilKey()
cut.stopClip(hero) // stops it where it is, back to idle; `dance` settles
const wave = cut.clip(hero, 'Wave')
await cut.race([wave, cut.wait(1)]) // at most a second of it: the loser of a race is stopped, the clip with itcut.clip takes a clip's name, a kind (attack, walk…) or an animation file's path, as client.playClip does, and settles at once when the model has no such clip. .stop() on what it returns stops the clip and no longer waits for it. A skipped cinematic stops the clips it was waiting for. cut.stopClip(id) stops any clip played on demand on that unit, a units lane's too.
Name things a cinematic refers to
"refs": {
"hero": { "query": { "type": "hero", "owner": "me", "nearest": { "region": "gate" } } },
"boss": { "code": "boss" },
"road": { "param": "road" },
"keep": { "camera": "keep" },
"gate": { "region": "gate" },
"aldric": { "name": "aldric" }
}Refs resolve when asked (as a clip starts), so "the hero nearest the gate" is found then. A { code } ref is answered by the entry's resolve: { boss: (cut) => id } or cut.resolve('boss', fn). In code: cut.ref('hero') ({ entity, point, pose, value }), cut.entity('hero'), cut.state.entities() (CutEntity).
Play a clip only sometimes
{ "at": 3, "for": 2, "speaker": "hero", "text": "You came!", "when": { "all": [{ "param": "hard" }, { "ref": "hero", "alive": true }] } }Conditions: { "param": "hard" } (or "equals" a value), { "ref": "hero", "alive": true }, { "any": [...] }, { "all": [...] }, { "not": {...} }, { "hook": "bossAwake" } (the entry's conditions, or cut.condition(name, fn)), and the world's words (arrived, dead, in range: see Triggering from a mission). A script filters clips with cut.filter((clip, lane) => ...).
Hear clips as they play
hooks: {
'item:intro-film:start': (_cut, { clip }) => {
const { element } = clip!.handle as CutVideo
element.style.filter = 'sepia(0.6)'
},
'clip:start': (_cut, { lane, item }) => analytics.track('cinematic clip', lane, item?.at)
}
cut.running({ lane: 'video' }) // every video going now
cut.runningOf('intro-film')?.handle // one by its name
client.cinematics.onChange((playing) => playing?.cut.on('lane:audio:start', (_cut, { clip }) => console.log(clip)))Write a lane of your own
import { defineLane, type Clip } from '@v12-engine/client'
import { oneOf } from '@v12-engine/engine'
interface CheerClip extends Clip {
who: 'me' | 'enemy' | 'everyone'
}
export const cheerLane = defineLane<CheerClip>({
kind: 'melee.cheer',
name: 'Cheer',
// its own fields checked with the engine's checkers; `at`, `for`, `ease` and `when` are checked before
read: (item, what) => ({ ...item, who: oneOf('me', 'enemy', 'everyone')(item.who ?? 'everyone', `${what}.who`) }),
// starts at its moment, `from` seconds in after a seek; what it returns ends it
run(cut, item, from) {
if (from > 0) return
for (const id of cut.stage.units?.(item.who) ?? []) cut.stage.playClip(id, 'cheer')
},
editor: { color: '#f0c040', fields: [{ key: 'who', kind: 'choice', options: ['me', 'enemy', 'everyone'] }], label: (item) => `${item.who} cheer` }
})
// on the view: cinematics: { lanes: [cheerLane] }
// in a file: { "id": "cheers", "kind": "melee.cheer", "items": [{ "at": 2, "who": "me" }] }The campaign starter's waves lane is a walk-through: A lane of its own.
Test a cinematic
import { stepCinematic } from '@v12-engine/client/testing'
const run = await stepCinematic(intro, { seconds: 2, units: [{ id: 7, name: 'hero', type: 'footman', x: 10, z: 10 }] })
expect(run.said()).toEqual(['hero: Hold the line.'])
expect(run.stage.pose().x).toBeCloseTo(20)
await run.key('Enter') // moves a line that waits on, as the game's Enter does; another key is heard by the waits
await run.pick('right') // answers the choice showing
run.stage.event({ type: 'death', id: 7, attack: false }) // an event of the game's, for a wait on one
await run.step(5)
expect(run.outcome).toBe('ended')
expect(run.stage.of('clip').map((call) => call.args[1])).toEqual(['cheer'])
expect(run.host).toContain('hold') // what the director asked of the game: hold, hands, the HUD, the letterbox, the camera backIt plays with the client's own director, cut and lanes on a plain-data stage (testStage) that writes down every call.
Reference
CinematicDef
| Field | What |
|---|---|
id | its id (the file is cinematics/<id>.json) |
length | seconds; left out, it ends with its last item |
lanes | each { id, kind, items, muted?, group? } |
markers | { at, name, kind? }; kind: 'section' splits it |
params | what it expects: kind (number, text, toggle, choice, point, points, unit, region, camera, data), required, default |
refs | names it talks of (above) |
play | PlayOptions: hold, skippable, letterbox, back… |
loop | { from, to } |
preload | { types, models, sounds } |
Every item takes at, for (clips), ease, when, id (its Name for code), and pin ("marker:Battle" or "item:i3", for the editor only). Params are cut.params, with defaults filled; a missing required one is logged and what needs it is left out.
Built-in lanes (BUILT_IN_LANE_KINDS)
| Kind | Holds | An item | In code |
|---|---|---|---|
camera | keys: a shot, a view, a rail; clips: follow, handheld, shake | { "at": 6, "value": { "view": "gate" }, "ease": "inOutQuad" } | cut.camera, cut.shot, cut.rail, cut.follow |
screen | clips: letterbox, fade, vignette, tint, overlay, blur… | { "at": 0, "for": 4, "letterbox": 2.39 } | cut.screen.* |
picture | keys: grade, bloom, grain, focus | { "at": 2, "value": { "saturation": 0.4, "focus": "hero" } } | cut.picture.* |
time | clips: slow motion, freezes | { "at": 3, "for": 1, "rate": 0.25 } | cut.speed.slow, cut.speed.freeze |
env | keys: hour, weather, mist | { "at": 0, "value": { "hour": 18 } } | cut.env.hour, .weather, .fog, .wind |
dialog | clips: a line, a choice | { "at": 1, "for": 3, "speaker": "td.commander", "text": "Hold the road." } | cut.say, cut.choose |
ui | clips: a part of the entry's interface | { "at": 2, "for": 4, "ui": "title", "layer": "hud" } | cut.ui.mount, cut.ui.pin |
video | clips: a video file | { "at": 0, "for": 8, "video": "intro.mp4", "fit": "cover" } | cut.video |
audio | clips: music, stinger, sound, voice, a bus level | { "at": 0, "music": "td.battle", "crossfade": 2 } | cut.audio.* |
control | clips: waits, an include | { "at": 5, "wait": "key", "key": "Enter" } | cut.untilKey, .untilClick, .untilCue, .untilEvent, .untilWhen, cut.play(id) |
units | clips: a clip, an order, hide, tint, director, steps, fight | { "at": 4, "unit": "hero", "clip": "cheer" } | cut.clip, cut.sequence, cut.units.hide, .tint, .ink, .flash |
props | models of the cinematic's own | { "at": 1, "for": 4, "prop": "cart", "path": "road" } | cut.prop(model, at), propAt(items, t, places) |
fx | clips: an effect | { "at": 6, "fx": "explosion", "where": "gate", "scale": 2 } | cut.fx('explosion', { on: 'boss' }) |
hooks | clips: a hook by name | { "at": 6, "hook": "openGate" } | cut.on('openGate', run), cut.emit('openGate') |
A lane may appear twice with different ids. A muted lane is kept but not played. Where items of a lane can't overlap is the lane's to say (LaneEditor.slot).
Units lane clips: clip is a clip name, or a kind (idle, walk, attack, cast, channel, work, death, sleep) mapped by the model's animations, so one cinematic fits any model. unit is the name on the map, or an id the script gives (cut.play(def, { units: { hero: id } })). An order is sent as the player's command. A prop's clip plays on a LiteAnimator (prop.play('attack', false, { marks: [{ at: 'hit', run }] })).
Fx lane clips: an effect with a for plays for all of it (played again if it ends sooner); one with no for ends by itself; a paused cinematic holds them (FxHandle.hold). The Inspector lists the game's effects (GameView.fx.defs) then the ready-made ones (PRESET_FX); picking one of those takes it into fx.json ({ "extends": "fireball" }). A lane of yours plays one with playCutFx(cut, () => cut.stage.fx(...), { lasts }).
Hooks (CutEvent)
| Hook | When |
|---|---|
start, end | it begins; it ends (event.outcome: ended, skipped, stopped…) |
skip, pause, resume, seek | skipped; clock held, let go, jumped (to, from) |
shot | the camera reached a key, or a cut.camera move ended |
line | a line was shown (speaker, text) |
marker:<name> | the time reached a marker |
cue:<name> | a cue came (params) |
lane:<kind>:clip, lane:<kind>:key | a clip of a lane started at its moment; a key was reached |
lane:<kind>:start, lane:<kind>:end | a clip began (or part way, by a seek: into), ended (why) |
clip:start, clip:end | the same, for every lane |
item:<id>:start, item:<id>:end, item:<id>:key | the same, for the item with that id |
| any other name | a hooks-lane clip or cut.emit(name) |
A marker or key is heard as time reaches it, never when a seek jumps past. A hook that throws is logged and the cinematic goes on. The clock never waits for a hook; what a hook returns is waited for before the cinematic ends. event.clip is a RunningClip (lane, item, id, start, handle); event.why is done, ended, a seek, over, or stopped.
Lanes of your own (LaneDef)
A lane either samples (sample(cut, items, t), a pure function of time, like the camera: scrubbing is free) or runs (run(cut, item, from), started at its moment and ended when its time is up, at a seek or a skip; it may return { stop, handle, ended }: LaneRun). length(item, cut) measures a clip (a line as long as its voice: cut.soundSeconds(name), else lineTime). ending(cut, item) returning a promise holds the clock at a clip's end, as the dialogue lane does. State between clips goes in cut.lane(kind).state. A lane acts on cut.stage and names units by cut.entity(name); it says what happens with cut.emit('lane:<kind>:<event>'); reached(cut, key) hears its keys.
Its editor (LaneEditor): color, icon, hint, label, fields (by kind; when, rgb, step, min, max; groupFields puts two on a line), moment, slot(item), check(item, names, def) (for Problems; cinematicProblems(def, names, lanes) in code), media(item) (drawn as a waveform), draw(item, at) (in the scene: at.scene, at.root, at.selected, at.point(name), at.heightAt), inspector. Add lanes with cinematics.lanes on the view, kit.lanes.add, defineEditorExtension({ lanes }) or editor.lanes.add. defineLane<YourItem> goes into any list as it is (AnyLane). A lane of a built-in's kind replaces it.
Extending, in short
| Extend | With |
|---|---|
| a lane | defineLane in GameView.cinematics.lanes |
| a transition | a TransitionDef in GameView.cinematics.transitions, client.transitions.add |
| an ease | GameView.cinematics.eases |
| the dialog box, choices | GameView.cinematics.dialog, .choice, client.setDialogLook, a component, a mount |
| interface on the stage | cut.ui, the ui lane |
| hooks, refs, conditions | hooks, resolve, conditions on the entry; cut.on, cut.resolve, cut.condition |
| the screen's look | GameView.cinematics.screen.look, .process |
Testing (@v12-engine/client/testing)
stepCinematic(defOrScript, { seconds, units, params, hooks, entries, play }). run.stage.calls (each with at), run.stage.of(kind), run.skip(), run.key, run.pick, run.step, run.said(), run.outcome, run.host. Units, views, paths and regions are given by name (views, paths, regions).
What it costs
| What | Cost |
|---|---|
| a frame of 10 lanes of 200 clips | 0.0028 ms (a seek 0.04 ms) |
| a live transition (second render) | 9.2 ms against 3.3 ms |
| the screen pass | 2.1 ms a frame (software renderer) |
| a camera path of 200 shots worked out | 1.3 ms |
| the Cinematic panel: a zoom | 11 ms |
| the preview: an edit replayed, a scrub | 0.058 ms, 0.024 ms |
A cinematic not playing costs nothing; the screen pass, the transition pass and a portrait's view are made only while asked.
Deprecated
cut.track, CinematicTrack, readTracks, GameView.tracks and tracks.json (three fixed lists a track) work for one more release: trackToCinematic turns a track into a cinematic, and the editor's New › Import all of tracks.json makes a file of each (CinematicFiles.importTracks(tracks)). Move to cinematics/<id>.json and GameView.cinematics.defs.