{
  "$schema": "http://json-schema.org/draft-07/schema",
  "$id": "https://appliedenergistics.github.io/screen_style",
  "type": "object",
  "title": "AE2 Screen Style",
  "description": "Provides styling information for an AE2 UI screen",
  "required": [],
  "definitions": {
    "position": {
      "$comment": "Used to position an element in relationship to the size of the current dialog",
      "$id": "Position",
      "type": "object",
      "properties": {
        "left": {
          "type": "number",
          "description": "Positions the content to the right (positive) or left (negative) of the left screen edge."
        },
        "top": {
          "type": "number",
          "description": "Positions the content to the bottom (positive) or top (negative) of the top screen edge."
        },
        "right": {
          "type": "number",
          "description": "Positions the content to the left (positive) or right (negative) of the right screen edge."
        },
        "bottom": {
          "type": "number",
          "description": "Positions the content to the top (positive) or bottom (negative) of the bottom screen edge."
        }
      }
    },
    "color": {
      "$comment": "Definition of a color using a fake HTML notation",
      "type": "string",
      "pattern": "^#([0-9a-fA-F]{2}){3,4}$"
    },
    "text": {
      "$comment": "JSON schema definition of Minecraft text https://minecraft.wiki/w/Raw_JSON_text_format",
      "type": "object",
      "properties": {
        "extra": {
          "description": "Text that is displayed after this text, but that inherits this texts properties.",
          "type": "array",
          "items": {
            "$ref": "#/definitions/text"
          }
        },
        "color": {
          "type": "string",
          "pattern": "^#([0-9a-fA-F]{6})$"
        },
        "font": {
          "type": "string",
          "default": "minecraft:default",
          "description": "Font in assets/<namespace>/font"
        },
        "bold": {
          "type": "boolean",
          "default": false
        },
        "italic": {
          "type": "boolean",
          "default": false
        },
        "underlined": {
          "type": "boolean",
          "default": false
        },
        "strikethrough": {
          "type": "boolean",
          "default": false
        },
        "obfuscated": {
          "type": "boolean",
          "default": false
        },
        "insertion": {
          "type": "string",
          "description": "When shift-clicked while the chat is open, the text of this property will be inserted."
        },
        "clickEvent": {
          "type": "object",
          "properties": {
            "action": {
              "type": "string",
              "enum": [
                "open_url",
                "open_file",
                "run_command",
                "suggest_command",
                "change_page",
                "copy_to_clipboard"
              ]
            },
            "value": {
              "type": "string"
            }
          },
          "required": ["action", "value"]
        },
        "hoverEvent": {
          "type": "object",
          "oneOf": [
            {
              "properties": {
                "action": {
                  "const": "show_text"
                },
                "contents": {
                  "$ref": "#/definitions/text"
                }
              }
            },
            {
              "properties": {
                "action": {
                  "const": "show_item"
                },
                "contents": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "default": "minecraft:air",
                      "description": "The item to show"
                    },
                    "count": {
                      "type": "integer",
                      "default": 1,
                      "description": "The item stack size"
                    },
                    "tag": {
                      "type": "string",
                      "description": "NBT of the item, serialized as string. See https://minecraft.wiki/w/Player.dat_format#Item_structure"
                    }
                  },
                  "required": ["id"]
                }
              }
            },
            {
              "properties": {
                "action": {
                  "const": "show_entity"
                },
                "contents": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "$ref": "#/definitions/text"
                    },
                    "type": {
                      "type": "string",
                      "default": "minecraft:pig",
                      "description": "The entity type id to show"
                    },
                    "id": {
                      "type": "string",
                      "description": "UUID of the entity to show"
                    }
                  }
                }
              }
            }
          ]
        }
      },
      "oneOf": [
        {
          "properties": {
            "text": {
              "description": "Display simple text",
              "type": "string"
            }
          },
          "required": ["text"]
        },
        {
          "properties": {
            "translate": {
              "description": "The ID of a translation key",
              "type": "string"
            },
            "with": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/text"
              }
            }
          },
          "required": ["translate"]
        },
        {
          "properties": {
            "keybind": {
              "type": "string",
              "description": "A keybind identifier"
            }
          },
          "required": ["keybind"]
        }
      ]
    },
    "rect": {
      "oneOf": [
        {
          "type": "array",
          "items": [
            {
              "type": "integer",
              "description": "x"
            },
            {
              "type": "integer",
              "description": "y"
            },
            {
              "type": "integer",
              "description": "width"
            },
            {
              "type": "integer",
              "description": "height"
            }
          ],
          "additionalItems": false
        },
        {
          "type": "object",
          "properties": {
            "x": {
              "type": "integer"
            },
            "y": {
              "type": "integer"
            },
            "width": {
              "type": "integer"
            },
            "height": {
              "type": "integer"
            }
          },
          "additionalProperties": false
        }
      ]
    },
    "blitter": {
      "type": "object",
      "properties": {
        "texture": {
          "type": "string"
        },
        "textureWidth": {
          "type": "integer",
          "default": 256
        },
        "textureHeight": {
          "type": "integer",
          "default": 256
        },
        "srcRect": {
          "$ref": "#/definitions/rect"
        }
      },
      "required": ["texture"]
    },
    "generatedBackground": {
      "type": "object",
      "properties": {
        "width": {
          "type": "integer"
        },
        "height": {
          "type": "integer"
        }
      },
      "required": ["width", "height"]
    }
  },
  "properties": {
    "includes": {
      "description": "Relative path to other files to include before processing this one.",
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "palette": {
      "$comment": "See PaletteColor enum",
      "type": "object",
      "description": "Defines colors used through the UI screen",
      "properties": {
        "DEFAULT_TEXT_COLOR": {
          "$ref": "#/definitions/color"
        },
        "MUTED_TEXT_COLOR": {
          "$ref": "#/definitions/color"
        },
        "SELECTION_COLOR": {
          "$ref": "#/definitions/color"
        },
        "TEXTFIELD_PLACEHOLDER": {
          "$ref": "#/definitions/color"
        },
        "TEXTFIELD_SELECTION": {
          "$ref": "#/definitions/color"
        },
        "TEXTFIELD_ERROR": {
          "$ref": "#/definitions/color"
        },
        "TEXTFIELD_TEXT": {
          "$ref": "#/definitions/color"
        },
        "ERROR": {
          "$ref": "#/definitions/color"
        }
      }
    },
    "background": {
      "$ref": "#/definitions/blitter"
    },
    "generatedBackground": {
      "$ref": "#/definitions/generatedBackground"
    },
    "slots": {
      "type": "object",
      "description": "Defines positions for slots and their grid alignment",
      "additionalProperties": {
        "type": "object",
        "allOf": [
          {
            "properties": {
              "grid": {
                "$comment": "Configures the slots with this semantic in a grid",
                "enum": [
                  "IO_BUS_CONFIG",
                  "BREAK_AFTER_9COLS",
                  "BREAK_AFTER_2COLS",
                  "BREAK_AFTER_3COLS",
                  "HORIZONTAL",
                  "VERTICAL"
                ]
              }
            }
          },
          {
            "$ref": "#/definitions/position"
          }
        ]
      },
      "propertyNames": {
        "$comment": "List SlotSemantic names here",
        "enum": [
          "NONE",
          "STORAGE",
          "PLAYER_INVENTORY",
          "PLAYER_HOTBAR",
          "TOOLBOX",
          "CONFIG",
          "UPGRADE",
          "STORAGE_CELL",
          "INSCRIBER_PLATE_TOP",
          "INSCRIBER_PLATE_BOTTOM",
          "MACHINE_INPUT",
          "MACHINE_PROCESSING",
          "MACHINE_OUTPUT",
          "MACHINE_CRAFTING_GRID",
          "BLANK_PATTERN",
          "ENCODED_PATTERN",
          "VIEW_CELL",
          "CRAFTING_GRID",
          "CRAFTING_RESULT",
          "PROCESSING_INPUTS",
          "PROCESSING_OUTPUTS",
          "SMITHING_TABLE_TEMPLATE",
          "SMITHING_TABLE_BASE",
          "SMITHING_TABLE_ADDITION",
          "SMITHING_TABLE_RESULT",
          "STONECUTTING_INPUT",
          "MISSING_INGREDIENT"
        ]
      }
    },
    "text": {
      "description": "Defines text that will be shown on the UI, the property name is used to reference text from code",
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "properties": {
          "text": {
            "$ref": "#/definitions/text"
          },
          "color": {
            "$comment": "See enum PaletteColor",
            "enum": [
              "DEFAULT_TEXT_COLOR",
              "MUTED_TEXT_COLOR",
              "SELECTION_COLOR",
              "ERROR"
            ],
            "default": "DEFAULT_TEXT_COLOR"
          },
          "position": {
            "$ref": "#/definitions/position"
          },
          "scale": {
            "type": "number",
            "default": 1,
            "minimum": 0.1,
            "maximum": 4,
            "$comment": "Can be used to display smaller text, 0.5 works well, usually"
          },
          "align": {
            "type": "string",
            "default": "LEFT",
            "enum": ["LEFT", "CENTER", "RIGHT"]
          },
          "maxWidth": {
            "type": "number",
            "minimum": 0,
            "default": 0,
            "description": "If greater than 0, the text will be word-wrapped when it reaches the given width in pixels."
          }
        }
      }
    },
    "tooltips": {
      "description": "Defines areas that will show a tooltip on the screen. These areas are evaluated after everything else that could show a tooltip.",
      "type": "object",
      "additionalProperties": {
        "allOf": [
          {
            "type": "object",
            "properties": {
              "tooltip": {
                "type": "array",
                "items": {
                  "$ref": "#/definitions/text"
                }
              },
              "width": {
                "type": "integer"
              },
              "height": {
                "type": "integer"
              }
            },
            "required": ["tooltip", "width", "height"]
          },
          {
            "$ref": "#/definitions/position"
          }
        ]
      }
    },
    "images": {
      "description": "Additional screen-specific images",
      "additionalProperties": {
        "$ref": "#/definitions/blitter"
      }
    },
    "helpTopic": {
      "description": "Overrides the default help topic for this screen. This will be resolved as a link to a page in the guidebook and may contain an optional fragment (#some-heading) to directly link to a heading or anchor in the page.",
      "type": "string"
    },
    "terminalStyle": {
      "description": "If this screen is a terminal, this defines required properties to display it properly",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "header": {
          "description": "The top of the terminal background right up to the first row of content.",
          "$ref": "#/definitions/blitter"
        },
        "firstRow": {
          "description": "The area to draw for the first row in the terminal. Usually this includes the top of the scrollbar.",
          "$ref": "#/definitions/blitter"
        },
        "row": {
          "description": "The area to repeat for every row in the terminal. Should be 16px for the item + 2px for the border in size.",
          "$ref": "#/definitions/blitter"
        },
        "lastRow": {
          "description": "The area to draw for the last row in the terminal. Usually this includes the top of the scrollbar.",
          "$ref": "#/definitions/blitter"
        },
        "bottom": {
          "description": "The area to draw at the bottom of the terminal (i.e. includes the player inventory).",
          "$ref": "#/definitions/blitter"
        },
        "maxRows": {
          "description": "If specified, limits the terminal to at most this many rows rather than using up available space.",
          "type": "integer",
          "minimum": 3
        },
        "slotsPerRow": {
          "description": "The number of slots per row on the background image.",
          "type": "integer",
          "minimum": 1
        },
        "sortable": {
          "description": "Defines if this terminal has a sort by button.",
          "type": "boolean",
          "default": true
        },
        "supportsAutoCrafting": {
          "description": "Defines if this terminal supports auto-crafting. If not, the button to show only craftable items is hidden.",
          "type": "boolean",
          "default": false
        },
        "stackSizeStyle": {
          "description": "The type of stack size rendering to use.",
          "type": "string",
          "default": "ITEMS",
          "enum": ["ITEMS", "FLUIDS"]
        },
        "showTooltipsWithItemInHand": {
          "type": "boolean",
          "default": false,
          "description": "Should the terminal show item tooltips for the network inventory even if the player has an item in their hand? Useful for showing fluid tooltips when the player has a bucket in hand."
        }
      }
    },
    "widgets": {
      "description": "Defines properties of various widgets that are positioned on the screen. The properties are widget-dependant. Which widget is placed is decided in code.",
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "allOf": [
          {
            "$ref": "#/definitions/position"
          },
          {
            "properties": {
              "width": {
                "type": "integer"
              },
              "height": {
                "type": "integer"
              },
              "hideEdge": {
                "description": "Used to hide the border around TabButtons",
                "type": "boolean"
              }
            }
          }
        ]
      }
    }
  }
}
