Skip to content

Commit

Permalink
empty checks for house, rivers & roads (#45)
Browse files Browse the repository at this point in the history
* empty checks for house & rivers

* fix: check for not extracted road files
  • Loading branch information
TheWillard authored Mar 23, 2024
1 parent 33ead69 commit a980217
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/geojsons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ void writeHouses(rvff::cxx::OprwCxx& wrp, std::filesystem::path& basePathGeojson
mapFeature["properties"] = { { "color", color }, { "height", houseHeight }, { "position", housePos } };
house.push_back(mapFeature);
}
writeGZJson("house.geojson.gz", basePathGeojson, house);

if (!house.is_null() && house.is_array() && !house.empty()) {
writeGZJson("house.geojson.gz", basePathGeojson, house);
}
}

void writeObjects(rvff::cxx::OprwCxx& wrp, std::filesystem::path& basePathGeojson)
Expand Down Expand Up @@ -226,12 +229,19 @@ void writeRoads(

auto prefix = roads_pbo->get_prefix();

bool noRoadFilesExtracted = true;
for (auto& entry : roads_pbo->get_pbo().entries) {
if (boost::istarts_with((((fs::path)static_cast<std::string>(prefix)) / static_cast<std::string>(entry.filename)).string(), roadsPathDir)) {
roads_pbo->extract_single_file(static_cast<std::string>(entry.filename), basePathGeojsonTemp.string(), false);
noRoadFilesExtracted = false;
}
}

if (noRoadFilesExtracted) {
PLOG_ERROR << "Couldn't find or extract any road files. No roads will be exported!";
return;
}

auto gdalPath = getDllPath();
#ifdef _WIN32
// get appdata path
Expand Down Expand Up @@ -811,7 +821,9 @@ void writeRiver(rvff::cxx::OprwCxx& wrp, std::filesystem::path& basePathGeojson)
rivers.push_back(river);
}

writeGZJson("river.geojson.gz", basePathGeojson, rivers);
if (!rivers.is_null() && rivers.is_array() && !rivers.empty()) {
writeGZJson("river.geojson.gz", basePathGeojson, rivers);
}
}

void writeMounts(rvff::cxx::OprwCxx& wrp, fs::path& basePathGeojson) {
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ void extractMap(const std::string &worldName, const std::string &worldPath, std:
startMsg << "]";

prettyDiagLog(startMsg.str());
PLOG_INFO << startMsg.str();

if (!fs::exists(basePath))
{
Expand Down

0 comments on commit a980217

Please sign in to comment.