Skip to content

@modoki/engine / index / PlayState

Type Alias: PlayState

PlayState = "stopped" | "playing" | "paused"

Global RUN MODE — the single source of truth for "what run state is the editor/game in".

Four modes (Unity-style Stopped/Playing plus the two editor-preview states that used to masquerade as "stopped"):

  • stopped — authoring: sim off, particles frozen, no timeline eval. Editing is safe.
  • scrub — dragging a timeline/animation playhead: an idempotent POSE at time t; NO edge events (silent). Each call is one pose, so it is inherently non-advancing.
  • preview — the Timeline panel ▶ forward playthrough: edges fire (signals/audio/control/ OnSequence), particles play, but the SIM TIER stays gated off (not full Play).
  • playing — full Play: the whole simulation runs. plus an advancing sub-flag: false = a frozen frame (Play "paused", or a paused preview).

The runtime defaults to playing/advancing so a SHIPPED game (which never imports the editor) runs with zero setup. The editor drives the mode explicitly: opens a scene stopped, snapshots on Play, reverts on Stop — so play/preview/scrub mutations never leak into saved scenes (see editor/scene/playMode.ts). isSimRunning() gates the sim tier (pipeline.ts, getTime.ts).

MIGRATION (preview-mode-refactor, Phase 0): RunMode is introduced additively — the legacy PlayState API (getPlayState/setPlayState/isSimRunning/onPlayStateChange) is DERIVED from (mode, advancing) as an exact compat shim (scrub/preview both read back as stopped, which is how they behave today). Nobody SETS scrub/preview until Phase 1, so behaviour is byte-identical. Later phases flip call sites to the mode helpers below and retire the shims.

Built with Modoki.