mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-08 18:13:52 +00:00
feat(editor): add --gen-zone-readme auto-generated manifest
Some checks are pending
Build / Build (arm64) (push) Waiting to run
Build / Build (x86-64) (push) Waiting to run
Build / Build (macOS arm64) (push) Waiting to run
Build / Build (windows-arm64) (push) Waiting to run
Build / Build (windows-x86-64) (push) Waiting to run
Security / CodeQL (C/C++) (push) Waiting to run
Security / Semgrep (push) Waiting to run
Security / Sanitizer Build (ASan/UBSan) (push) Waiting to run
Some checks are pending
Build / Build (arm64) (push) Waiting to run
Build / Build (x86-64) (push) Waiting to run
Build / Build (macOS arm64) (push) Waiting to run
Build / Build (windows-arm64) (push) Waiting to run
Build / Build (windows-x86-64) (push) Waiting to run
Security / CodeQL (C/C++) (push) Waiting to run
Security / Semgrep (push) Waiting to run
Security / Sanitizer Build (ASan/UBSan) (push) Waiting to run
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.
This commit is contained in:
parent
1ea5b5946d
commit
9b10440588
1 changed files with 178 additions and 0 deletions
|
|
@ -9,6 +9,7 @@
|
|||
#include "terrain_biomes.hpp"
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#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 <projectDir> [--json]\n");
|
||||
std::printf(" One-glance status table per zone in a project (BOOTSTRAPPED/PARTIAL/EMPTY)\n");
|
||||
std::printf(" --gen-zone-readme <zoneDir> [--out <path>]\n");
|
||||
std::printf(" Auto-generate README.md from zone.json + asset inventory (writes README.md by default)\n");
|
||||
std::printf(" --validate-zone-pack <zoneDir> [--json]\n");
|
||||
std::printf(" Audit a zone's open-format asset pack: textures/meshes/audio counts + WOM validity\n");
|
||||
std::printf(" --validate-project-packs <projectDir>\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<std::string>();
|
||||
if (zj.contains("biome") && zj["biome"].is_string())
|
||||
biome = zj["biome"].get<std::string>();
|
||||
}
|
||||
} 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<std::pair<std::string, uint64_t>> 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<MeshRow> 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<AudRow> 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<float>(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/,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue