Instructions for setting up schemas on AS

This commit is contained in:
Yair Morgenstern 2023-09-21 23:00:57 +03:00
parent 14c5d9eb17
commit ab3a04f50f
3 changed files with 58 additions and 41 deletions

View File

@ -8,4 +8,5 @@ nav:
- Creating-a-UI-skin.md - Creating-a-UI-skin.md
- Unique-parameters.md - Unique-parameters.md
- uniques.md - uniques.md
- Type-checking.md

View File

@ -0,0 +1,17 @@
# Type checking
Mistakes happen. Misnamed fields, things we forgot to add, or even stuff we didn't know existed.
Computers can handle a lot of that themselves, so we can let them do the work to ensure that our json files are correct, by using *json schemas*.
As of now, only Buildings.json has a proper schema
## Using Android Studio
- Double-click space, search "json schema mappings", enter
- Click the small '+' (top, under 'language & frameworks' text)
- Put the URL as `https://raw.githubusercontent.com/yairm210/Unciv/master/docs/Modders/schemas/buildings.json`
- Click the '+' under the 'Schema version' text, add 'File pattern', put pattern as `*/Buildings.json`
Tada! Now Android Studio will recognize all Buildings.json files as belonging to that schema, and will warn you of inconsistencies!

View File

@ -2,15 +2,15 @@
"$schema": "http://json-schema.org/draft-07/schema", "$schema": "http://json-schema.org/draft-07/schema",
"type": "array", "type": "array",
"items": { "items": {
"allOf": [
{ "$ref": "#/definitions/stats"},
{
"type": "object", "type": "object",
"properties": { "properties": {
"name": { "type": "string" }, "name": { "type": "string" },
"uniques": { "uniques": {
"type": "array", "type": "array",
"items": { "type": "string" }, "items": {
"type": "string",
"pattern": "^[^><]*(\\<[^>]*\\>[^><]*)*$"
},
"uniqueItems": true // Can't imagine you mean to include the same thing twice "uniqueItems": true // Can't imagine you mean to include the same thing twice
}, },
"civilopediaText": { "civilopediaText": {
@ -42,9 +42,8 @@
"required": [ "required": [
"name" "name"
], ],
"additionalProperties": false, "allOf": [{ "$ref": "#/definitions/stats"}],
} "additionalProperties": false
],
}, },
"definitions": { "definitions": {
"stats": { "stats": {