{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://shroudforge.net/schemas/1.8.1/extended.mod.schema.json",
  "title": "ShroudForge mod extension",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "enabled"
  ],
  "properties": {
    "$schema": {
      "type": "string"
    },
    "schemaVersion": {
      "const": 1
    },
    "enabled": {
      "type": "boolean"
    },
    "targets": {
      "description": "Processes this mod runs in. Legacy EML packages without targets default to client and server. ShroudForge packages default to client.",
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "enum": [
          "client",
          "server"
        ]
      }
    },
    "launcher": {
      "description": "Launcher that originally identified this mod. Omit for ShroudForge mods. Use EML to preserve EML provenance.",
      "enum": [
        "EML",
        "SF"
      ]
    },
    "links": {
      "type": "object",
      "propertyNames": {
        "pattern": "^[a-z][a-z0-9-]*$"
      },
      "additionalProperties": {
        "type": "string",
        "pattern": "^https://",
        "maxLength": 2048
      }
    },
    "changelog": {
      "type": "array",
      "maxItems": 50,
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 500
      }
    },
    "settings": {
      "type": "object",
      "propertyNames": {
        "pattern": "^[A-Za-z0-9._-]{1,80}$"
      },
      "additionalProperties": {
        "oneOf": [
          {
            "type": [
              "boolean",
              "string",
              "number",
              "array"
            ]
          },
          {
            "$ref": "#/$defs/setting"
          }
        ]
      }
    },
    "groups": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/group"
      }
    },
    "inputReservations": {
      "$ref": "#/$defs/inputReservations"
    },
    "presets": {
      "description": "Setting presets, keyed by the string setting that chooses them. Choosing a preset sets each listed setting. Editing one of them selects the custom value.",
      "type": "object",
      "propertyNames": {
        "pattern": "^[A-Za-z0-9._-]{1,80}$"
      },
      "additionalProperties": {
        "$ref": "#/$defs/preset"
      }
    }
  },
  "$defs": {
    "setting": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "value"
      ],
      "properties": {
        "value": {
          "type": [
            "boolean",
            "string",
            "number",
            "array"
          ]
        },
        "label": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "description": {
          "type": "string",
          "maxLength": 500
        },
        "control": {
          "enum": [
            "toggle",
            "checkbox",
            "text",
            "textarea",
            "number",
            "slider",
            "select",
            "radio",
            "segmented",
            "multiselect",
            "keybind",
            "color"
          ]
        },
        "applyAt": {
          "enum": [
            "live",
            "restart"
          ]
        },
        "restartRequired": {
          "type": "boolean"
        },
        "assetPreparation": {
          "type": "boolean"
        },
        "enabledWhen": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "setting",
            "equals"
          ],
          "properties": {
            "setting": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._-]{1,80}$"
            },
            "equals": {
              "type": [
                "boolean",
                "string",
                "number"
              ]
            }
          }
        },
        "min": {
          "type": "number"
        },
        "max": {
          "type": "number"
        },
        "step": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "minLength": {
          "type": "integer",
          "minimum": 0
        },
        "maxLength": {
          "type": "integer",
          "minimum": 0
        },
        "options": {
          "type": "object",
          "minProperties": 1,
          "additionalProperties": {
            "oneOf": [
              {
                "type": "string",
                "minLength": 1,
                "maxLength": 120
              },
              {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "label"
                ],
                "properties": {
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120
                  },
                  "group": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 60
                  }
                }
              }
            ]
          }
        }
      },
      "allOf": [
        {
          "if": {
            "required": [
              "control"
            ],
            "properties": {
              "control": {
                "const": "keybind"
              }
            }
          },
          "then": {
            "properties": {
              "value": {
                "type": "string",
                "maxLength": 96,
                "description": "One shortcut string containing an SDL keyboard chord, a Mouse button chord, or keyboard|mouse alternatives. Each chord supports ordered Ctrl, Alt, Shift and Meta prefixes. Empty disables the shortcut.",
                "pattern": "^(?:(?:Ctrl\\+)?(?:Alt\\+)?(?:Shift\\+)?(?:Meta\\+)?SDL:[1-9][0-9]{0,2}(?:\\|(?:Ctrl\\+)?(?:Alt\\+)?(?:Shift\\+)?(?:Meta\\+)?Mouse:[1-9][0-9]?)?|(?:Ctrl\\+)?(?:Alt\\+)?(?:Shift\\+)?(?:Meta\\+)?Mouse:[1-9][0-9]?)?$"
              }
            }
          }
        }
      ]
    },
    "action": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "label"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9._-]{1,80}$"
        },
        "label": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "style": {
          "enum": [
            "primary",
            "secondary",
            "danger"
          ]
        },
        "confirm": {
          "type": "string",
          "maxLength": 500
        }
      }
    },
    "group": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "label"
      ],
      "properties": {
        "label": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "description": {
          "type": "string",
          "maxLength": 500
        },
        "settings": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string",
            "pattern": "^[A-Za-z0-9._-]{1,80}$"
          }
        },
        "actions": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/action"
          }
        },
        "tab": {
          "type": "boolean"
        }
      }
    },
    "inputReservations": {
      "description": "Keys and mouse wheel the game may be denied while the mod reports one of its contexts. A ShroudForge without input reservations ignores this block.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "contexts": {
          "type": "object",
          "propertyNames": {
            "pattern": "^[A-Za-z0-9._-]{1,80}$"
          },
          "additionalProperties": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          }
        },
        "keys": {
          "type": "object",
          "propertyNames": {
            "pattern": "^[A-Za-z0-9._-]{1,80}$"
          },
          "additionalProperties": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "when"
            ],
            "properties": {
              "when": {
                "type": "string",
                "pattern": "^[A-Za-z0-9._-]{1,80}$"
              },
              "keyboard": {
                "type": "boolean"
              },
              "mouse": {
                "type": "boolean"
              }
            }
          }
        },
        "wheels": {
          "type": "object",
          "propertyNames": {
            "pattern": "^[A-Za-z0-9._-]{1,80}$"
          },
          "additionalProperties": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "when"
            ],
            "properties": {
              "when": {
                "type": "string",
                "pattern": "^[A-Za-z0-9._-]{1,80}$"
              }
            }
          }
        },
        "choices": {
          "description": "The player's padlocks, written by the Modloader.",
          "type": "object",
          "propertyNames": {
            "pattern": "^[A-Za-z0-9._-]{1,80}$"
          },
          "additionalProperties": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "keyboard": {
                "type": "boolean"
              },
              "mouse": {
                "type": "boolean"
              }
            }
          }
        }
      }
    },
    "preset": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "settings",
        "values"
      ],
      "properties": {
        "custom": {
          "description": "Controller value meaning hand-tuned settings. Defaults to custom.",
          "type": "string",
          "minLength": 1
        },
        "settings": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "pattern": "^[A-Za-z0-9._-]{1,80}$"
          }
        },
        "values": {
          "description": "One entry per preset value of the controller, giving a value to every listed setting.",
          "type": "object",
          "minProperties": 1,
          "additionalProperties": {
            "type": "object",
            "propertyNames": {
              "pattern": "^[A-Za-z0-9._-]{1,80}$"
            },
            "additionalProperties": {
              "type": [
                "boolean",
                "string",
                "number",
                "array"
              ]
            }
          }
        }
      }
    }
  }
}
