mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-04-20 11:35:07 +02:00
Generate info file
This commit is contained in:
parent
89baed4ed5
commit
fd4ce45885
1 changed files with 48 additions and 0 deletions
|
@ -153,6 +153,52 @@ static bool checkFilename(const char *name, int *x, int *z) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void writeInfo(const std::string &filename, const std::set<std::pair<int, int>> ®ions, int minX, int maxX, int minZ, int maxZ) {
|
||||||
|
const std::string tmpfile = filename + ".tmp";
|
||||||
|
|
||||||
|
FILE *f = fopen(tmpfile.c_str(), "w");
|
||||||
|
if (!f) {
|
||||||
|
std::fprintf(stderr, "Unable to open %s: %s\n", tmpfile.c_str(), std::strerror(errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(f, "{\n");
|
||||||
|
fprintf(f, " \"info\" : {\n");
|
||||||
|
fprintf(f, " \"minX\" : %i,\n", minX);
|
||||||
|
fprintf(f, " \"maxX\" : %i,\n", maxX);
|
||||||
|
fprintf(f, " \"minZ\" : %i,\n", minZ);
|
||||||
|
fprintf(f, " \"maxZ\" : %i\n", maxZ);
|
||||||
|
fprintf(f, " },\n");
|
||||||
|
fprintf(f, " \"regions\" : [\n");
|
||||||
|
|
||||||
|
for (int z = minZ; z <= maxZ; z++) {
|
||||||
|
fprintf(f, " [");
|
||||||
|
|
||||||
|
for (int x = minX; x <= maxX; x++) {
|
||||||
|
fprintf(f, "%s", regions.count(std::make_pair(x, z)) ? "true" : "false");
|
||||||
|
|
||||||
|
if (x < maxX)
|
||||||
|
fprintf(f, ", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (z < maxZ)
|
||||||
|
fprintf(f, "],\n");
|
||||||
|
else
|
||||||
|
fprintf(f, "]\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(f, " ]\n");
|
||||||
|
fprintf(f, "}\n");
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
if (std::rename(tmpfile.c_str(), filename.c_str()) < 0) {
|
||||||
|
std::fprintf(stderr, "Unable to save %s: %s\n", filename.c_str(), std::strerror(errno));
|
||||||
|
unlink(tmpfile.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
std::fprintf(stderr, "Usage: %s <data directory> <output directory>\n", argv[0]);
|
std::fprintf(stderr, "Usage: %s <data directory> <output directory>\n", argv[0]);
|
||||||
|
@ -192,5 +238,7 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
|
writeInfo(outputdir + "/info.json", regions, minX, maxX, minZ, maxZ);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue