mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-08 01:53:52 +00:00
feat(editor): add --export-zone-items-md markdown items report
Renders items.json as a Markdown report grouped by quality, best first (Artifact → Legendary → Epic → Rare → Uncommon → Common → Poor). Header shows total count + zone name; quality breakdown table summarizes the distribution; per-quality sections list ID / name / itemLevel / displayId / stack with right-aligned numeric columns. Drops cleanly into design docs, PR descriptions, and GitHub Pages — one rendered page communicates the loot landscape better than scrolling through JSON. Used find()/iterators instead of operator[] in the per-quality loops so the bucket map doesn't grow phantom empty entries (caught by the "qualities (used)" line reporting 7 instead of the actual 3 in the first test run). Verified: 3-item zone (1 common / 1 uncommon / 1 legendary) → ITEMS.md sections appear in best-first order, quality count line reports 3 not 7. Brings command count to 210.
This commit is contained in:
parent
98c9b3c624
commit
90cd64c88d
1 changed files with 92 additions and 1 deletions
|
|
@ -540,6 +540,8 @@ static void printUsage(const char* argv0) {
|
|||
std::printf(" Append one item entry to <zoneDir>/items.json (auto-creates the file)\n");
|
||||
std::printf(" --list-items <zoneDir> [--json]\n");
|
||||
std::printf(" Print every item in <zoneDir>/items.json with quality colors and key fields\n");
|
||||
std::printf(" --export-zone-items-md <zoneDir> [out.md]\n");
|
||||
std::printf(" Render items.json as a Markdown table grouped by quality (rare/epic/etc.)\n");
|
||||
std::printf(" --info-item <zoneDir> <id|index> [--json]\n");
|
||||
std::printf(" Detail view for one item (lookup by id, or by index if prefixed with '#')\n");
|
||||
std::printf(" --set-item <zoneDir> <id|#index> [--name S] [--quality N] [--displayId N] [--itemLevel N] [--stackable N]\n");
|
||||
|
|
@ -962,7 +964,7 @@ int main(int argc, char* argv[]) {
|
|||
"--check-project-content", "--check-project-refs",
|
||||
"--export-zone-deps-md", "--export-zone-spawn-png",
|
||||
"--add-creature", "--add-object", "--add-quest", "--add-item",
|
||||
"--list-items", "--info-item", "--set-item",
|
||||
"--list-items", "--info-item", "--set-item", "--export-zone-items-md",
|
||||
"--add-quest-objective", "--add-quest-reward-item", "--set-quest-reward",
|
||||
"--remove-quest-objective", "--clone-quest", "--clone-creature",
|
||||
"--clone-item", "--validate-items", "--info-project-items",
|
||||
|
|
@ -13166,6 +13168,95 @@ int main(int argc, char* argv[]) {
|
|||
std::printf(" %s\n", c.c_str());
|
||||
}
|
||||
return 0;
|
||||
} else if (std::strcmp(argv[i], "--export-zone-items-md") == 0 && i + 1 < argc) {
|
||||
// Render items.json as a Markdown table grouped by
|
||||
// quality. Useful for design docs, PR descriptions, and
|
||||
// GitHub Pages — one rendered page communicates the loot
|
||||
// landscape better than scrolling through JSON.
|
||||
std::string zoneDir = argv[++i];
|
||||
std::string outPath;
|
||||
if (i + 1 < argc && argv[i + 1][0] != '-') outPath = argv[++i];
|
||||
namespace fs = std::filesystem;
|
||||
std::string path = zoneDir + "/items.json";
|
||||
if (!fs::exists(path)) {
|
||||
std::fprintf(stderr,
|
||||
"export-zone-items-md: %s has no items.json\n",
|
||||
zoneDir.c_str());
|
||||
return 1;
|
||||
}
|
||||
nlohmann::json doc;
|
||||
try {
|
||||
std::ifstream in(path);
|
||||
in >> doc;
|
||||
} catch (...) {
|
||||
std::fprintf(stderr,
|
||||
"export-zone-items-md: %s is not valid JSON\n",
|
||||
path.c_str());
|
||||
return 1;
|
||||
}
|
||||
if (!doc.contains("items") || !doc["items"].is_array()) {
|
||||
std::fprintf(stderr,
|
||||
"export-zone-items-md: %s has no 'items' array\n",
|
||||
path.c_str());
|
||||
return 1;
|
||||
}
|
||||
if (outPath.empty()) outPath = zoneDir + "/ITEMS.md";
|
||||
const auto& items = doc["items"];
|
||||
static const char* qualityNames[] = {
|
||||
"Poor", "Common", "Uncommon", "Rare", "Epic",
|
||||
"Legendary", "Artifact"
|
||||
};
|
||||
// Bucket by quality so the report reads top-down from
|
||||
// best loot to filler. Reverse iteration over the buckets.
|
||||
std::map<int, std::vector<size_t>> byQuality;
|
||||
for (size_t k = 0; k < items.size(); ++k) {
|
||||
uint32_t q = items[k].value("quality", 1u);
|
||||
if (q > 6) q = 0;
|
||||
byQuality[q].push_back(k);
|
||||
}
|
||||
std::ofstream out(outPath);
|
||||
if (!out) {
|
||||
std::fprintf(stderr,
|
||||
"export-zone-items-md: cannot write %s\n", outPath.c_str());
|
||||
return 1;
|
||||
}
|
||||
std::string zoneName = fs::path(zoneDir).filename().string();
|
||||
out << "# Items: " << zoneName << "\n\n";
|
||||
out << "Source: `" << path << "` \n";
|
||||
out << "Total items: **" << items.size() << "**\n\n";
|
||||
// Quality histogram up top.
|
||||
out << "## Quality breakdown\n\n";
|
||||
out << "| Quality | Count |\n|---|---:|\n";
|
||||
for (int q = 6; q >= 0; --q) {
|
||||
auto it = byQuality.find(q);
|
||||
if (it == byQuality.end()) continue;
|
||||
out << "| " << qualityNames[q] << " | "
|
||||
<< it->second.size() << " |\n";
|
||||
}
|
||||
out << "\n";
|
||||
// Per-quality sections, best first.
|
||||
for (int q = 6; q >= 0; --q) {
|
||||
auto qit = byQuality.find(q);
|
||||
if (qit == byQuality.end()) continue;
|
||||
out << "## " << qualityNames[q] << "\n\n";
|
||||
out << "| ID | Name | iLvl | Display | Stack |\n";
|
||||
out << "|---:|---|---:|---:|---:|\n";
|
||||
for (size_t k : qit->second) {
|
||||
const auto& it = items[k];
|
||||
std::string name = it.value("name", std::string("(unnamed)"));
|
||||
out << "| " << it.value("id", 0u) << " | "
|
||||
<< name << " | "
|
||||
<< it.value("itemLevel", 1u) << " | "
|
||||
<< it.value("displayId", 0u) << " | "
|
||||
<< it.value("stackable", 1u) << " |\n";
|
||||
}
|
||||
out << "\n";
|
||||
}
|
||||
out.close();
|
||||
std::printf("Wrote %s\n", outPath.c_str());
|
||||
std::printf(" total items : %zu\n", items.size());
|
||||
std::printf(" qualities : %zu (used)\n", byQuality.size());
|
||||
return 0;
|
||||
} else if (std::strcmp(argv[i], "--remove-item") == 0 && i + 2 < argc) {
|
||||
// Remove the item at given 0-based index from <zoneDir>/
|
||||
// items.json. Mirrors --remove-creature/--remove-object/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue