{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Swords crossword",
  "type": "object",
  "required": ["grid", "clues"],
  "$defs": {
    "square": { "type": "string", "pattern": "^\\d+,\\d+$", "description": "x,y from 0,0 at the top left" },
    "squares": { "type": "array", "items": { "$ref": "#/$defs/square" } },
    "scene": {
      "type": "array",
      "maxItems": 40,
      "description": "Steps that play over the grid after the solve. The last state stays on screen. Data only: no code, no addresses.",
      "items": {
        "oneOf": [
          { "$ref": "#/$defs/scenePaint" },
          { "$ref": "#/$defs/sceneWrite" },
          { "$ref": "#/$defs/sceneLine" },
          { "$ref": "#/$defs/sceneImage" },
          { "$ref": "#/$defs/sceneText" },
          { "$ref": "#/$defs/sceneClear" },
          { "$ref": "#/$defs/sceneEffect" }
        ]
      }
    },
    "sceneSeconds": { "type": "number", "minimum": 0, "maximum": 60 },
    "sceneSquares": { "type": "array", "minItems": 1, "maxItems": 2000, "items": { "type": "string", "pattern": "^\\d{1,3},\\d{1,3}$" } },
    "sceneColor": { "type": "string", "pattern": "^(red|orange|yellow|green|blue|purple|pink|#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8}))$" },
    "sceneRect": {
      "type": "object",
      "required": ["x", "y", "w", "h"],
      "additionalProperties": false,
      "description": "A rectangle of squares. x,y is its top left square. Fractions are fine.",
      "properties": { "x": { "type": "number", "minimum": 0 }, "y": { "type": "number", "minimum": 0 }, "w": { "type": "number", "exclusiveMinimum": 0 }, "h": { "type": "number", "exclusiveMinimum": 0 } }
    },
    "scenePaint": {
      "type": "object",
      "required": ["kind", "squares", "color"],
      "additionalProperties": false,
      "properties": {
        "kind": { "const": "paint" },
        "at": { "$ref": "#/$defs/sceneSeconds", "description": "Seconds after the solve when the step starts. Left out: when the step before it ends." },
        "for": { "$ref": "#/$defs/sceneSeconds", "description": "Seconds the change takes. Left out: 0.6." },
        "squares": { "$ref": "#/$defs/sceneSquares" },
        "color": { "$ref": "#/$defs/sceneColor" },
        "stagger": { "$ref": "#/$defs/sceneSeconds", "description": "Seconds between one square and the next." }
      }
    },
    "sceneWrite": {
      "type": "object",
      "required": ["kind", "squares", "text"],
      "additionalProperties": false,
      "properties": {
        "kind": { "const": "write" },
        "at": { "$ref": "#/$defs/sceneSeconds" },
        "for": { "$ref": "#/$defs/sceneSeconds" },
        "squares": { "$ref": "#/$defs/sceneSquares" },
        "text": {
          "description": "One string with a character for each square (a space empties the square), or a list with a string for each square.",
          "oneOf": [{ "type": "string", "maxLength": 2000 }, { "type": "array", "maxItems": 2000, "items": { "type": "string", "maxLength": 10 } }]
        },
        "stagger": { "$ref": "#/$defs/sceneSeconds" }
      }
    },
    "sceneLine": {
      "type": "object",
      "required": ["kind", "through"],
      "additionalProperties": false,
      "properties": {
        "kind": { "const": "line" },
        "at": { "$ref": "#/$defs/sceneSeconds" },
        "for": { "$ref": "#/$defs/sceneSeconds" },
        "through": {
          "type": "array",
          "minItems": 2,
          "maxItems": 2000,
          "description": "Points as x,y. A whole number is the middle of a square; 2.5,0 is on a border.",
          "items": { "type": "string", "pattern": "^[-0-9.]+,[-0-9.]+$" }
        },
        "color": { "$ref": "#/$defs/sceneColor" },
        "width": { "type": "number", "minimum": 0.01, "maximum": 1, "description": "In squares. Left out: 0.12." },
        "closed": { "type": "boolean" }
      }
    },
    "sceneImage": {
      "type": "object",
      "required": ["kind", "src"],
      "additionalProperties": false,
      "properties": {
        "kind": { "const": "image" },
        "at": { "$ref": "#/$defs/sceneSeconds" },
        "for": { "$ref": "#/$defs/sceneSeconds" },
        "src": { "type": "string", "pattern": "^data:image/(png|jpeg|gif|webp|svg\\+xml);base64,[A-Za-z0-9+/]+={0,2}$", "description": "An embedded picture. Never an address. All pictures of a scene together: 1,500,000 bytes decoded." },
        "over": { "oneOf": [{ "const": "grid" }, { "$ref": "#/$defs/sceneRect" }] },
        "fit": { "enum": ["contain", "cover", "stretch"] },
        "opacity": { "type": "number", "minimum": 0, "maximum": 1 },
        "enter": { "enum": ["fade", "grow", "none"] }
      }
    },
    "sceneText": {
      "type": "object",
      "required": ["kind", "text"],
      "additionalProperties": false,
      "properties": {
        "kind": { "const": "text" },
        "at": { "$ref": "#/$defs/sceneSeconds" },
        "for": { "$ref": "#/$defs/sceneSeconds" },
        "text": { "type": "string", "minLength": 1, "maxLength": 200 },
        "over": { "oneOf": [{ "enum": ["below", "grid"] }, { "$ref": "#/$defs/sceneRect" }] },
        "size": { "type": "number", "minimum": 0.2, "maximum": 5, "description": "Letter height in squares, for a caption over the grid. Left out: 0.6." },
        "color": { "$ref": "#/$defs/sceneColor" }
      }
    },
    "sceneClear": {
      "type": "object",
      "required": ["kind"],
      "additionalProperties": false,
      "properties": {
        "kind": { "const": "clear" },
        "at": { "$ref": "#/$defs/sceneSeconds" },
        "for": { "$ref": "#/$defs/sceneSeconds" },
        "steps": { "type": "array", "maxItems": 40, "items": { "type": "integer", "minimum": 1, "maximum": 39 }, "description": "Numbers of earlier steps to remove (the first step is 1). Left out: all." }
      }
    },
    "sceneEffect": {
      "type": "object",
      "required": ["kind", "effect"],
      "additionalProperties": false,
      "properties": {
        "kind": { "const": "effect" },
        "at": { "$ref": "#/$defs/sceneSeconds" },
        "effect": { "enum": ["confetti", "rain", "burst", "wave"] }
      }
    }
  },
  "properties": {
    "title": { "type": "string" },
    "author": { "type": "string" },
    "copyright": { "type": "string" },
    "notes": { "type": "string" },
    "grid": { "type": "array", "minItems": 1, "items": { "type": "string", "pattern": "^[A-Za-z0-9#]+$" }, "description": "One string per row, all the same length. # is a black square." },
    "clues": { "type": "object", "additionalProperties": { "type": "string" }, "description": "Keyed \"x,y,across\" / \"x,y,down\" (the answer's first square), or by the answer in capitals." },
    "rebus": { "type": "object", "additionalProperties": { "type": "string" } },
    "circles": { "$ref": "#/$defs/squares" },
    "shaded": { "$ref": "#/$defs/squares" },
    "colors": { "type": "object", "additionalProperties": { "enum": ["red", "orange", "yellow", "green", "blue", "purple", "pink"] } },
    "absent": { "$ref": "#/$defs/squares" },
    "bars": { "type": "object", "additionalProperties": { "type": "array", "items": { "enum": ["right", "bottom"] } } },
    "sprites": { "type": "object", "additionalProperties": { "type": "object", "properties": { "emoji": { "type": "string" } } } },
    "ending": {
      "type": "object",
      "properties": {
        "message": { "type": "string" },
        "note": { "type": "string" },
        "effects": { "type": "array", "items": { "type": "string", "description": "confetti, rain, burst, wave. A reader skips a name it does not know." } },
        "emoji": { "type": "array", "items": { "type": "string" } },
        "highlight": { "$ref": "#/$defs/squares" },
        "link": { "type": "object", "required": ["label", "url"], "properties": { "label": { "type": "string" }, "url": { "type": "string", "pattern": "^https?://" } } },
        "scene": { "$ref": "#/$defs/scene" }
      }
    }
  }
}
