Skip to content

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 ​

ts
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.defs

readCinematic 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 ​

ts
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 it

cut.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 ​

json
"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 ​

json
{ "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 ​

ts
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 ​

ts
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 ​

ts
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 back

It plays with the client's own director, cut and lanes on a plain-data stage (testStage) that writes down every call.

Reference ​

CinematicDef ​

FieldWhat
idits id (the file is cinematics/<id>.json)
lengthseconds; left out, it ends with its last item
laneseach { id, kind, items, muted?, group? }
markers{ at, name, kind? }; kind: 'section' splits it
paramswhat it expects: kind (number, text, toggle, choice, point, points, unit, region, camera, data), required, default
refsnames it talks of (above)
playPlayOptions: 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) ​

KindHoldsAn itemIn code
camerakeys: 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
screenclips: letterbox, fade, vignette, tint, overlay, blur…{ "at": 0, "for": 4, "letterbox": 2.39 }cut.screen.*
picturekeys: grade, bloom, grain, focus{ "at": 2, "value": { "saturation": 0.4, "focus": "hero" } }cut.picture.*
timeclips: slow motion, freezes{ "at": 3, "for": 1, "rate": 0.25 }cut.speed.slow, cut.speed.freeze
envkeys: hour, weather, mist{ "at": 0, "value": { "hour": 18 } }cut.env.hour, .weather, .fog, .wind
dialogclips: a line, a choice{ "at": 1, "for": 3, "speaker": "td.commander", "text": "Hold the road." }cut.say, cut.choose
uiclips: a part of the entry's interface{ "at": 2, "for": 4, "ui": "title", "layer": "hud" }cut.ui.mount, cut.ui.pin
videoclips: a video file{ "at": 0, "for": 8, "video": "intro.mp4", "fit": "cover" }cut.video
audioclips: music, stinger, sound, voice, a bus level{ "at": 0, "music": "td.battle", "crossfade": 2 }cut.audio.*
controlclips: waits, an include{ "at": 5, "wait": "key", "key": "Enter" }cut.untilKey, .untilClick, .untilCue, .untilEvent, .untilWhen, cut.play(id)
unitsclips: 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
propsmodels of the cinematic's own{ "at": 1, "for": 4, "prop": "cart", "path": "road" }cut.prop(model, at), propAt(items, t, places)
fxclips: an effect{ "at": 6, "fx": "explosion", "where": "gate", "scale": 2 }cut.fx('explosion', { on: 'boss' })
hooksclips: 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) ​

HookWhen
start, endit begins; it ends (event.outcome: ended, skipped, stopped…)
skip, pause, resume, seekskipped; clock held, let go, jumped (to, from)
shotthe camera reached a key, or a cut.camera move ended
linea line was shown (speaker, text)
marker:<name>the time reached a marker
cue:<name>a cue came (params)
lane:<kind>:clip, lane:<kind>:keya clip of a lane started at its moment; a key was reached
lane:<kind>:start, lane:<kind>:enda clip began (or part way, by a seek: into), ended (why)
clip:start, clip:endthe same, for every lane
item:<id>:start, item:<id>:end, item:<id>:keythe same, for the item with that id
any other namea 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 ​

ExtendWith
a lanedefineLane in GameView.cinematics.lanes
a transitiona TransitionDef in GameView.cinematics.transitions, client.transitions.add
an easeGameView.cinematics.eases
the dialog box, choicesGameView.cinematics.dialog, .choice, client.setDialogLook, a component, a mount
interface on the stagecut.ui, the ui lane
hooks, refs, conditionshooks, resolve, conditions on the entry; cut.on, cut.resolve, cut.condition
the screen's lookGameView.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 ​

WhatCost
a frame of 10 lanes of 200 clips0.0028 ms (a seek 0.04 ms)
a live transition (second render)9.2 ms against 3.3 ms
the screen pass2.1 ms a frame (software renderer)
a camera path of 200 shots worked out1.3 ms
the Cinematic panel: a zoom11 ms
the preview: an edit replayed, a scrub0.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.