Skip to content

Commit

Permalink
Adding ui-json schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
DaanV2 committed Oct 23, 2023
1 parent 6643219 commit dfe72ca
Show file tree
Hide file tree
Showing 17 changed files with 1,875 additions and 0 deletions.
3 changes: 3 additions & 0 deletions source/compress_specification.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
{ "Source": "./resource/sounds/sound_definitions.json", "Destination": "../resource/sounds/sound_definitions.json" },
{ "Source": "./resource/sounds.json", "Destination": "../resource/sounds.json" },
{ "Source": "./resource/textures/terrain_texture.json", "Destination": "../resource/textures/terrain_texture.json" },
{ "Source": "./resource/ui/ui.json", "Destination": "../resource/ui/ui.json" },
{ "Source": "./resource/ui/_ui_defs.json", "Destination": "../resource/ui/_ui_defs.json" },
{ "Source": "./resource/ui/ui.json", "Destination": "../resource/ui/ui.json" },
{ "Source": "./behavior/animation_controllers/animation_controller.json", "Destination": "../behavior/animation_controllers/animation_controller.json" },
{ "Source": "./behavior/animations/animations.json", "Destination": "../behavior/animations/animations.json" },
{ "Source": "./behavior/biomes/biomes.json", "Destination": "../behavior/biomes/biomes.json" },
Expand Down
12 changes: 12 additions & 0 deletions source/resource/ui/_global_variables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"title": "Global Variables",
"description": "Global variables that can be used in any JSON file.",
"type": "object",
"propertyNames": {
"pattern": "^\\$[a-zA-Z0-9_]+$"
},
"additionalProperties": {
"title": "Global Variable",
"type": ["array", "boolean", "integer", "number", "string"]
}
}
17 changes: 17 additions & 0 deletions source/resource/ui/_ui_defs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"title": "UI definitions",
"type": "object",
"properties": {
"ui_defs": {
"title": "UI definitions",
"type": "array",
"items": {
"type": "string",
"title": "UI definition path",
"description": "Path to a UI definition file.",
"examples": ["ui/button.json", "ui/checkbox.json"]
}
}
}
}
6 changes: 6 additions & 0 deletions source/resource/ui/general/anchor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"title": "Anchor",
"description": "An anchor is a reference to an element in the UI.",
"type": "string",
"enum": ["bottom", "bottom_left", "bottom_right", "bottom_middle", "center", "left", "left_middle", "right", "right_middle", "top", "top_left", "top_right", "top_middle"]
}
5 changes: 5 additions & 0 deletions source/resource/ui/general/any.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"title": "Any",
"description": "An any value.",
"type": ["array", "boolean", "integer", "number", "object", "string"]
}
14 changes: 14 additions & 0 deletions source/resource/ui/general/boolean.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"title": "Boolean",
"description": "A boolean value.",
"anyOf": [
{
"type": "boolean"
},
{
"type": "string",
"$ref": "./item_ref.json"
}
],
"examples": ["true", "false", "$variable", "($variable)"]
}
40 changes: 40 additions & 0 deletions source/resource/ui/general/color.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"definitions": {
"color_item": {
"type": "number",
"minimum": 0,
"maximum": 1
}
},
"oneOf": [
{
"type": "string",
"description": "A variable",
"$ref": "./item_ref.json"
},
{
"type": "array",
"description": "A size with width and height.",
"items": [
{
"title": "Red",
"type": "string",
"description": "A variable",
"$ref": "#/definitions/color_item"
},
{
"title": "Green",
"type": "string",
"description": "A variable",
"$ref": "#/definitions/color_item"
},
{
"title": "Blue",
"type": "string",
"description": "A variable",
"$ref": "#/definitions/color_item"
}
]
}
]
}
14 changes: 14 additions & 0 deletions source/resource/ui/general/integer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"title": "Integer",
"description": "A integer value.",
"oneOf": [
{
"type": "integer"
},
{
"type": "string",
"$ref": "./item_ref.json"
}
],
"examples": [0, 1, 2, "$variable", "($variable)"]
}
35 changes: 35 additions & 0 deletions source/resource/ui/general/item_ref.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"anyOf": [
{
"title": "Item reference",
"description": "A reference to an item: using the following syntax: [element_name]@[namespace_reference].[element_name_reference]",
"type": "string",
"examples": ["button@minecraft", "button@minecraft:ui"],
"pattern": "^[a-zA-Z0-9_]*@[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)?$"
},
{
"title": "Item reference",
"description": "A reference to an item: using the following syntax: [namespace_reference].[element_name_reference]",
"type": "string",
"examples": ["button@minecraft", "button@minecraft:ui"],
"pattern": "[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)?$"
},
{
"title": "Variable reference",
"description": "A variable is a reference to a value that can be used in the UI.",
"type": "string",
"anyOf": [
{
"pattern": "^\\$[a-zA-Z0-9_]+$"
},
{
"pattern": "^#[a-zA-Z0-9_]+$"
},
{
"pattern": "^\\(.*\\)$"
}
]
}
]
}
14 changes: 14 additions & 0 deletions source/resource/ui/general/number.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"title": "Number",
"description": "A Number value.",
"oneOf": [
{
"type": "number"
},
{
"type": "string",
"$ref": "./item_ref.json"
}
],
"examples": [0, 1, 2, "$variable", "($variable)"]
}
51 changes: 51 additions & 0 deletions source/resource/ui/general/size.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"title": "Size",
"description": "The size of the element.",
"definitions": {
"size_coord": {
"title": "Size Coord",
"description": "A size coordinate.",
"oneOf": [
{
"type": "string",
"enum": ["default", "fill"]
},
{
"type": "string",
"pattern": "^[0-9]+(px|%)$"
},
{
"type": "integer",
"minimum": 0
}
],
"examples": ["default", "fill", "100px", "100%", "100% - 2px"]
}
},
"oneOf": [
{
"type": "string",
"description": "A variable",
"$ref": "./item_ref.json"
},
{
"type": "array",
"description": "A size with width and height.",
"items": [
{
"title": "Width",
"type": "string",
"description": "A variable",
"$ref": "#/definitions/size_coord"
},
{
"title": "Height",
"type": "string",
"description": "A variable",
"$ref": "#/definitions/size_coord"
}
]
}
],
"examples": ["default", "fill", ["100%", "100%"]]
}
5 changes: 5 additions & 0 deletions source/resource/ui/general/string.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"title": "String",
"description": "A string value.",
"anyOf": [{ "type": "string" }, { "type": "string", "$ref": "./item_ref.json" }]
}
20 changes: 20 additions & 0 deletions source/resource/ui/general/variable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"title": "Variable",
"description": "A variable is a reference to a value that can be used in the UI.",
"type": "string",
"anyOf": [
{
"type": "string",
"pattern": "^\\$[a-zA-Z0-9_]+$"
},
{
"type": "string",
"pattern": "^#[a-zA-Z0-9_]+$"
},
{
"type": "string",
"pattern": "^\\(.*\\)$"
}
],
"examples": ["$variable", "($variable)"]
}
47 changes: 47 additions & 0 deletions source/resource/ui/general/vec2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"definitions": {
"size_coord": {
"oneOf": [
{
"type": "string",
"enum": ["default", "fill"]
},
{
"type": "string",
"pattern": "^[0-9]+(px|%)$"
},
{
"type": "integer",
"minimum": 0
}
],
"examples": ["default", "fill", "100px", "100%", "100% - 2px"]
}
},
"oneOf": [
{
"type": "string",
"description": "A variable",
"$ref": "./item_ref.json"
},
{
"type": "array",
"description": "A size with width and height.",
"items": [
{
"title": "Width",
"type": "string",
"description": "A variable",
"$ref": "#/definitions/size_coord"
},
{
"title": "Height",
"type": "string",
"description": "A variable",
"$ref": "#/definitions/size_coord"
}
]
}
],
"examples": ["default", "fill", ["100%", "100%"]]
}
55 changes: 55 additions & 0 deletions source/resource/ui/general/vec4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"definitions": {
"size_coord": {
"oneOf": [
{
"type": "string",
"enum": ["default", "fill"]
},
{
"type": "string",
"pattern": "^[0-9]+(px|%)$"
},
{
"type": "integer",
"minimum": 0
}
],
"examples": ["default", "fill", "100px", "100%", "100% - 2px"]
}
},
"oneOf": [
{
"type": "string",
"description": "A variable",
"$ref": "./item_ref.json"
},
{
"type": "array",
"description": "A size with width and height.",
"items": [
{
"title": "X",
"description": "A variable",
"$ref": "#/definitions/size_coord"
},
{
"title": "Y",
"description": "A variable",
"$ref": "#/definitions/size_coord"
},
{
"title": "Width",
"description": "A variable",
"$ref": "#/definitions/size_coord"
},
{
"title": "Height",
"description": "A variable",
"$ref": "#/definitions/size_coord"
}
]
}
],
"examples": ["default", "fill", ["100%", "100%"]]
}
Loading

0 comments on commit dfe72ca

Please sign in to comment.