{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://libraries.ludic-assembly.victorqueiroz.dev/schema.json",
  "title": "Ludic Assembly 0.1",
  "description": "Structural schema. Use validateAsset for reference, graph, bounds and geometry validation.",
  "type": "object",
  "properties": {
    "schema": {
      "const": "asset-assembly/0.1"
    },
    "units": {
      "enum": ["meters", "tiles"]
    },
    "parameters": {
      "type": "object",
      "minProperties": 0,
      "maxProperties": 256,
      "propertyNames": {
        "pattern": "^[A-Za-z][A-Za-z0-9_-]{0,79}$"
      },
      "additionalProperties": {
        "type": "number"
      }
    },
    "materials": {
      "type": "object",
      "minProperties": 1,
      "maxProperties": 256,
      "propertyNames": {
        "pattern": "^[A-Za-z][A-Za-z0-9_-]{0,79}$"
      },
      "additionalProperties": {
        "type": "object",
        "properties": {
          "color": {
            "type": "string",
            "pattern": "^#[0-9a-fA-F]{6}$"
          },
          "tintable": {
            "type": "boolean"
          }
        },
        "required": ["color"],
        "additionalProperties": false
      }
    },
    "groups": {
      "type": "object",
      "minProperties": 0,
      "maxProperties": 256,
      "propertyNames": {
        "pattern": "^[A-Za-z][A-Za-z0-9_-]{0,79}$"
      },
      "additionalProperties": {
        "type": "object",
        "properties": {
          "parent": {
            "type": "string"
          },
          "position": {
            "$ref": "#/$defs/point"
          }
        },
        "required": ["position"],
        "additionalProperties": false
      }
    },
    "parts": {
      "type": "object",
      "minProperties": 1,
      "maxProperties": 256,
      "propertyNames": {
        "pattern": "^[A-Za-z][A-Za-z0-9_-]{0,79}$"
      },
      "additionalProperties": {
        "type": "object",
        "properties": {
          "shape": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "type": {
                    "const": "box"
                  },
                  "size": {
                    "type": "object",
                    "properties": {
                      "width": {
                        "$ref": "#/$defs/scalar"
                      },
                      "height": {
                        "$ref": "#/$defs/scalar"
                      },
                      "depth": {
                        "$ref": "#/$defs/scalar"
                      }
                    },
                    "required": ["width", "height", "depth"],
                    "additionalProperties": false
                  },
                  "bevel": {
                    "$ref": "#/$defs/scalar"
                  }
                },
                "required": ["type", "size"],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "const": "cylinder"
                  },
                  "radius": {
                    "$ref": "#/$defs/scalar"
                  },
                  "height": {
                    "$ref": "#/$defs/scalar"
                  }
                },
                "required": ["type", "radius", "height"],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "const": "funnel"
                  },
                  "bottomRadius": {
                    "$ref": "#/$defs/scalar"
                  },
                  "topRadius": {
                    "$ref": "#/$defs/scalar"
                  },
                  "height": {
                    "$ref": "#/$defs/scalar"
                  }
                },
                "required": ["type", "bottomRadius", "topRadius", "height"],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "const": "beam"
                  },
                  "from": {
                    "$ref": "#/$defs/point"
                  },
                  "to": {
                    "$ref": "#/$defs/point"
                  },
                  "width": {
                    "$ref": "#/$defs/scalar"
                  }
                },
                "required": ["type", "from", "to", "width"],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "const": "tube"
                  },
                  "from": {
                    "$ref": "#/$defs/point"
                  },
                  "to": {
                    "$ref": "#/$defs/point"
                  },
                  "radius": {
                    "$ref": "#/$defs/scalar"
                  }
                },
                "required": ["type", "from", "to", "radius"],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "const": "coil"
                  },
                  "radius": {
                    "$ref": "#/$defs/scalar"
                  },
                  "thickness": {
                    "$ref": "#/$defs/scalar"
                  }
                },
                "required": ["type", "radius", "thickness"],
                "additionalProperties": false
              }
            ]
          },
          "material": {
            "type": "string"
          },
          "placement": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "type": {
                    "const": "absolute"
                  },
                  "selfAnchor": {
                    "type": "string"
                  },
                  "position": {
                    "$ref": "#/$defs/point"
                  }
                },
                "required": ["type", "selfAnchor", "position"],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "const": "attach"
                  },
                  "selfAnchor": {
                    "type": "string"
                  },
                  "target": {
                    "type": "object",
                    "properties": {
                      "part": {
                        "type": "string"
                      },
                      "anchor": {
                        "type": "string"
                      }
                    },
                    "required": ["part", "anchor"],
                    "additionalProperties": false
                  },
                  "offset": {
                    "$ref": "#/$defs/point"
                  }
                },
                "required": ["type", "selfAnchor", "target"],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "const": "repeat"
                  },
                  "pattern": {
                    "const": "corners"
                  },
                  "selfAnchor": {
                    "type": "string"
                  },
                  "target": {
                    "type": "object",
                    "properties": {
                      "part": {
                        "type": "string"
                      },
                      "face": {
                        "enum": ["top", "bottom"]
                      }
                    },
                    "required": ["part", "face"],
                    "additionalProperties": false
                  },
                  "edgeInset": {
                    "type": "object",
                    "properties": {
                      "x": {
                        "$ref": "#/$defs/scalar"
                      },
                      "z": {
                        "$ref": "#/$defs/scalar"
                      }
                    },
                    "required": ["x", "z"],
                    "additionalProperties": false
                  }
                },
                "required": ["type", "pattern", "selfAnchor", "target", "edgeInset"],
                "additionalProperties": false
              }
            ]
          },
          "parent": {
            "type": "string"
          },
          "anchors": {
            "type": "object",
            "minProperties": 0,
            "maxProperties": 256,
            "propertyNames": {
              "pattern": "^[A-Za-z][A-Za-z0-9_-]{0,79}$"
            },
            "additionalProperties": {
              "$ref": "#/$defs/point"
            }
          }
        },
        "required": ["shape", "material", "placement"],
        "additionalProperties": false
      }
    },
    "groundPivot": {
      "$ref": "#/$defs/point"
    }
  },
  "required": ["schema", "units", "materials", "parts"],
  "additionalProperties": false,
  "$defs": {
    "scalar": {
      "oneOf": [
        {
          "type": "number"
        },
        {
          "type": "object",
          "properties": {
            "parameter": {
              "type": "string"
            }
          },
          "required": ["parameter"],
          "additionalProperties": false
        }
      ]
    },
    "point": {
      "type": "object",
      "properties": {
        "x": {
          "$ref": "#/$defs/scalar"
        },
        "y": {
          "$ref": "#/$defs/scalar"
        },
        "z": {
          "$ref": "#/$defs/scalar"
        }
      },
      "required": ["x", "y", "z"],
      "additionalProperties": false
    }
  }
}
