diff --git a/docs/Modders/.pages b/docs/Modders/.pages index 4a0d2e594a..af9306a418 100644 --- a/docs/Modders/.pages +++ b/docs/Modders/.pages @@ -8,4 +8,5 @@ nav: - Creating-a-UI-skin.md - Unique-parameters.md - uniques.md + - Type-checking.md diff --git a/docs/Modders/Type-checking.md b/docs/Modders/Type-checking.md new file mode 100644 index 0000000000..a69954738f --- /dev/null +++ b/docs/Modders/Type-checking.md @@ -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! + diff --git a/docs/Modders/schemas/buildings.json b/docs/Modders/schemas/buildings.json index 7e88fd0889..922b45857c 100644 --- a/docs/Modders/schemas/buildings.json +++ b/docs/Modders/schemas/buildings.json @@ -2,49 +2,48 @@ "$schema": "http://json-schema.org/draft-07/schema", "type": "array", "items": { - "allOf": [ - { "$ref": "#/definitions/stats"}, - { - "type": "object", - "properties": { - "name": { "type": "string" }, - "uniques": { - "type": "array", - "items": { "type": "string" }, - "uniqueItems": true // Can't imagine you mean to include the same thing twice - }, - "civilopediaText": { - "type": "array", - "items": { "$ref": "#/definitions/civilopediaText"} - }, - "requiredTech": { "type": "string" }, - "cost": { "type": "number" }, - "maintenance": { "type": "number" }, - "percentStatBonus": { "$ref": "#/definitions/stats" }, - "specialistSlots": { "type": "object" }, - "greatPersonPoints": { "type": "object" }, - "hurryCostModifier": { "type": "number" }, - "isWonder": { "type": "boolean" }, - "isNationalWonder": { "type": "boolean" }, - "requiredBuilding": { "type": "string" }, - "requiredResource": { "type": "string" }, - "requiredNearbyImprovedResources": { - "type": "array", - "items": { "type": "string" } - }, - "cityStrength": { "type": "number" }, - "cityHealth": { "type": "number" }, - "replaces": { "type": "string" }, - "uniqueTo": { "type": "string" }, - "quote": { "type": "string" }, - "replacementTextForUniques": { "type": "string" } + "type": "object", + "properties": { + "name": { "type": "string" }, + "uniques": { + "type": "array", + "items": { + "type": "string", + "pattern": "^[^><]*(\\<[^>]*\\>[^><]*)*$" }, - "required": [ - "name" - ], - "additionalProperties": false, - } + "uniqueItems": true // Can't imagine you mean to include the same thing twice + }, + "civilopediaText": { + "type": "array", + "items": { "$ref": "#/definitions/civilopediaText"} + }, + "requiredTech": { "type": "string" }, + "cost": { "type": "number" }, + "maintenance": { "type": "number" }, + "percentStatBonus": { "$ref": "#/definitions/stats" }, + "specialistSlots": { "type": "object" }, + "greatPersonPoints": { "type": "object" }, + "hurryCostModifier": { "type": "number" }, + "isWonder": { "type": "boolean" }, + "isNationalWonder": { "type": "boolean" }, + "requiredBuilding": { "type": "string" }, + "requiredResource": { "type": "string" }, + "requiredNearbyImprovedResources": { + "type": "array", + "items": { "type": "string" } + }, + "cityStrength": { "type": "number" }, + "cityHealth": { "type": "number" }, + "replaces": { "type": "string" }, + "uniqueTo": { "type": "string" }, + "quote": { "type": "string" }, + "replacementTextForUniques": { "type": "string" } + }, + "required": [ + "name" ], + "allOf": [{ "$ref": "#/definitions/stats"}], + "additionalProperties": false }, "definitions": { "stats": {