diff --git a/cl_dll/hud_inventory.cpp b/cl_dll/hud_inventory.cpp index bd2d58c89..249b479a2 100644 --- a/cl_dll/hud_inventory.cpp +++ b/cl_dll/hud_inventory.cpp @@ -13,20 +13,9 @@ using namespace rapidjson; const char hudInventorySchema[] = R"( { "type": "object", - "definitions": { - "alpha": { - "type": "integer", - "minimum": 0, - "maximum": 255 - }, - "color": { - "type": ["string", "null"], - "pattern": "^([0-9]{1,3}[ ]+[0-9]{1,3}[ ]+[0-9]{1,3})|((#|0x)[0-9a-fA-F]{6})$" - } - }, "properties": { - "default_sprite_alpha": "#/definitions/alpha", - "text_alpha": "#/definitions/alpha", + "default_sprite_alpha": "definitions.json#/alpha", + "text_alpha": "definitions.json#/alpha", "items": { "additionalProperties": { "type": "object", @@ -35,10 +24,10 @@ const char hudInventorySchema[] = R"( "type": ["string", "null"] }, "color": { - "$ref": "#/definitions/color" + "$ref": "definitions.json#/color" }, "alpha": { - "$ref": "#/definitions/alpha" + "$ref": "definitions.json#/alpha" }, "position": { "type": "string", @@ -102,6 +91,14 @@ bool InventoryHudSpec::ReadFromFile(const char *fileName) } } auto colorIt = value.FindMember("color"); + + Color color; + if (UpdatePropertyFromJson(color, value, "color")) + { + item.packedColor = PackRGB(color.r, color.g, color.b); + item.colorDefined = true; + } + if (colorIt != value.MemberEnd()) { if (colorIt->value.IsString()) diff --git a/dlls/soundscripts.cpp b/dlls/soundscripts.cpp index fc2ce31af..9fda6951a 100644 --- a/dlls/soundscripts.cpp +++ b/dlls/soundscripts.cpp @@ -14,32 +14,6 @@ using namespace rapidjson; const char* soundScriptsSchema = R"( { "definitions": { - "range": { - "type": ["string", "object", "number"], - "minimum": 0.0, - "maximum": 1.0, - "pattern": "[0-9]+(\\.[0-9]+)?(,[0-9]+(\\.[0-9]+)?)?", - "properties": { - "min": { - "type": "number" - }, - "max": { - "type": "number" - } - } - }, - "range_int": { - "type": ["string", "object", "integer"], - "pattern": "[0-9]+(,[0-9]+)?", - "properties": { - "min": { - "type": "integer" - }, - "max": { - "type": "integer" - } - } - }, "soundscript": { "type": "object", "properties": { @@ -55,7 +29,7 @@ const char* soundScriptsSchema = R"( "pattern": "^auto|weapon|voice|item|body|static$" }, "volume": { - "$ref": "#/definitions/range", + "$ref": "definitions.json#/range", }, "attenuation": { "type": ["number", "string"], @@ -63,7 +37,7 @@ const char* soundScriptsSchema = R"( "pattern": "^norm|idle|static|none$" }, "pitch": { - "$ref": "#/definitions/range_int" + "$ref": "definitions.json#/range_int" } } } diff --git a/dlls/warpball.cpp b/dlls/warpball.cpp index 0fcba7dad..1eff414d3 100644 --- a/dlls/warpball.cpp +++ b/dlls/warpball.cpp @@ -68,63 +68,13 @@ const char warpballCatalogSchema[] = R"( "maximum": 1.0 }, "pitch": { - "$ref": "#/definitions/range" + "$ref": "definitions.json#/range_int" }, "attenuation": { "type": "number", "minimum": 0 } } - }, - "alpha": { - "type": "integer", - "minimum": 0, - "maximum": 255 - }, - "color": { - "type": ["string", "array"], - "pattern": "^([0-9]{1,3}[ ]+[0-9]{1,3}[ ]+[0-9]{1,3})|((#|0x)[0-9a-fA-F]{6})$", - "items": { - "type": "integer", - "minimum": 0, - "maximum": 255 - }, - "minItems": 3, - "maxItems": 3 - }, - "range": { - "type": ["string", "object", "number", "array"], - "pattern": "[0-9]+(\\.[0-9]+)?(,[0-9]+(\\.[0-9]+)?)?", - "properties": { - "min": { - "type": "number" - }, - "max": { - "type": "number" - } - }, - "items": { - "type": "number" - }, - "minItems": 2, - "maxItems": 2 - }, - "range_int": { - "type": ["string", "object", "integer", "array"], - "pattern": "[0-9]+(,[0-9]+)?", - "properties": { - "min": { - "type": "integer" - }, - "max": { - "type": "integer" - } - }, - "items": { - "type": "integer", - }, - "minItems": 2, - "maxItems": 2 } }, "properties": { @@ -165,10 +115,10 @@ const char warpballCatalogSchema[] = R"( "$ref": "#/definitions/sprite_name" }, "color": { - "$ref": "#/definitions/color" + "$ref": "definitions.json#/color" }, "alpha": { - "$ref": "#/definitions/alpha" + "$ref": "definitions.json#/alpha" }, "width": { "type": "integer", @@ -178,7 +128,7 @@ const char warpballCatalogSchema[] = R"( "type": "integer" }, "life": { - "$ref": "#/definitions/range" + "$ref": "definitions.json#/range" } } }, @@ -187,13 +137,13 @@ const char warpballCatalogSchema[] = R"( "minumum": 1 }, "beam_count": { - "$ref": "#/definitions/range_int" + "$ref": "definitions.json#/range_int" }, "light": { "type": ["object", "null"], "properties": { "color": { - "$ref": "#/definitions/color" + "$ref": "definitions.json#/color" }, "radius": { "type": "integer" diff --git a/game_shared/json_utils.cpp b/game_shared/json_utils.cpp index 19f9c5eab..f690c8f02 100644 --- a/game_shared/json_utils.cpp +++ b/game_shared/json_utils.cpp @@ -20,6 +20,60 @@ using namespace rapidjson; +constexpr const char definitions[] = R"( +{ + "alpha": { + "type": "integer", + "minimum": 0, + "maximum": 255 + }, + "color": { + "type": ["string", "array", "null"], + "pattern": "^([0-9]{1,3}[ ]+[0-9]{1,3}[ ]+[0-9]{1,3})|((#|0x)[0-9a-fA-F]{6})$", + "items": { + "type": "integer", + "minimum": 0, + "maximum": 255 + }, + "minItems": 3, + "maxItems": 3 + }, + "range": { + "type": ["string", "object", "number", "array"], + "pattern": "[0-9]+(\\.[0-9]+)?(,[0-9]+(\\.[0-9]+)?)?", + "properties": { + "min": { + "type": "number" + }, + "max": { + "type": "number" + } + }, + "items": { + "type": "number" + }, + "minItems": 2, + "maxItems": 2 + }, + "range_int": { + "type": ["string", "object", "integer", "array"], + "pattern": "[0-9]+(,[0-9]+)?", + "properties": { + "min": { + "type": "integer" + }, + "max": { + "type": "integer" + } + }, + "items": { + "type": "integer", + }, + "minItems": 2, + "maxItems": 2 + } +})"; + static void CalculateLineAndColumnFromOffset(const char* pMemFile, size_t offset, size_t& line, size_t& column) { const char* cur = pMemFile; @@ -52,19 +106,41 @@ static void ReportParseErrors(const char* fileName, ParseResult& parseResult, co JSON_ERROR("%s: JSON parse error: %s (Line %lu, column %lu)\n", fileName, GetParseError_En(parseResult.Code()), errorLine, errorColumn); } +class DefinitionsProvider : public IRemoteSchemaDocumentProvider +{ +public: + DefinitionsProvider(const SchemaDocument* schema): _schema(schema) {} + const SchemaDocument* GetRemoteDocument(const char* uri, SizeType length) { + return _schema; + } +private: + const SchemaDocument* _schema; +}; + bool ReadJsonDocumentWithSchema(Document &document, const char *pMemFile, int fileSize, const char *schemaText, const char* fileName) { if (!fileName) fileName = ""; + Document definitionsSchemaDocument; + definitionsSchemaDocument.Parse(definitions); + ParseResult parseResult = definitionsSchemaDocument; + if (!parseResult) { + ReportParseErrors(fileName, parseResult, pMemFile); + return false; + } + SchemaDocument definitionsSchema(definitionsSchemaDocument); + Document schemaDocument; schemaDocument.Parse(schemaText); - ParseResult parseResult = schemaDocument; + parseResult = schemaDocument; if (!parseResult) { ReportParseErrors(fileName, parseResult, pMemFile); return false; } - SchemaDocument schema(schemaDocument); + + DefinitionsProvider provider(&definitionsSchema); + SchemaDocument schema(schemaDocument, 0, 0, &provider); document.Parse(pMemFile, fileSize); parseResult = document;