{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://blackautumn.divinevtt.com/modding/schemas/graph.schema.json",
  "title": "graph file",
  "description": "A graph of a mod: nodes wired together, its variables, comment boxes, and functions.",
  "$defs": {
    "var": {
      "type": "object",
      "description": "a variable",
      "properties": {
        "name": {
          "type": "string"
        },
        "kind": {
          "enum": [
            "Bool",
            "bool",
            "Int",
            "int",
            "Float",
            "float",
            "Text",
            "text",
            "Vector",
            "vector",
            "Colour",
            "colour",
            "Object",
            "object",
            "Enum",
            "enum",
            "List",
            "list",
            "Any",
            "any",
            "Map",
            "map"
          ],
          "description": "what it holds"
        },
        "type": {
          "type": "string",
          "description": "for a thing or a list, the game's type (\"Player.Character\"); for a map, the value's kind or type"
        },
        "key": {
          "type": "string",
          "description": "a map's key kind or type"
        },
        "value": {
          "description": "what it starts as"
        },
        "saved": {
          "type": "boolean",
          "description": "kept in the game's save"
        },
        "scope": {
          "enum": [
            "Graph",
            "graph",
            "Local",
            "local",
            "Mod",
            "mod",
            "Thing",
            "thing"
          ],
          "description": "graph (the default), local (one event's runs), mod (shared by the mod's graphs), thing (kept on each person or thing)"
        },
        "owner": {
          "type": "string",
          "description": "a local's event node id"
        }
      },
      "required": [
        "name"
      ]
    },
    "node": {
      "type": "object",
      "description": "a node",
      "properties": {
        "id": {
          "type": "string",
          "description": "its own id in the graph"
        },
        "node": {
          "type": "string",
          "pattern": "^[a-z]+/.+",
          "description": "the kind of node: event/..., call/..., get/..., flow/..., math/..., text/..., list/..., var/get/<name>, var/set/<name>, var/op/<op>/<name>, fn/<mod>.<Name>, brain/..."
        },
        "x": {
          "type": "number"
        },
        "y": {
          "type": "number"
        },
        "values": {
          "type": "object",
          "description": "what is typed into its inputs, by pin name; things by address (\"thing/Longsword\")"
        },
        "pins": {
          "type": "integer",
          "description": "inputs added with + Add pin",
          "minimum": 0,
          "maximum": 16
        },
        "off": {
          "type": "boolean",
          "description": "switched off: a run passes straight through it"
        },
        "comment": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "node"
      ]
    },
    "wire": {
      "type": "object",
      "description": "a wire from an output to an input",
      "properties": {
        "from": {
          "type": "string",
          "description": "the node it leaves"
        },
        "out": {
          "type": "string",
          "description": "its output pin"
        },
        "to": {
          "type": "string",
          "description": "the node it goes into"
        },
        "in": {
          "type": "string",
          "description": "its input pin"
        }
      },
      "required": [
        "from",
        "out",
        "to",
        "in"
      ]
    },
    "note": {
      "type": "object",
      "description": "a comment box",
      "properties": {
        "text": {
          "type": "string"
        },
        "x": {
          "type": "number"
        },
        "y": {
          "type": "number"
        },
        "w": {
          "type": "number"
        },
        "h": {
          "type": "number"
        },
        "node": {
          "type": "string",
          "description": "the node it points at"
        },
        "colour": {
          "type": "string"
        }
      }
    },
    "function": {
      "type": "object",
      "description": "a function: a node kind fn/<mod id>.<name>",
      "properties": {
        "name": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_]+$",
          "description": "its name"
        },
        "title": {
          "type": "string"
        },
        "note": {
          "type": "string"
        },
        "category": {
          "type": "string"
        },
        "pure": {
          "type": "boolean",
          "description": "worked out when asked, with no run pins"
        },
        "inputs": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/var"
          }
        },
        "outputs": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/var"
          }
        },
        "vars": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/var"
          }
        },
        "nodes": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/node"
          }
        },
        "wires": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/wire"
          }
        },
        "notes": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/note"
          }
        }
      },
      "required": [
        "name"
      ]
    }
  },
  "type": "object",
  "properties": {
    "$schema": {
      "type": "string",
      "description": "this schema's address, for an editor"
    },
    "graph": {
      "type": "integer",
      "description": "the graph file format",
      "minimum": 1,
      "maximum": 1
    },
    "name": {
      "type": "string"
    },
    "title": {
      "type": "string"
    },
    "note": {
      "type": "string"
    },
    "vars": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/var"
      }
    },
    "nodes": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/node"
      }
    },
    "wires": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/wire"
      }
    },
    "notes": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/note"
      }
    },
    "functions": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/function"
      }
    }
  },
  "additionalProperties": false
}
