|
|
|
|
@ -31,6 +31,7 @@ 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); |
|
|
|
|
void addV3f(rapidjson::Writer<rapidjson::StringBuffer>& writer, float x, float y, float z); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// interface
|
|
|
|
|
@ -198,23 +199,58 @@ slSaveGridFile(hexgrid& hg)
|
|
|
|
|
if (utilConcatPath(full_path, g_data_dir, hg.map_file, max_len)) { |
|
|
|
|
LOG(INFO) << "saving grid file: " << full_path << "\n"; |
|
|
|
|
|
|
|
|
|
// assemble json from hexgrid
|
|
|
|
|
rapidjson::Document doc; |
|
|
|
|
// need to store grid properties: hex_size, world origin, world normal?, layout_mode?
|
|
|
|
|
// hex properties: hex space coordinates, world XPos/YPos, world hex vertices
|
|
|
|
|
|
|
|
|
|
// write document to buffer
|
|
|
|
|
rapidjson::StringBuffer sb; |
|
|
|
|
rapidjson::Writer<rapidjson::StringBuffer> writer(sb); |
|
|
|
|
doc.Accept(writer); |
|
|
|
|
|
|
|
|
|
// write buffer to file
|
|
|
|
|
if (utilWriteTextFile(full_path, sb.GetString())) { |
|
|
|
|
LOG(INFO) << "save successful\n"; |
|
|
|
|
return true; |
|
|
|
|
writer.StartObject(); |
|
|
|
|
|
|
|
|
|
writer.Key("hex_size"); writer.Uint(hg.hex_size); |
|
|
|
|
writer.Key("layout_mode"); |
|
|
|
|
writer.String((hg.layout_mode == LAYOUT_FLAT) ? "layout_flat" : "layout_pointy"); |
|
|
|
|
writer.Key("world_position"); |
|
|
|
|
addV3f(writer, hg.position.x, hg.position.y, hg.position.z); |
|
|
|
|
writer.Key("world_normal"); |
|
|
|
|
addV3f(writer, hg.normal.x, hg.normal.y, hg.normal.z); |
|
|
|
|
|
|
|
|
|
writer.Key("hexes"); |
|
|
|
|
writer.StartArray(); |
|
|
|
|
|
|
|
|
|
for (auto& it : hg.hex_map) { |
|
|
|
|
hex_info& hxi = it.second; |
|
|
|
|
writer.StartObject(); |
|
|
|
|
writer.Key("XPos"); writer.Double(hxi.XPos); |
|
|
|
|
writer.Key("YPos"); writer.Double(hxi.YPos); |
|
|
|
|
writer.Key("q"); writer.Int(hxi.hex.q); |
|
|
|
|
writer.Key("r"); writer.Int(hxi.hex.r); |
|
|
|
|
writer.Key("s"); writer.Int(hxi.hex.s); |
|
|
|
|
writer.Key("vertices"); |
|
|
|
|
writer.StartArray(); |
|
|
|
|
|
|
|
|
|
for (uint i = 0; i < hxi.vertices.size(); i++) { |
|
|
|
|
// TODO: hard coded z value for hex vertices
|
|
|
|
|
Point p = hxi.vertices[i]; |
|
|
|
|
addV3f(writer, p.x, p.y, 0.f); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
writer.EndArray(); |
|
|
|
|
writer.EndObject(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
LOG(ERROR) << "error saving file: " << full_path << "\n"; |
|
|
|
|
writer.EndArray(); |
|
|
|
|
|
|
|
|
|
writer.EndObject(); |
|
|
|
|
|
|
|
|
|
if (writer.IsComplete()) { |
|
|
|
|
if (utilWriteTextFile(full_path, sb.GetString())) { |
|
|
|
|
LOG(INFO) << "save successful\n"; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
LOG(ERROR) << "error saving file: " << full_path << "\n"; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
LOG(ERROR) << "malformed json\n"; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -296,3 +332,16 @@ parseVec4(const rapidjson::Value& node)
|
|
|
|
|
|
|
|
|
|
return v4; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
addV3f(rapidjson::Writer<rapidjson::StringBuffer>& writer, float x, float y, float z) |
|
|
|
|
{ |
|
|
|
|
writer.StartObject(); |
|
|
|
|
writer.Key("x"); |
|
|
|
|
writer.Double(x); |
|
|
|
|
writer.Key("y"); |
|
|
|
|
writer.Double(y); |
|
|
|
|
writer.Key("z"); |
|
|
|
|
writer.Double(z); |
|
|
|
|
writer.EndObject(); |
|
|
|
|
} |
|
|
|
|
|