/** * Whether a state machine keeps its current state per behavior instance or shares one for the whole * run. Everything was `local` before scopes existed, so a missing field means `local` and old * projects load unchanged. Variables are shared by living on a Variables asset instead (#91). */ export type Scope = 'local' | 'global'; export interface Scoped { scope?: Scope; } export function scopeOf(owner: Scoped): Scope { return owner.scope === 'global' ? 'global' : 'local'; } export function isGlobal(owner: Scoped): boolean { return owner.scope === 'global'; } /** Reads a scope out of loaded data, where anything but the one known word means `local`. */ export function readScope(raw: unknown): Scope { return raw === 'global' ? 'global' : 'local'; } /** Keeps `local` out of the document: the field is present only when it says `global`. */ export function setScope(owner: Scoped, scope: Scope): void { if (scope === 'global') owner.scope = 'global'; else delete owner.scope; }