mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-10 11:03:51 +00:00
feat(editor): add WCEF JSON round-trip (--export/--import-wcef-json)
Closes the editing loop on the creature-family catalog: dump a
.wcef to JSON, hand-edit familyKind / petTalentTree /
minLevelForTame / petFoodTypes (e.g. add Bread to Bear's diet,
move Boar from Tenacity to Cunning, drop the tame requirement on
exotic Worm from 50 to 45), re-import to a byte-identical binary.
Three different field types each take dual int+name forms:
- familyKind: int 0..5 OR "beast"/"demon"/"undead"/"elemental"/
"not-pet"/"exotic"
- petTalentTree: int 0..3 OR "none"/"ferocity"/"tenacity"/
"cunning"
- petFoodTypes: int bitfield OR pipe-separated label string
("Meat|Fish|Raw"). Importer prefers the int form when both
are present so unknown bits round-trip losslessly.
Verified byte-identical round-trip on all three presets
(starter / ferocity / exotic). CLI flag count 919 -> 921.
This commit is contained in:
parent
12faffeb87
commit
3e73860475
3 changed files with 211 additions and 0 deletions
|
|
@ -220,6 +220,7 @@ const char* const kArgRequired[] = {
|
|||
"--export-wscd-json", "--import-wscd-json",
|
||||
"--gen-cef", "--gen-cef-ferocity", "--gen-cef-exotic",
|
||||
"--info-wcef", "--validate-wcef",
|
||||
"--export-wcef-json", "--import-wcef-json",
|
||||
"--gen-weather-temperate", "--gen-weather-arctic",
|
||||
"--gen-weather-desert", "--gen-weather-stormy",
|
||||
"--gen-zone-atmosphere",
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "pipeline/wowee_creature_families.hpp"
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <cctype>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
|
@ -146,6 +147,205 @@ 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 = stripWcefExt(base);
|
||||
if (!wowee::pipeline::WoweeCreatureFamilyLoader::exists(base)) {
|
||||
std::fprintf(stderr,
|
||||
"export-wcef-json: WCEF not found: %s.wcef\n",
|
||||
base.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto c = wowee::pipeline::WoweeCreatureFamilyLoader::load(base);
|
||||
if (outPath.empty()) outPath = base + ".wcef.json";
|
||||
nlohmann::json j;
|
||||
j["catalog"] = c.name;
|
||||
nlohmann::json arr = nlohmann::json::array();
|
||||
for (const auto& e : c.entries) {
|
||||
std::string foodNames;
|
||||
appendFoodNames(e.petFoodTypes, foodNames);
|
||||
nlohmann::json je;
|
||||
je["familyId"] = e.familyId;
|
||||
je["name"] = e.name;
|
||||
je["description"] = e.description;
|
||||
je["familyKind"] = e.familyKind;
|
||||
je["familyKindName"] =
|
||||
wowee::pipeline::WoweeCreatureFamily::familyKindName(e.familyKind);
|
||||
je["petTalentTree"] = e.petTalentTree;
|
||||
je["petTalentTreeName"] =
|
||||
wowee::pipeline::WoweeCreatureFamily::petTalentTreeName(e.petTalentTree);
|
||||
je["minLevelForTame"] = e.minLevelForTame;
|
||||
je["skillLine"] = e.skillLine;
|
||||
je["petFoodTypes"] = e.petFoodTypes;
|
||||
je["petFoodTypesLabels"] = foodNames;
|
||||
je["iconColorRGBA"] = e.iconColorRGBA;
|
||||
arr.push_back(je);
|
||||
}
|
||||
j["entries"] = arr;
|
||||
std::ofstream os(outPath);
|
||||
if (!os) {
|
||||
std::fprintf(stderr,
|
||||
"export-wcef-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(" families : %zu\n", c.entries.size());
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t parseFamilyKindToken(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::WoweeCreatureFamily::Exotic)
|
||||
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 == "beast") return wowee::pipeline::WoweeCreatureFamily::Beast;
|
||||
if (s == "demon") return wowee::pipeline::WoweeCreatureFamily::Demon;
|
||||
if (s == "undead") return wowee::pipeline::WoweeCreatureFamily::Undead;
|
||||
if (s == "elemental") return wowee::pipeline::WoweeCreatureFamily::Elemental;
|
||||
if (s == "not-pet" ||
|
||||
s == "notpet") return wowee::pipeline::WoweeCreatureFamily::NotPet;
|
||||
if (s == "exotic") return wowee::pipeline::WoweeCreatureFamily::Exotic;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
uint8_t parseTalentTreeToken(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::WoweeCreatureFamily::Cunning)
|
||||
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 == "none") return wowee::pipeline::WoweeCreatureFamily::TreeNone;
|
||||
if (s == "ferocity") return wowee::pipeline::WoweeCreatureFamily::Ferocity;
|
||||
if (s == "tenacity") return wowee::pipeline::WoweeCreatureFamily::Tenacity;
|
||||
if (s == "cunning") return wowee::pipeline::WoweeCreatureFamily::Cunning;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
uint32_t parseFoodTypesField(const nlohmann::json& jv) {
|
||||
using F = wowee::pipeline::WoweeCreatureFamily;
|
||||
if (jv.is_number_integer() || jv.is_number_unsigned())
|
||||
return jv.get<uint32_t>();
|
||||
if (jv.is_string()) {
|
||||
std::string s = jv.get<std::string>();
|
||||
uint32_t out = 0;
|
||||
size_t pos = 0;
|
||||
while (pos < s.size()) {
|
||||
size_t end = s.find('|', pos);
|
||||
if (end == std::string::npos) end = s.size();
|
||||
std::string tok = s.substr(pos, end - pos);
|
||||
for (auto& ch : tok) ch = static_cast<char>(std::tolower(ch));
|
||||
if (tok == "meat") out |= F::Meat;
|
||||
else if (tok == "fish") out |= F::Fish;
|
||||
else if (tok == "bread") out |= F::Bread;
|
||||
else if (tok == "cheese") out |= F::Cheese;
|
||||
else if (tok == "fruit") out |= F::Fruit;
|
||||
else if (tok == "fungus") out |= F::Fungus;
|
||||
else if (tok == "raw") out |= F::Raw;
|
||||
pos = end + 1;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
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];
|
||||
std::ifstream is(jsonPath);
|
||||
if (!is) {
|
||||
std::fprintf(stderr,
|
||||
"import-wcef-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-wcef-json: parse error in %s: %s\n",
|
||||
jsonPath.c_str(), ex.what());
|
||||
return 1;
|
||||
}
|
||||
wowee::pipeline::WoweeCreatureFamily 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::WoweeCreatureFamily::Entry e;
|
||||
if (je.contains("familyId")) e.familyId = je["familyId"].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>();
|
||||
uint8_t kind = wowee::pipeline::WoweeCreatureFamily::Beast;
|
||||
if (je.contains("familyKind"))
|
||||
kind = parseFamilyKindToken(je["familyKind"], kind);
|
||||
else if (je.contains("familyKindName"))
|
||||
kind = parseFamilyKindToken(je["familyKindName"], kind);
|
||||
e.familyKind = kind;
|
||||
uint8_t tree = wowee::pipeline::WoweeCreatureFamily::TreeNone;
|
||||
if (je.contains("petTalentTree"))
|
||||
tree = parseTalentTreeToken(je["petTalentTree"], tree);
|
||||
else if (je.contains("petTalentTreeName"))
|
||||
tree = parseTalentTreeToken(je["petTalentTreeName"], tree);
|
||||
e.petTalentTree = tree;
|
||||
if (je.contains("minLevelForTame"))
|
||||
e.minLevelForTame = je["minLevelForTame"].get<uint8_t>();
|
||||
if (je.contains("skillLine"))
|
||||
e.skillLine = je["skillLine"].get<uint32_t>();
|
||||
if (je.contains("petFoodTypes"))
|
||||
e.petFoodTypes = parseFoodTypesField(je["petFoodTypes"]);
|
||||
else if (je.contains("petFoodTypesLabels"))
|
||||
e.petFoodTypes = parseFoodTypesField(je["petFoodTypesLabels"]);
|
||||
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 = ".wcef.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 = stripWcefExt(outBase);
|
||||
if (!wowee::pipeline::WoweeCreatureFamilyLoader::save(c, outBase)) {
|
||||
std::fprintf(stderr,
|
||||
"import-wcef-json: failed to save %s.wcef\n",
|
||||
outBase.c_str());
|
||||
return 1;
|
||||
}
|
||||
std::printf("Wrote %s.wcef\n", outBase.c_str());
|
||||
std::printf(" catalog : %s\n", c.name.c_str());
|
||||
std::printf(" families : %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);
|
||||
|
|
@ -278,6 +478,12 @@ bool handleCreatureFamiliesCatalog(int& i, int argc, char** argv,
|
|||
if (std::strcmp(argv[i], "--validate-wcef") == 0 && i + 1 < argc) {
|
||||
outRc = handleValidate(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--export-wcef-json") == 0 && i + 1 < argc) {
|
||||
outRc = handleExportJson(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--import-wcef-json") == 0 && i + 1 < argc) {
|
||||
outRc = handleImportJson(i, argc, argv); return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1755,6 +1755,10 @@ void printUsage(const char* argv0) {
|
|||
std::printf(" Print WCEF entries (id / kind / talent tree / tame level / skill line / food types / name)\n");
|
||||
std::printf(" --validate-wcef <wcef-base> [--json]\n");
|
||||
std::printf(" Static checks: id+name required, familyKind 0..5, talent tree 0..3, no duplicate ids; warns on NotPet+talent, Exotic+lvl>80, Beast/Exotic with no foods (would starve)\n");
|
||||
std::printf(" --export-wcef-json <wcef-base> [out.json]\n");
|
||||
std::printf(" Export binary .wcef to a human-editable JSON sidecar (defaults to <base>.wcef.json)\n");
|
||||
std::printf(" --import-wcef-json <json-path> [out-base]\n");
|
||||
std::printf(" Import a .wcef.json sidecar back into binary .wcef (accepts familyKind/petTalentTree int OR name; petFoodTypes int OR pipe-separated label 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");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue