From 9b1044058838790cc31f3ab2ff6b1a54dfa6e712 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Fri, 8 May 2026 10:58:28 -0700 Subject: [PATCH] feat(editor): add --gen-zone-readme auto-generated manifest Writes README.md to a zone (or to --out path) with a Markdown asset table covering textures (PNG bytes), meshes (verts/tris/ bones/batches/bytes), and audio (sample rate + duration). Reads zone.json for the friendly map name and biome. Saves the manual README maintenance every time content changes. --- tools/editor/main.cpp | 178 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) diff --git a/tools/editor/main.cpp b/tools/editor/main.cpp index e490167e..c2829800 100644 --- a/tools/editor/main.cpp +++ b/tools/editor/main.cpp @@ -9,6 +9,7 @@ #include "terrain_biomes.hpp" #include #include +#include #include #include "pipeline/wowee_model.hpp" #include "pipeline/wowee_building.hpp" @@ -635,6 +636,8 @@ static void printUsage(const char* argv0) { std::printf(" One-glance health digest for a zone: pack counts/bytes + audit pass/fail\n"); std::printf(" --info-project-summary [--json]\n"); std::printf(" One-glance status table per zone in a project (BOOTSTRAPPED/PARTIAL/EMPTY)\n"); + std::printf(" --gen-zone-readme [--out ]\n"); + std::printf(" Auto-generate README.md from zone.json + asset inventory (writes README.md by default)\n"); std::printf(" --validate-zone-pack [--json]\n"); std::printf(" Audit a zone's open-format asset pack: textures/meshes/audio counts + WOM validity\n"); std::printf(" --validate-project-packs \n"); @@ -1156,6 +1159,7 @@ int main(int argc, char* argv[]) { "--gen-project-starter-pack", "--gen-audio-tone", "--gen-audio-noise", "--gen-audio-sweep", "--gen-zone-audio-pack", "--info-zone-summary", "--info-project-summary", + "--gen-zone-readme", "--validate-zone-pack", "--validate-project-packs", "--info-spawn", "--diff-zone-spawns", "--list-items", "--info-item", "--set-item", "--export-zone-items-md", @@ -15265,6 +15269,180 @@ int main(int argc, char* argv[]) { r.name.c_str()); } return 0; + } else if (std::strcmp(argv[i], "--gen-zone-readme") == 0 && i + 1 < argc) { + // Auto-generate README.md for a zone. Writes a Markdown + // doc summarizing zone.json metadata and itemizing every + // texture, mesh, and audio asset (with vert/tri counts + // for meshes and duration for WAVs). Saves repeating the + // README maintenance every time content changes. + std::string zoneDir = argv[++i]; + std::string outPath; + for (int k = i + 1; k < argc; ++k) { + std::string flag = argv[k]; + if (flag == "--out" && k + 1 < argc) { + outPath = argv[++k]; + i = k; + } else if (flag.rfind("--", 0) == 0) { + std::fprintf(stderr, + "gen-zone-readme: unknown flag '%s'\n", flag.c_str()); + return 1; + } + } + namespace fs = std::filesystem; + if (!fs::exists(zoneDir + "/zone.json")) { + std::fprintf(stderr, + "gen-zone-readme: %s has no zone.json\n", zoneDir.c_str()); + return 1; + } + if (outPath.empty()) outPath = zoneDir + "/README.md"; + std::string mapName = fs::path(zoneDir).filename().string(); + std::string biome = "?"; + try { + std::ifstream zf(zoneDir + "/zone.json"); + if (zf) { + nlohmann::json zj; + zf >> zj; + if (zj.contains("mapName") && zj["mapName"].is_string()) + mapName = zj["mapName"].get(); + if (zj.contains("biome") && zj["biome"].is_string()) + biome = zj["biome"].get(); + } + } catch (...) {} + std::ofstream out(outPath); + if (!out) { + std::fprintf(stderr, + "gen-zone-readme: cannot open %s for write\n", + outPath.c_str()); + return 1; + } + out << "# " << mapName << "\n\n"; + out << "Auto-generated zone manifest. Re-run `--gen-zone-readme " + << zoneDir << "` after content changes.\n\n"; + out << "- **Biome**: " << biome << "\n"; + out << "- **Zone path**: `" << zoneDir << "`\n\n"; + // Textures + std::vector> texList; + fs::path texDir = fs::path(zoneDir) / "textures"; + std::error_code ec; + if (fs::exists(texDir)) { + for (const auto& e : fs::recursive_directory_iterator(texDir, ec)) { + if (!e.is_regular_file()) continue; + if (e.path().extension() != ".png") continue; + texList.push_back({fs::relative(e.path(), zoneDir).string(), + e.file_size()}); + } + } + std::sort(texList.begin(), texList.end()); + out << "## Textures (" << texList.size() << ")\n\n"; + if (texList.empty()) { + out << "_None._\n\n"; + } else { + out << "| File | Bytes |\n|------|-------|\n"; + for (const auto& [path, bytes] : texList) { + out << "| `" << path << "` | " << bytes << " |\n"; + } + out << "\n"; + } + // Meshes + struct MeshRow { + std::string path; + uint64_t bytes; size_t verts, tris, bones, batches; + }; + std::vector meshList; + fs::path meshDir = fs::path(zoneDir) / "meshes"; + if (fs::exists(meshDir)) { + for (const auto& e : fs::recursive_directory_iterator(meshDir, ec)) { + if (!e.is_regular_file()) continue; + if (e.path().extension() != ".wom") continue; + std::string base = e.path().string(); + base = base.substr(0, base.size() - 4); + auto wom = wowee::pipeline::WoweeModelLoader::load(base); + meshList.push_back({ + fs::relative(e.path(), zoneDir).string(), + e.file_size(), + wom.vertices.size(), + wom.indices.size() / 3, + wom.bones.size(), + wom.batches.size(), + }); + } + } + std::sort(meshList.begin(), meshList.end(), + [](const MeshRow& a, const MeshRow& b) { return a.path < b.path; }); + out << "## Meshes (" << meshList.size() << ")\n\n"; + if (meshList.empty()) { + out << "_None._\n\n"; + } else { + out << "| File | Verts | Tris | Bones | Batches | Bytes |\n"; + out << "|------|-------|------|-------|---------|-------|\n"; + for (const auto& r : meshList) { + out << "| `" << r.path << "` | " << r.verts << " | " + << r.tris << " | " << r.bones << " | " + << r.batches << " | " << r.bytes << " |\n"; + } + out << "\n"; + } + // Audio + struct AudRow { + std::string path; + uint64_t bytes; + uint32_t sampleRate; + float duration; + }; + std::vector audList; + fs::path audDir = fs::path(zoneDir) / "audio"; + if (fs::exists(audDir)) { + for (const auto& e : fs::recursive_directory_iterator(audDir, ec)) { + if (!e.is_regular_file()) continue; + if (e.path().extension() != ".wav") continue; + AudRow r{fs::relative(e.path(), zoneDir).string(), + e.file_size(), 0, 0.0f}; + FILE* f = std::fopen(e.path().c_str(), "rb"); + if (f) { + char hdr[44]; + if (std::fread(hdr, 1, 44, f) == 44 && + std::memcmp(hdr, "RIFF", 4) == 0 && + std::memcmp(hdr + 8, "WAVE", 4) == 0) { + uint16_t channels = 0, bps = 0; + uint32_t dataBytes = 0; + std::memcpy(&channels, hdr + 22, 2); + std::memcpy(&r.sampleRate, hdr + 24, 4); + std::memcpy(&bps, hdr + 34, 2); + std::memcpy(&dataBytes, hdr + 40, 4); + if (r.sampleRate > 0 && channels > 0 && bps > 0) { + uint32_t bytesPerSample = channels * (bps / 8); + if (bytesPerSample > 0) { + r.duration = static_cast(dataBytes) / + (r.sampleRate * bytesPerSample); + } + } + } + std::fclose(f); + } + audList.push_back(std::move(r)); + } + } + std::sort(audList.begin(), audList.end(), + [](const AudRow& a, const AudRow& b) { return a.path < b.path; }); + out << "## Audio (" << audList.size() << ")\n\n"; + if (audList.empty()) { + out << "_None._\n\n"; + } else { + out << "| File | Sample rate | Duration (s) | Bytes |\n"; + out << "|------|-------------|--------------|-------|\n"; + for (const auto& r : audList) { + out << "| `" << r.path << "` | " << r.sampleRate + << " Hz | " << std::fixed << std::setprecision(2) + << r.duration << " | " << r.bytes << " |\n"; + } + out << "\n"; + } + out.close(); + std::printf("Wrote %s\n", outPath.c_str()); + std::printf(" textures : %zu\n", texList.size()); + std::printf(" meshes : %zu\n", meshList.size()); + std::printf(" audio : %zu\n", audList.size()); + return 0; } else if (std::strcmp(argv[i], "--validate-zone-pack") == 0 && i + 1 < argc) { // Audit a zone's open-format asset pack. Reports counts // and total bytes per category (textures/, meshes/,