{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://raw.githubusercontent.com/cristonj/vertex/master/schema/scene.schema.json",
  "title": "Vertex scene document",
  "description": "A complete Vertex game world: vector shapes (SVG path data), entities (instances of shapes), and game state. This file is the formal description of the format and doubles as documentation for code generators: a whole game is this object plus systems.",
  "type": "object",
  "properties": {
    "width": { "type": "number", "description": "World width in world units.", "default": 800 },
    "height": { "type": "number", "description": "World height in world units.", "default": 600 },
    "background": { "type": "string", "description": "CSS color painted behind everything.", "default": "#000" },
    "shapes": {
      "type": "object",
      "description": "Named vector shapes. Geometry is SVG path data centered on (0,0), facing +x at rotation 0. Keep paths small; prefer M/L/Q/C/Z.",
      "additionalProperties": { "$ref": "#/definitions/shape" }
    },
    "entities": {
      "type": "array",
      "items": { "$ref": "#/definitions/entity" },
      "description": "Instances of shapes. Plain data: every field is readable and writable by humans, systems, and agents."
    },
    "camera": {
      "type": "object",
      "description": "World point shown at the screen center. Omit for an identity view (origin top-left).",
      "properties": { "x": { "type": "number" }, "y": { "type": "number" }, "zoom": { "type": "number", "default": 1 }, "rot": { "type": "number", "default": 0 } }
    },
    "sounds": {
      "type": "object",
      "description": "Named sound effects as synth parameters (see src/audio.js): no audio files.",
      "additionalProperties": { "$ref": "#/definitions/sound" }
    },
    "state": {
      "type": "object",
      "description": "Game-level values (score, lives, ...). state.hud, if present, is rendered as text by both renderers."
    }
  },
  "definitions": {
    "shape": {
      "type": "object",
      "description": "One path with style, or a composite of parts.",
      "properties": {
        "d": { "type": "string", "description": "SVG path data. Supports M/L/H/V/C/S/Q/T/A/Z, absolute and relative." },
        "fill": {
          "description": "CSS color, 'none', or a gradient.",
          "anyOf": [ { "type": "string" }, { "$ref": "#/definitions/gradient" } ]
        },
        "stroke": { "type": "string", "description": "CSS color, or 'none'." },
        "width": { "type": "number", "description": "Stroke width." },
        "clip": { "type": "string", "description": "SVG path data; the part is clipped to this region (local coords)." },
        "parts": {
          "type": "array",
          "description": "Multiple paths drawn together as one shape, in order.",
          "items": { "$ref": "#/definitions/shape" }
        }
      },
      "anyOf": [ { "required": ["d"] }, { "required": ["parts"] } ]
    },
    "sound": {
      "type": "object",
      "description": "Parametric sound effect. Rendered deterministically to samples at load time.",
      "properties": {
        "wave": { "enum": ["square", "saw", "sine", "triangle", "noise"] },
        "freq": { "type": "number", "description": "Start frequency, Hz." },
        "slide": { "type": "number", "description": "Frequency change, Hz per second." },
        "attack": { "type": "number" }, "sustain": { "type": "number" }, "decay": { "type": "number" },
        "volume": { "type": "number" }, "vibrato": { "type": "number" }, "vibratoRate": { "type": "number" },
        "duty": { "type": "number", "description": "Square wave duty cycle 0..1." },
        "lowpass": { "type": "number", "description": "One-pole lowpass cutoff, Hz." }
      }
    },
    "gradient": {
      "type": "object",
      "description": "Linear (x1,y1 -> x2,y2) or radial (cx,cy,r) gradient in local shape coordinates.",
      "required": ["type", "stops"],
      "properties": {
        "type": { "enum": ["linear", "radial"] },
        "x1": { "type": "number" }, "y1": { "type": "number" }, "x2": { "type": "number" }, "y2": { "type": "number" },
        "cx": { "type": "number" }, "cy": { "type": "number" }, "r": { "type": "number" },
        "stops": {
          "type": "array",
          "items": { "type": "array", "prefixItems": [ { "type": "number" }, { "type": "string" } ], "minItems": 2, "maxItems": 2 },
          "description": "[[offset 0..1, color], ...]"
        }
      }
    },
    "entity": {
      "type": "object",
      "description": "An instance of a shape in the world.",
      "properties": {
        "id": { "type": "string", "description": "Unique id. Auto-assigned (e1, e2, ...) if omitted." },
        "shape": { "type": "string", "description": "Name of a shape defined in shapes." },
        "d": { "type": "string", "description": "Inline geometry (SVG path data) instead of a named shape; may change every step (morphs, generated art)." },
        "fill": { "type": "string", "description": "Fill for inline geometry." },
        "stroke": { "type": "string", "description": "Stroke for inline geometry." },
        "width": { "type": "number", "description": "Stroke width for inline geometry." },
        "x": { "type": "number" },
        "y": { "type": "number" },
        "rot": { "type": "number", "description": "Rotation in radians; 0 faces +x." },
        "scale": { "type": "number" },
        "vx": { "type": "number", "description": "Velocity, world units per second." },
        "vy": { "type": "number" },
        "vr": { "type": "number", "description": "Angular velocity, radians per second." },
        "drag": { "type": "number", "description": "Velocity damping fraction per second, 0..1 (used by the motion system)." },
        "tags": {
          "type": "array",
          "items": { "type": "string" },
          "description": "System selectors: 'wrap' wraps at edges, other tags pair up in collide()."
        },
        "data": {
          "type": "object",
          "description": "Free-form per-entity values. data.ttl (seconds) despawns the entity via the lifetime system."
        },
        "hidden": { "type": "boolean", "description": "Skipped by renderers." },
        "layer": { "type": "number", "description": "Draw order; lower draws first, stable within a layer. Default 0." },
        "parallax": { "type": "number", "description": "Camera influence: 1 normal, 0 pinned to screen, 0.5 distant background." },
        "fixed": { "type": "boolean", "description": "Screen-space (UI): ignores the camera." }
      }
    }
  }
}
