diff --git a/tools/editor/main.cpp b/tools/editor/main.cpp index 9c9bda7e..8c1133a0 100644 --- a/tools/editor/main.cpp +++ b/tools/editor/main.cpp @@ -540,6 +540,8 @@ static void printUsage(const char* argv0) { std::printf(" Append one item entry to /items.json (auto-creates the file)\n"); std::printf(" --list-items [--json]\n"); std::printf(" Print every item in /items.json with quality colors and key fields\n"); + std::printf(" --export-zone-items-md [out.md]\n"); + std::printf(" Render items.json as a Markdown table grouped by quality (rare/epic/etc.)\n"); std::printf(" --info-item [--json]\n"); std::printf(" Detail view for one item (lookup by id, or by index if prefixed with '#')\n"); std::printf(" --set-item [--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> 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 / // items.json. Mirrors --remove-creature/--remove-object/