feat(editor): add WCTR JSON round-trip (--export/--import-wctr-json)

Closes the editing loop on the currency-type catalog: dump a
.wctr to JSON, hand-edit currencyKind / cap values / categoryId
/ isAccountWide / iconPath (e.g. raise Conquest Points weekly
cap from 1650 to 2200, retag a server-custom currency from
Misc to FactionToken kind, mark Honor Points as account-wide
for a casual server), re-import to a byte-identical binary.

The exporter emits both currencyKind (int 0..5) and the human-
readable currencyKindName ("pvp-honor" / "pve-raid" /
"faction-token" / "event-token" / "crafting" / "misc"); the
importer accepts either form. isAccountWide round-trips as a
JSON bool but accepts int as well so machine-generated sidecars
work too.

Verified byte-identical round-trip on all three presets
(pvp / pve / faction). CLI flag count 970 -> 972.
This commit is contained in:
Kelsi 2026-05-09 22:33:12 -07:00
parent b8bd80cb35
commit 4426f26f79
3 changed files with 161 additions and 0 deletions

View file

@ -242,6 +242,7 @@ const char* const kArgRequired[] = {
"--export-wtle-json", "--import-wtle-json",
"--gen-ctr", "--gen-ctr-pve", "--gen-ctr-faction",
"--info-wctr", "--validate-wctr",
"--export-wctr-json", "--import-wctr-json",
"--gen-weather-temperate", "--gen-weather-arctic",
"--gen-weather-desert", "--gen-weather-stormy",
"--gen-zone-atmosphere",

View file

@ -5,6 +5,7 @@
#include "pipeline/wowee_currency_types.hpp"
#include <nlohmann/json.hpp>
#include <cctype>
#include <cstdint>
#include <cstdio>
#include <cstring>
@ -126,6 +127,155 @@ int handleInfo(int& i, int argc, char** argv) {
return 0;
}
int handleExportJson(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string outPath;
if (parseOptArg(i, argc, argv)) outPath = argv[++i];
base = stripWctrExt(base);
if (!wowee::pipeline::WoweeCurrencyTypeLoader::exists(base)) {
std::fprintf(stderr,
"export-wctr-json: WCTR not found: %s.wctr\n",
base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeCurrencyTypeLoader::load(base);
if (outPath.empty()) outPath = base + ".wctr.json";
nlohmann::json j;
j["catalog"] = c.name;
nlohmann::json arr = nlohmann::json::array();
for (const auto& e : c.entries) {
nlohmann::json je;
je["currencyId"] = e.currencyId;
je["name"] = e.name;
je["description"] = e.description;
je["itemId"] = e.itemId;
je["maxQuantity"] = e.maxQuantity;
je["maxQuantityWeekly"] = e.maxQuantityWeekly;
je["categoryId"] = e.categoryId;
je["currencyKind"] = e.currencyKind;
je["currencyKindName"] =
wowee::pipeline::WoweeCurrencyType::currencyKindName(e.currencyKind);
je["isAccountWide"] = e.isAccountWide != 0;
je["iconPath"] = e.iconPath;
je["iconColorRGBA"] = e.iconColorRGBA;
arr.push_back(je);
}
j["entries"] = arr;
std::ofstream os(outPath);
if (!os) {
std::fprintf(stderr,
"export-wctr-json: failed to open %s for write\n",
outPath.c_str());
return 1;
}
os << j.dump(2) << "\n";
std::printf("Wrote %s\n", outPath.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" currencies : %zu\n", c.entries.size());
return 0;
}
uint8_t parseCurrencyKindToken(const nlohmann::json& jv,
uint8_t fallback) {
if (jv.is_number_integer() || jv.is_number_unsigned()) {
int v = jv.get<int>();
if (v < 0 || v > wowee::pipeline::WoweeCurrencyType::Misc)
return fallback;
return static_cast<uint8_t>(v);
}
if (jv.is_string()) {
std::string s = jv.get<std::string>();
for (auto& ch : s) ch = static_cast<char>(std::tolower(ch));
if (s == "pvp-honor" ||
s == "pvphonor") return wowee::pipeline::WoweeCurrencyType::PvPHonor;
if (s == "pve-raid" ||
s == "pveraid") return wowee::pipeline::WoweeCurrencyType::PvERaid;
if (s == "faction-token" ||
s == "factiontoken") return wowee::pipeline::WoweeCurrencyType::FactionToken;
if (s == "event-token" ||
s == "eventtoken") return wowee::pipeline::WoweeCurrencyType::EventToken;
if (s == "crafting") return wowee::pipeline::WoweeCurrencyType::Crafting;
if (s == "misc") return wowee::pipeline::WoweeCurrencyType::Misc;
}
return fallback;
}
int handleImportJson(int& i, int argc, char** argv) {
std::string jsonPath = argv[++i];
std::string outBase;
if (parseOptArg(i, argc, argv)) outBase = argv[++i];
std::ifstream is(jsonPath);
if (!is) {
std::fprintf(stderr,
"import-wctr-json: failed to open %s\n", jsonPath.c_str());
return 1;
}
nlohmann::json j;
try {
is >> j;
} catch (const std::exception& ex) {
std::fprintf(stderr,
"import-wctr-json: parse error in %s: %s\n",
jsonPath.c_str(), ex.what());
return 1;
}
wowee::pipeline::WoweeCurrencyType c;
if (j.contains("catalog") && j["catalog"].is_string())
c.name = j["catalog"].get<std::string>();
if (j.contains("entries") && j["entries"].is_array()) {
for (const auto& je : j["entries"]) {
wowee::pipeline::WoweeCurrencyType::Entry e;
if (je.contains("currencyId")) e.currencyId = je["currencyId"].get<uint32_t>();
if (je.contains("name")) e.name = je["name"].get<std::string>();
if (je.contains("description")) e.description = je["description"].get<std::string>();
if (je.contains("itemId")) e.itemId = je["itemId"].get<uint32_t>();
if (je.contains("maxQuantity")) e.maxQuantity = je["maxQuantity"].get<uint32_t>();
if (je.contains("maxQuantityWeekly")) e.maxQuantityWeekly = je["maxQuantityWeekly"].get<uint32_t>();
if (je.contains("categoryId")) e.categoryId = je["categoryId"].get<uint32_t>();
uint8_t kind = wowee::pipeline::WoweeCurrencyType::PvPHonor;
if (je.contains("currencyKind"))
kind = parseCurrencyKindToken(je["currencyKind"], kind);
else if (je.contains("currencyKindName"))
kind = parseCurrencyKindToken(je["currencyKindName"], kind);
e.currencyKind = kind;
if (je.contains("isAccountWide")) {
if (je["isAccountWide"].is_boolean())
e.isAccountWide = je["isAccountWide"].get<bool>() ? 1 : 0;
else
e.isAccountWide = je["isAccountWide"].get<uint8_t>() ? 1 : 0;
}
if (je.contains("iconPath")) e.iconPath = je["iconPath"].get<std::string>();
if (je.contains("iconColorRGBA")) e.iconColorRGBA = je["iconColorRGBA"].get<uint32_t>();
c.entries.push_back(e);
}
}
if (outBase.empty()) {
outBase = jsonPath;
const std::string suffix1 = ".wctr.json";
const std::string suffix2 = ".json";
if (outBase.size() >= suffix1.size() &&
outBase.compare(outBase.size() - suffix1.size(),
suffix1.size(), suffix1) == 0) {
outBase.resize(outBase.size() - suffix1.size());
} else if (outBase.size() >= suffix2.size() &&
outBase.compare(outBase.size() - suffix2.size(),
suffix2.size(), suffix2) == 0) {
outBase.resize(outBase.size() - suffix2.size());
}
}
outBase = stripWctrExt(outBase);
if (!wowee::pipeline::WoweeCurrencyTypeLoader::save(c, outBase)) {
std::fprintf(stderr,
"import-wctr-json: failed to save %s.wctr\n",
outBase.c_str());
return 1;
}
std::printf("Wrote %s.wctr\n", outBase.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" currencies : %zu\n", c.entries.size());
return 0;
}
int handleValidate(int& i, int argc, char** argv) {
std::string base = argv[++i];
bool jsonOut = consumeJsonFlag(i, argc, argv);
@ -241,6 +391,12 @@ bool handleCurrencyTypesCatalog(int& i, int argc, char** argv,
if (std::strcmp(argv[i], "--validate-wctr") == 0 && i + 1 < argc) {
outRc = handleValidate(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--export-wctr-json") == 0 && i + 1 < argc) {
outRc = handleExportJson(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--import-wctr-json") == 0 && i + 1 < argc) {
outRc = handleImportJson(i, argc, argv); return true;
}
return false;
}

View file

@ -1857,6 +1857,10 @@ void printUsage(const char* argv0) {
std::printf(" Print WCTR entries (id / kind / itemId / max+weekly caps / categoryId / accountWide / name)\n");
std::printf(" --validate-wctr <wctr-base> [--json]\n");
std::printf(" Static checks: id+name required, currencyKind 0..5, no duplicate ids; warns on weekly>absolute, FactionToken+cat=0, no caps+no item+no icon\n");
std::printf(" --export-wctr-json <wctr-base> [out.json]\n");
std::printf(" Export binary .wctr to a human-editable JSON sidecar (defaults to <base>.wctr.json)\n");
std::printf(" --import-wctr-json <json-path> [out-base]\n");
std::printf(" Import a .wctr.json sidecar back into binary .wctr (accepts currencyKind int OR currencyKindName string; isAccountWide bool OR int)\n");
std::printf(" --gen-weather-temperate <wow-base> [zoneName]\n");
std::printf(" Emit .wow weather schedule: clear-dominant + occasional rain + fog (forest / grassland)\n");
std::printf(" --gen-weather-arctic <wow-base> [zoneName]\n");