|
|
|
|
@ -30,8 +30,8 @@ bool loadTextFile(char*& output, const char* data_dir, const char* file_name);
|
|
|
|
|
bool parseFile(rapidjson::Document* doc, const char* file_contents, const char* file_name); |
|
|
|
|
glm::vec3 parseVec3(const rapidjson::Value& node); |
|
|
|
|
glm::vec4 parseVec4(const rapidjson::Value& node); |
|
|
|
|
bool validateScene(rapidjson::Document* schema_doc, rapidjson::Document* scene_doc, |
|
|
|
|
const char* scene_file); |
|
|
|
|
bool validateJSON(rapidjson::Document* schema_doc, rapidjson::Document* doc, |
|
|
|
|
const char* json_file); |
|
|
|
|
void addV3f(rapidjson::Writer<rapidjson::StringBuffer>& writer, float x, float y, float z); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -58,7 +58,7 @@ slLoadFile(const char* data_dir, const char* scene_file, const char* schema_file
|
|
|
|
|
utilSafeFree(scene_contents); |
|
|
|
|
utilSafeFree(schema_contents); |
|
|
|
|
|
|
|
|
|
if (!retDoc || !retSchema || !validateScene(&schema_doc, sd->doc, scene_file)) { |
|
|
|
|
if (!retDoc || !retSchema || !validateJSON(&schema_doc, sd->doc, scene_file)) { |
|
|
|
|
slFreeSceneDoc(sd); |
|
|
|
|
return nullptr; |
|
|
|
|
} |
|
|
|
|
@ -163,11 +163,11 @@ slParseHexGrid(slSceneDoc* sd, hexgrid& hg, util_image& palette_image)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool |
|
|
|
|
slParseGridHashMap(hexgrid& hg, const char* data_dir) |
|
|
|
|
slParseGridHashMap(hexgrid& hg, const char* data_dir, const char* hexmap_schema_file) |
|
|
|
|
{ |
|
|
|
|
LOG(DEBUG) << "loading map_file: " << hg.map_file << "\n"; |
|
|
|
|
char* contents; |
|
|
|
|
|
|
|
|
|
char* contents; |
|
|
|
|
if (!loadTextFile(contents, data_dir, hg.map_file)) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
@ -178,11 +178,19 @@ slParseGridHashMap(hexgrid& hg, const char* data_dir)
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO: still need a schema for the hashmap
|
|
|
|
|
rapidjson::Document doc; |
|
|
|
|
bool ret = false; |
|
|
|
|
rapidjson::Document doc, schema_doc; |
|
|
|
|
bool retDoc, retSchema = false; |
|
|
|
|
char* schema_contents; |
|
|
|
|
|
|
|
|
|
if (parseFile(&doc, contents, hg.map_file)) { |
|
|
|
|
retDoc = parseFile(&doc, contents, hg.map_file); |
|
|
|
|
|
|
|
|
|
if (loadTextFile(schema_contents, data_dir, hexmap_schema_file)) |
|
|
|
|
retSchema = parseFile(&schema_doc, schema_contents, hexmap_schema_file); |
|
|
|
|
|
|
|
|
|
utilSafeFree(contents); |
|
|
|
|
utilSafeFree(schema_contents); |
|
|
|
|
|
|
|
|
|
if (retDoc && retSchema && validateJSON(&schema_doc, &doc, hg.map_file)) { |
|
|
|
|
hg.hex_size = doc["hex_size"].GetInt(); |
|
|
|
|
std::string orientation_str = doc["layout_mode"].GetString(); |
|
|
|
|
hg.layout_mode = (orientation_str == "layout_flat") ? LAYOUT_FLAT : LAYOUT_POINTY; |
|
|
|
|
@ -214,11 +222,10 @@ slParseGridHashMap(hexgrid& hg, const char* data_dir)
|
|
|
|
|
hg.hex_map.insert({hxi.hex, hxi}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ret = true; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
utilSafeFree(contents); |
|
|
|
|
return ret; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool |
|
|
|
|
@ -362,13 +369,13 @@ parseFile(rapidjson::Document* doc, const char* file_contents, const char* file_
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool |
|
|
|
|
validateScene(rapidjson::Document* schema_doc, rapidjson::Document* scene_doc, const char* scene_file) |
|
|
|
|
validateJSON(rapidjson::Document* schema_doc, rapidjson::Document* doc, const char* json_file) |
|
|
|
|
{ |
|
|
|
|
rapidjson::SchemaDocument schema(*schema_doc); |
|
|
|
|
rapidjson::SchemaValidator validator(schema); |
|
|
|
|
|
|
|
|
|
if (!scene_doc->Accept(validator)) { |
|
|
|
|
LOG(ERROR) << "Error validating scene file: " << scene_file << "\n"; |
|
|
|
|
if (!doc->Accept(validator)) { |
|
|
|
|
LOG(ERROR) << "Error validating scene file: " << json_file << "\n"; |
|
|
|
|
rapidjson::StringBuffer sb; |
|
|
|
|
validator.GetInvalidSchemaPointer().StringifyUriFragment(sb); |
|
|
|
|
LOG(ERROR) << "Invalid schema: " << sb.GetString() << "\n"; |
|
|
|
|
@ -379,7 +386,7 @@ validateScene(rapidjson::Document* schema_doc, rapidjson::Document* scene_doc, c
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
LOG(INFO) << "scene file: " << scene_file << " passed schema validation\n"; |
|
|
|
|
LOG(INFO) << "JSON file: " << json_file << " passed schema validation\n"; |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|