mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-10 19:13:52 +00:00
feat(editor): add WTBR JSON round-trip (--export/--import-wtbr-json)
Closes the editing loop on the token-reward catalog: dump a
.wtbr to JSON, hand-edit rewardKind / rewardId / spent token
counts / faction gates (e.g. raise T10 helm cost from 95 to 100
Emblems, swap a server-custom mount reward to a Pet kind, lower
an Argent Tournament reward standing from Exalted to Honored),
re-import to a byte-identical binary.
Two dual-encoded fields:
- rewardKind: int 0..7 OR "item" / "spell" / "title" /
"mount" / "pet" / "currency" / "heirloom" / "cosmetic"
- requiredFactionStanding: int 0..7 OR "hated" / "hostile" /
"unfriendly" / "neutral" / "friendly" / "honored" /
"revered" / "exalted"
Verified byte-identical round-trip on all three presets
(raid / pvp / faction). CLI flag count 1039 -> 1041.
This commit is contained in:
parent
c1c4b8fa12
commit
28becba00e
3 changed files with 184 additions and 0 deletions
|
|
@ -272,6 +272,7 @@ const char* const kArgRequired[] = {
|
|||
"--export-wbkd-json", "--import-wbkd-json",
|
||||
"--gen-tbr", "--gen-tbr-pvp", "--gen-tbr-faction",
|
||||
"--info-wtbr", "--validate-wtbr",
|
||||
"--export-wtbr-json", "--import-wtbr-json",
|
||||
"--gen-weather-temperate", "--gen-weather-arctic",
|
||||
"--gen-weather-desert", "--gen-weather-stormy",
|
||||
"--gen-zone-atmosphere",
|
||||
|
|
|
|||
|
|
@ -1995,6 +1995,10 @@ void printUsage(const char* argv0) {
|
|||
std::printf(" Print WTBR entries (id / spent token x count / reward kind / rewardId / faction@standing gate / name)\n");
|
||||
std::printf(" --validate-wtbr <wtbr-base> [--json]\n");
|
||||
std::printf(" Static checks: id+name+spentTokenItemId+count required, rewardKind 0..7, requiredFactionStanding 0..7, no duplicate ids; warns on rewardId=0 (no actual reward), standing>Neutral with factionId=0, Currency conversion item->itself\n");
|
||||
std::printf(" --export-wtbr-json <wtbr-base> [out.json]\n");
|
||||
std::printf(" Export binary .wtbr to a human-editable JSON sidecar (defaults to <base>.wtbr.json)\n");
|
||||
std::printf(" --import-wtbr-json <json-path> [out-base]\n");
|
||||
std::printf(" Import a .wtbr.json sidecar back into binary .wtbr (accepts rewardKind/requiredFactionStanding int OR name)\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");
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "pipeline/wowee_token_rewards.hpp"
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <cctype>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
|
@ -131,6 +132,178 @@ 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 = stripWtbrExt(base);
|
||||
if (!wowee::pipeline::WoweeTokenRewardLoader::exists(base)) {
|
||||
std::fprintf(stderr,
|
||||
"export-wtbr-json: WTBR not found: %s.wtbr\n",
|
||||
base.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto c = wowee::pipeline::WoweeTokenRewardLoader::load(base);
|
||||
if (outPath.empty()) outPath = base + ".wtbr.json";
|
||||
nlohmann::json j;
|
||||
j["catalog"] = c.name;
|
||||
nlohmann::json arr = nlohmann::json::array();
|
||||
for (const auto& e : c.entries) {
|
||||
nlohmann::json je;
|
||||
je["tokenRewardId"] = e.tokenRewardId;
|
||||
je["name"] = e.name;
|
||||
je["description"] = e.description;
|
||||
je["spentTokenItemId"] = e.spentTokenItemId;
|
||||
je["spentTokenCount"] = e.spentTokenCount;
|
||||
je["rewardKind"] = e.rewardKind;
|
||||
je["rewardKindName"] =
|
||||
wowee::pipeline::WoweeTokenReward::rewardKindName(e.rewardKind);
|
||||
je["rewardId"] = e.rewardId;
|
||||
je["rewardCount"] = e.rewardCount;
|
||||
je["requiredFactionId"] = e.requiredFactionId;
|
||||
je["requiredFactionStanding"] = e.requiredFactionStanding;
|
||||
je["requiredFactionStandingName"] =
|
||||
wowee::pipeline::WoweeTokenReward::factionStandingName(e.requiredFactionStanding);
|
||||
je["iconColorRGBA"] = e.iconColorRGBA;
|
||||
arr.push_back(je);
|
||||
}
|
||||
j["entries"] = arr;
|
||||
std::ofstream os(outPath);
|
||||
if (!os) {
|
||||
std::fprintf(stderr,
|
||||
"export-wtbr-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(" rewards : %zu\n", c.entries.size());
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t parseRewardKindToken(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::WoweeTokenReward::Cosmetic)
|
||||
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 == "item") return wowee::pipeline::WoweeTokenReward::Item;
|
||||
if (s == "spell") return wowee::pipeline::WoweeTokenReward::Spell;
|
||||
if (s == "title") return wowee::pipeline::WoweeTokenReward::Title;
|
||||
if (s == "mount") return wowee::pipeline::WoweeTokenReward::Mount;
|
||||
if (s == "pet") return wowee::pipeline::WoweeTokenReward::Pet;
|
||||
if (s == "currency") return wowee::pipeline::WoweeTokenReward::Currency;
|
||||
if (s == "heirloom") return wowee::pipeline::WoweeTokenReward::Heirloom;
|
||||
if (s == "cosmetic") return wowee::pipeline::WoweeTokenReward::Cosmetic;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
uint8_t parseFactionStandingToken(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::WoweeTokenReward::Exalted)
|
||||
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 == "hated") return wowee::pipeline::WoweeTokenReward::Hated;
|
||||
if (s == "hostile") return wowee::pipeline::WoweeTokenReward::Hostile;
|
||||
if (s == "unfriendly") return wowee::pipeline::WoweeTokenReward::Unfriendly;
|
||||
if (s == "neutral") return wowee::pipeline::WoweeTokenReward::Neutral;
|
||||
if (s == "friendly") return wowee::pipeline::WoweeTokenReward::Friendly;
|
||||
if (s == "honored") return wowee::pipeline::WoweeTokenReward::Honored;
|
||||
if (s == "revered") return wowee::pipeline::WoweeTokenReward::Revered;
|
||||
if (s == "exalted") return wowee::pipeline::WoweeTokenReward::Exalted;
|
||||
}
|
||||
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-wtbr-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-wtbr-json: parse error in %s: %s\n",
|
||||
jsonPath.c_str(), ex.what());
|
||||
return 1;
|
||||
}
|
||||
wowee::pipeline::WoweeTokenReward 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::WoweeTokenReward::Entry e;
|
||||
if (je.contains("tokenRewardId")) e.tokenRewardId = je["tokenRewardId"].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("spentTokenItemId")) e.spentTokenItemId = je["spentTokenItemId"].get<uint32_t>();
|
||||
if (je.contains("spentTokenCount")) e.spentTokenCount = je["spentTokenCount"].get<uint32_t>();
|
||||
uint8_t kind = wowee::pipeline::WoweeTokenReward::Item;
|
||||
if (je.contains("rewardKind"))
|
||||
kind = parseRewardKindToken(je["rewardKind"], kind);
|
||||
else if (je.contains("rewardKindName"))
|
||||
kind = parseRewardKindToken(je["rewardKindName"], kind);
|
||||
e.rewardKind = kind;
|
||||
if (je.contains("rewardId")) e.rewardId = je["rewardId"].get<uint32_t>();
|
||||
if (je.contains("rewardCount")) e.rewardCount = je["rewardCount"].get<uint32_t>();
|
||||
if (je.contains("requiredFactionId")) e.requiredFactionId = je["requiredFactionId"].get<uint32_t>();
|
||||
uint8_t standing = wowee::pipeline::WoweeTokenReward::Neutral;
|
||||
if (je.contains("requiredFactionStanding"))
|
||||
standing = parseFactionStandingToken(je["requiredFactionStanding"], standing);
|
||||
else if (je.contains("requiredFactionStandingName"))
|
||||
standing = parseFactionStandingToken(je["requiredFactionStandingName"], standing);
|
||||
e.requiredFactionStanding = standing;
|
||||
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 = ".wtbr.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 = stripWtbrExt(outBase);
|
||||
if (!wowee::pipeline::WoweeTokenRewardLoader::save(c, outBase)) {
|
||||
std::fprintf(stderr,
|
||||
"import-wtbr-json: failed to save %s.wtbr\n",
|
||||
outBase.c_str());
|
||||
return 1;
|
||||
}
|
||||
std::printf("Wrote %s.wtbr\n", outBase.c_str());
|
||||
std::printf(" catalog : %s\n", c.name.c_str());
|
||||
std::printf(" rewards : %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);
|
||||
|
|
@ -252,6 +425,12 @@ bool handleTokenRewardsCatalog(int& i, int argc, char** argv,
|
|||
if (std::strcmp(argv[i], "--validate-wtbr") == 0 && i + 1 < argc) {
|
||||
outRc = handleValidate(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--export-wtbr-json") == 0 && i + 1 < argc) {
|
||||
outRc = handleExportJson(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--import-wtbr-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