mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-10 02:53:51 +00:00
feat(editor): add WTSK JSON round-trip (export/import sidecar)
Closes the JSON round-trip gap on the trade skill recipe catalog format shipped last batch. --export-wtsk-json emits all 14 scalar fields plus a dual int + name form for profession, plus a nested reagents[] array — only non-empty slots are emitted to keep hand-edits compact. --import-wtsk-json zeroes the reagent slots before parsing (so a 2-element reagents array correctly clears slots 2 and 3) and accepts profession by either int or name. Verified byte-identical round-trip on all three preset emitters (starter / blacksmithing / alchemy — including recipes with 3 reagent slots populated). 754 documented CLI flags.
This commit is contained in:
parent
33a7b4b3cf
commit
77384f600e
3 changed files with 158 additions and 0 deletions
|
|
@ -149,6 +149,7 @@ const char* const kArgRequired[] = {
|
|||
"--export-wpcn-json", "--import-wpcn-json",
|
||||
"--gen-tsk", "--gen-tsk-blacksmithing", "--gen-tsk-alchemy",
|
||||
"--info-wtsk", "--validate-wtsk",
|
||||
"--export-wtsk-json", "--import-wtsk-json",
|
||||
"--gen-weather-temperate", "--gen-weather-arctic",
|
||||
"--gen-weather-desert", "--gen-weather-stormy",
|
||||
"--gen-zone-atmosphere",
|
||||
|
|
|
|||
|
|
@ -1421,6 +1421,10 @@ void printUsage(const char* argv0) {
|
|||
std::printf(" Print WTSK entries (id / profession / 4 skill brackets / craft spell / produced item / qty / tool / reagent count / name)\n");
|
||||
std::printf(" --validate-wtsk <wtsk-base> [--json]\n");
|
||||
std::printf(" Static checks: id>0+unique, name not empty, profession 0..13, craft spell + produced item required, monotonic skill brackets\n");
|
||||
std::printf(" --export-wtsk-json <wtsk-base> [out.json]\n");
|
||||
std::printf(" Export binary .wtsk to a human-editable JSON sidecar with nested reagents (defaults to <base>.wtsk.json)\n");
|
||||
std::printf(" --import-wtsk-json <json-path> [out-base]\n");
|
||||
std::printf(" Import a .wtsk.json sidecar back into binary .wtsk (accepts profession int OR name string, reagents array up to 4 slots)\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");
|
||||
|
|
|
|||
|
|
@ -148,6 +148,153 @@ int handleInfo(int& i, int argc, char** argv) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int handleExportJson(int& i, int argc, char** argv) {
|
||||
// Mirrors the JSON pairs added for every other novel
|
||||
// open format. Each recipe emits all 14 scalar fields
|
||||
// plus a dual int + name form for profession, plus a
|
||||
// nested reagents[] array (only non-empty slots are
|
||||
// emitted to keep hand-edits compact).
|
||||
std::string base = argv[++i];
|
||||
std::string outPath;
|
||||
if (parseOptArg(i, argc, argv)) outPath = argv[++i];
|
||||
base = stripWtskExt(base);
|
||||
if (outPath.empty()) outPath = base + ".wtsk.json";
|
||||
if (!wowee::pipeline::WoweeTradeSkillLoader::exists(base)) {
|
||||
std::fprintf(stderr,
|
||||
"export-wtsk-json: WTSK not found: %s.wtsk\n", base.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto c = wowee::pipeline::WoweeTradeSkillLoader::load(base);
|
||||
nlohmann::json j;
|
||||
j["name"] = c.name;
|
||||
nlohmann::json arr = nlohmann::json::array();
|
||||
for (const auto& e : c.entries) appendEntryJson(arr, e);
|
||||
j["entries"] = arr;
|
||||
std::ofstream out(outPath);
|
||||
if (!out) {
|
||||
std::fprintf(stderr,
|
||||
"export-wtsk-json: cannot write %s\n", outPath.c_str());
|
||||
return 1;
|
||||
}
|
||||
out << j.dump(2) << "\n";
|
||||
out.close();
|
||||
std::printf("Wrote %s\n", outPath.c_str());
|
||||
std::printf(" source : %s.wtsk\n", base.c_str());
|
||||
std::printf(" recipes : %zu\n", c.entries.size());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handleImportJson(int& i, int argc, char** argv) {
|
||||
std::string jsonPath = argv[++i];
|
||||
std::string outBase;
|
||||
if (parseOptArg(i, argc, argv)) outBase = argv[++i];
|
||||
if (outBase.empty()) {
|
||||
outBase = jsonPath;
|
||||
std::string suffix = ".wtsk.json";
|
||||
if (outBase.size() > suffix.size() &&
|
||||
outBase.substr(outBase.size() - suffix.size()) == suffix) {
|
||||
outBase = outBase.substr(0, outBase.size() - suffix.size());
|
||||
} else if (outBase.size() > 5 &&
|
||||
outBase.substr(outBase.size() - 5) == ".json") {
|
||||
outBase = outBase.substr(0, outBase.size() - 5);
|
||||
}
|
||||
}
|
||||
outBase = stripWtskExt(outBase);
|
||||
std::ifstream in(jsonPath);
|
||||
if (!in) {
|
||||
std::fprintf(stderr,
|
||||
"import-wtsk-json: cannot read %s\n", jsonPath.c_str());
|
||||
return 1;
|
||||
}
|
||||
nlohmann::json j;
|
||||
try { in >> j; }
|
||||
catch (const std::exception& e) {
|
||||
std::fprintf(stderr,
|
||||
"import-wtsk-json: bad JSON in %s: %s\n",
|
||||
jsonPath.c_str(), e.what());
|
||||
return 1;
|
||||
}
|
||||
auto profFromName = [](const std::string& s) -> uint8_t {
|
||||
if (s == "blacksmithing") return wowee::pipeline::WoweeTradeSkill::Blacksmithing;
|
||||
if (s == "tailoring") return wowee::pipeline::WoweeTradeSkill::Tailoring;
|
||||
if (s == "engineering") return wowee::pipeline::WoweeTradeSkill::Engineering;
|
||||
if (s == "alchemy") return wowee::pipeline::WoweeTradeSkill::Alchemy;
|
||||
if (s == "enchanting") return wowee::pipeline::WoweeTradeSkill::Enchanting;
|
||||
if (s == "leatherworking") return wowee::pipeline::WoweeTradeSkill::Leatherworking;
|
||||
if (s == "jewelcrafting") return wowee::pipeline::WoweeTradeSkill::Jewelcrafting;
|
||||
if (s == "inscription") return wowee::pipeline::WoweeTradeSkill::Inscription;
|
||||
if (s == "mining") return wowee::pipeline::WoweeTradeSkill::Mining;
|
||||
if (s == "skinning") return wowee::pipeline::WoweeTradeSkill::Skinning;
|
||||
if (s == "herbalism") return wowee::pipeline::WoweeTradeSkill::Herbalism;
|
||||
if (s == "cooking") return wowee::pipeline::WoweeTradeSkill::Cooking;
|
||||
if (s == "first-aid") return wowee::pipeline::WoweeTradeSkill::FirstAid;
|
||||
if (s == "fishing") return wowee::pipeline::WoweeTradeSkill::Fishing;
|
||||
return wowee::pipeline::WoweeTradeSkill::Blacksmithing;
|
||||
};
|
||||
wowee::pipeline::WoweeTradeSkill c;
|
||||
c.name = j.value("name", std::string{});
|
||||
if (j.contains("entries") && j["entries"].is_array()) {
|
||||
for (const auto& je : j["entries"]) {
|
||||
wowee::pipeline::WoweeTradeSkill::Entry e;
|
||||
e.recipeId = je.value("recipeId", 0u);
|
||||
e.name = je.value("name", std::string{});
|
||||
e.description = je.value("description", std::string{});
|
||||
e.iconPath = je.value("iconPath", std::string{});
|
||||
if (je.contains("profession") &&
|
||||
je["profession"].is_number_integer()) {
|
||||
e.profession = static_cast<uint8_t>(
|
||||
je["profession"].get<int>());
|
||||
} else if (je.contains("professionName") &&
|
||||
je["professionName"].is_string()) {
|
||||
e.profession = profFromName(
|
||||
je["professionName"].get<std::string>());
|
||||
}
|
||||
e.skillId = je.value("skillId", 0u);
|
||||
e.orangeRank = static_cast<uint16_t>(je.value("orangeRank", 1));
|
||||
e.yellowRank = static_cast<uint16_t>(je.value("yellowRank", 25));
|
||||
e.greenRank = static_cast<uint16_t>(je.value("greenRank", 50));
|
||||
e.grayRank = static_cast<uint16_t>(je.value("grayRank", 75));
|
||||
e.craftSpellId = je.value("craftSpellId", 0u);
|
||||
e.producedItemId = je.value("producedItemId", 0u);
|
||||
e.producedMinCount = static_cast<uint8_t>(
|
||||
je.value("producedMinCount", 1));
|
||||
e.producedMaxCount = static_cast<uint8_t>(
|
||||
je.value("producedMaxCount", 1));
|
||||
e.toolItemId = je.value("toolItemId", 0u);
|
||||
// Reset to all-zero before parsing reagents — the
|
||||
// exporter only emits non-empty slots, so a
|
||||
// reagents[] of size 2 should leave slots 2 and
|
||||
// 3 clean.
|
||||
for (size_t k = 0;
|
||||
k < wowee::pipeline::WoweeTradeSkill::kMaxReagents; ++k) {
|
||||
e.reagentItemId[k] = 0;
|
||||
e.reagentCount[k] = 0;
|
||||
}
|
||||
if (je.contains("reagents") && je["reagents"].is_array()) {
|
||||
size_t slot = 0;
|
||||
for (const auto& jr : je["reagents"]) {
|
||||
if (slot >= wowee::pipeline::WoweeTradeSkill::kMaxReagents)
|
||||
break;
|
||||
e.reagentItemId[slot] = jr.value("itemId", 0u);
|
||||
e.reagentCount[slot] = static_cast<uint8_t>(
|
||||
jr.value("count", 0));
|
||||
++slot;
|
||||
}
|
||||
}
|
||||
c.entries.push_back(e);
|
||||
}
|
||||
}
|
||||
if (!wowee::pipeline::WoweeTradeSkillLoader::save(c, outBase)) {
|
||||
std::fprintf(stderr,
|
||||
"import-wtsk-json: failed to save %s.wtsk\n", outBase.c_str());
|
||||
return 1;
|
||||
}
|
||||
std::printf("Wrote %s.wtsk\n", outBase.c_str());
|
||||
std::printf(" source : %s\n", jsonPath.c_str());
|
||||
std::printf(" recipes : %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);
|
||||
|
|
@ -285,6 +432,12 @@ bool handleTradeSkillsCatalog(int& i, int argc, char** argv, int& outRc) {
|
|||
if (std::strcmp(argv[i], "--validate-wtsk") == 0 && i + 1 < argc) {
|
||||
outRc = handleValidate(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--export-wtsk-json") == 0 && i + 1 < argc) {
|
||||
outRc = handleExportJson(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--import-wtsk-json") == 0 && i + 1 < argc) {
|
||||
outRc = handleImportJson(i, argc, argv); return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue