feat(editor): add WSCS JSON round-trip (--export/--import-wscs-json)

Closes the editing loop on the skill-cost catalog: dump a .wscs
to JSON, hand-edit costKind / skill ranges / requiredLevel /
copperCost (e.g. retune Apprentice profession from 1s to 5s for
a faster server, raise Cold Weather Flying from lvl 77 to 75,
add a custom WeaponSkill tier above Master), re-import to a
byte-identical binary.

The exporter emits both costKind (int 0..4) and the human-
readable costKindName ("profession" / "weapon" / "riding" /
"class-skill" / "misc"); the importer accepts either form.

Verified byte-identical round-trip on all three presets
(prof / weapon / riding). CLI flag count 1015 -> 1017.
This commit is contained in:
Kelsi 2026-05-09 23:05:23 -07:00
parent b10bc2be5d
commit 7d7e1d73dc
3 changed files with 152 additions and 0 deletions

View file

@ -262,6 +262,7 @@ const char* const kArgRequired[] = {
"--export-wiqr-json", "--import-wiqr-json",
"--gen-scs", "--gen-scs-weapon", "--gen-scs-riding",
"--info-wscs", "--validate-wscs",
"--export-wscs-json", "--import-wscs-json",
"--gen-weather-temperate", "--gen-weather-arctic",
"--gen-weather-desert", "--gen-weather-stormy",
"--gen-zone-atmosphere",

View file

@ -1947,6 +1947,10 @@ void printUsage(const char* argv0) {
std::printf(" Print WSCS entries (id / rank / kind / minSkill / maxSkill / required level / gold cost / name)\n");
std::printf(" --validate-wscs <wscs-base> [--json]\n");
std::printf(" Static checks: id+name required, costKind 0..4, no duplicate ids, min<max; warns on lvl>80, RidingSkill below lvl 20, Profession with cost=0\n");
std::printf(" --export-wscs-json <wscs-base> [out.json]\n");
std::printf(" Export binary .wscs to a human-editable JSON sidecar (defaults to <base>.wscs.json)\n");
std::printf(" --import-wscs-json <json-path> [out-base]\n");
std::printf(" Import a .wscs.json sidecar back into binary .wscs (accepts costKind int OR costKindName string)\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");

View file

@ -5,6 +5,7 @@
#include "pipeline/wowee_skill_costs.hpp"
#include <nlohmann/json.hpp>
#include <cctype>
#include <cstdint>
#include <cstdio>
#include <cstring>
@ -138,6 +139,146 @@ 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 = stripWscsExt(base);
if (!wowee::pipeline::WoweeSkillCostLoader::exists(base)) {
std::fprintf(stderr,
"export-wscs-json: WSCS not found: %s.wscs\n",
base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeSkillCostLoader::load(base);
if (outPath.empty()) outPath = base + ".wscs.json";
nlohmann::json j;
j["catalog"] = c.name;
nlohmann::json arr = nlohmann::json::array();
for (const auto& e : c.entries) {
nlohmann::json je;
je["costId"] = e.costId;
je["name"] = e.name;
je["description"] = e.description;
je["skillRankIndex"] = e.skillRankIndex;
je["minSkillToLearn"] = e.minSkillToLearn;
je["maxSkillUnlocked"] = e.maxSkillUnlocked;
je["requiredLevel"] = e.requiredLevel;
je["costKind"] = e.costKind;
je["costKindName"] =
wowee::pipeline::WoweeSkillCost::costKindName(e.costKind);
je["copperCost"] = e.copperCost;
je["iconColorRGBA"] = e.iconColorRGBA;
arr.push_back(je);
}
j["entries"] = arr;
std::ofstream os(outPath);
if (!os) {
std::fprintf(stderr,
"export-wscs-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(" tiers : %zu\n", c.entries.size());
return 0;
}
uint8_t parseCostKindToken(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::WoweeSkillCost::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 == "profession") return wowee::pipeline::WoweeSkillCost::Profession;
if (s == "weapon" ||
s == "weaponskill") return wowee::pipeline::WoweeSkillCost::WeaponSkill;
if (s == "riding" ||
s == "ridingskill") return wowee::pipeline::WoweeSkillCost::RidingSkill;
if (s == "class-skill" ||
s == "classskill") return wowee::pipeline::WoweeSkillCost::ClassSkill;
if (s == "misc") return wowee::pipeline::WoweeSkillCost::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-wscs-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-wscs-json: parse error in %s: %s\n",
jsonPath.c_str(), ex.what());
return 1;
}
wowee::pipeline::WoweeSkillCost 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::WoweeSkillCost::Entry e;
if (je.contains("costId")) e.costId = je["costId"].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("skillRankIndex")) e.skillRankIndex = je["skillRankIndex"].get<uint32_t>();
if (je.contains("minSkillToLearn")) e.minSkillToLearn = je["minSkillToLearn"].get<uint16_t>();
if (je.contains("maxSkillUnlocked")) e.maxSkillUnlocked = je["maxSkillUnlocked"].get<uint16_t>();
if (je.contains("requiredLevel")) e.requiredLevel = je["requiredLevel"].get<uint8_t>();
uint8_t kind = wowee::pipeline::WoweeSkillCost::Profession;
if (je.contains("costKind"))
kind = parseCostKindToken(je["costKind"], kind);
else if (je.contains("costKindName"))
kind = parseCostKindToken(je["costKindName"], kind);
e.costKind = kind;
if (je.contains("copperCost")) e.copperCost = je["copperCost"].get<uint32_t>();
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 = ".wscs.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 = stripWscsExt(outBase);
if (!wowee::pipeline::WoweeSkillCostLoader::save(c, outBase)) {
std::fprintf(stderr,
"import-wscs-json: failed to save %s.wscs\n",
outBase.c_str());
return 1;
}
std::printf("Wrote %s.wscs\n", outBase.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" tiers : %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);
@ -257,6 +398,12 @@ bool handleSkillCostsCatalog(int& i, int argc, char** argv,
if (std::strcmp(argv[i], "--validate-wscs") == 0 && i + 1 < argc) {
outRc = handleValidate(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--export-wscs-json") == 0 && i + 1 < argc) {
outRc = handleExportJson(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--import-wscs-json") == 0 && i + 1 < argc) {
outRc = handleImportJson(i, argc, argv); return true;
}
return false;
}