#include "cli_sky_params_catalog.hpp" #include "cli_arg_parse.hpp" #include "cli_box_emitter.hpp" #include "pipeline/wowee_sky_params.hpp" #include #include #include #include #include #include #include #include #include #include namespace wowee { namespace editor { namespace cli { namespace { std::string stripWskpExt(std::string base) { stripExt(base, ".wskp"); return base; } bool saveOrError(const wowee::pipeline::WoweeSkyParams& c, const std::string& base, const char* cmd) { if (!wowee::pipeline::WoweeSkyParamsLoader::save(c, base)) { std::fprintf(stderr, "%s: failed to save %s.wskp\n", cmd, base.c_str()); return false; } return true; } void printGenSummary(const wowee::pipeline::WoweeSkyParams& c, const std::string& base) { std::printf("Wrote %s.wskp\n", base.c_str()); std::printf(" catalog : %s\n", c.name.c_str()); std::printf(" keyframes: %zu\n", c.entries.size()); } int handleGenStormwind(int& i, int argc, char** argv) { std::string base = argv[++i]; std::string name = "StormwindSkyDay"; if (parseOptArg(i, argc, argv)) name = argv[++i]; base = stripWskpExt(base); auto c = wowee::pipeline::WoweeSkyParamsLoader::makeStormwindDay(name); if (!saveOrError(c, base, "gen-skp")) return 1; printGenSummary(c, base); return 0; } int handleGenArctic(int& i, int argc, char** argv) { std::string base = argv[++i]; std::string name = "NorthrendArcticSky"; if (parseOptArg(i, argc, argv)) name = argv[++i]; base = stripWskpExt(base); auto c = wowee::pipeline::WoweeSkyParamsLoader::makeNorthrendArctic(name); if (!saveOrError(c, base, "gen-skp-arctic")) return 1; printGenSummary(c, base); return 0; } int handleGenHellfire(int& i, int argc, char** argv) { std::string base = argv[++i]; std::string name = "OutlandHellfireSky"; if (parseOptArg(i, argc, argv)) name = argv[++i]; base = stripWskpExt(base); auto c = wowee::pipeline::WoweeSkyParamsLoader::makeOutlandHellfire(name); if (!saveOrError(c, base, "gen-skp-hellfire")) return 1; printGenSummary(c, base); return 0; } int handleInfo(int& i, int argc, char** argv) { std::string base = argv[++i]; bool jsonOut = consumeJsonFlag(i, argc, argv); base = stripWskpExt(base); if (!wowee::pipeline::WoweeSkyParamsLoader::exists(base)) { std::fprintf(stderr, "WSKP not found: %s.wskp\n", base.c_str()); return 1; } auto c = wowee::pipeline::WoweeSkyParamsLoader::load(base); if (jsonOut) { nlohmann::json j; j["wskp"] = base + ".wskp"; j["name"] = c.name; j["count"] = c.entries.size(); nlohmann::json arr = nlohmann::json::array(); for (const auto& e : c.entries) { arr.push_back({ {"skyId", e.skyId}, {"name", e.name}, {"description", e.description}, {"mapId", e.mapId}, {"areaId", e.areaId}, {"timeOfDayHour", e.timeOfDayHour}, {"zenithColor", e.zenithColor}, {"horizonColor", e.horizonColor}, {"sunColor", e.sunColor}, {"sunAngleDeg", e.sunAngleDeg}, {"fogStartYards", e.fogStartYards}, {"fogEndYards", e.fogEndYards}, {"cloudOpacity", e.cloudOpacity}, {"cloudSpeedX10", e.cloudSpeedX10}, {"cloudSpeedMph", e.cloudSpeedX10 / 10.0}, {"iconColorRGBA", e.iconColorRGBA}, }); } j["entries"] = arr; std::printf("%s\n", j.dump(2).c_str()); return 0; } std::printf("WSKP: %s.wskp\n", base.c_str()); std::printf(" catalog : %s\n", c.name.c_str()); std::printf(" keyframes: %zu\n", c.entries.size()); if (c.entries.empty()) return 0; std::printf(" id map area hr sunAngle fog(s..e)yd cloud%% windMph name\n"); for (const auto& e : c.entries) { std::printf(" %4u %4u %4u %2u %5.1f %4.0f..%4.0f %3u%% %4.1f %s\n", e.skyId, e.mapId, e.areaId, e.timeOfDayHour, e.sunAngleDeg, e.fogStartYards, e.fogEndYards, (e.cloudOpacity * 100) / 255, e.cloudSpeedX10 / 10.0, e.name.c_str()); } return 0; } int handleValidate(int& i, int argc, char** argv) { std::string base = argv[++i]; bool jsonOut = consumeJsonFlag(i, argc, argv); base = stripWskpExt(base); if (!wowee::pipeline::WoweeSkyParamsLoader::exists(base)) { std::fprintf(stderr, "validate-wskp: WSKP not found: %s.wskp\n", base.c_str()); return 1; } auto c = wowee::pipeline::WoweeSkyParamsLoader::load(base); std::vector errors; std::vector warnings; if (c.entries.empty()) { warnings.push_back("catalog has zero entries"); } std::set idsSeen; // Per-(mapId, areaId, timeOfDayHour) triple // uniqueness — two keyframes at same hour for the // same area would render in unstable order during // diurnal interpolation. std::set tripleSeen; auto tripleKey = [](uint32_t mapId, uint32_t areaId, uint8_t hour) { return (static_cast(mapId) << 40) | (static_cast(areaId) << 8) | hour; }; for (size_t k = 0; k < c.entries.size(); ++k) { const auto& e = c.entries[k]; std::string ctx = "entry " + std::to_string(k) + " (id=" + std::to_string(e.skyId); if (!e.name.empty()) ctx += " " + e.name; ctx += ")"; if (e.skyId == 0) errors.push_back(ctx + ": skyId is 0"); if (e.name.empty()) errors.push_back(ctx + ": name is empty"); if (e.timeOfDayHour > 23) { errors.push_back(ctx + ": timeOfDayHour " + std::to_string(e.timeOfDayHour) + " > 23 — must be 0..23"); } if (e.sunAngleDeg < 0.0f || e.sunAngleDeg > 360.0f) { warnings.push_back(ctx + ": sunAngleDeg " + std::to_string(e.sunAngleDeg) + " outside [0, 360] — renderer wraps " "modulo but values outside the canonical " "range suggest authoring confusion"); } if (e.fogStartYards >= e.fogEndYards) { errors.push_back(ctx + ": fogStartYards " + std::to_string(e.fogStartYards) + " >= fogEndYards " + std::to_string(e.fogEndYards) + " — fog falloff would be inverted or " "zero-thickness"); } if (e.fogStartYards < 0.0f || e.fogEndYards < 0.0f) { errors.push_back(ctx + ": negative fog distance — fog distances " "must be non-negative"); } // Triple uniqueness: same area + same hour // duplication would tie at runtime. uint64_t key = tripleKey(e.mapId, e.areaId, e.timeOfDayHour); if (!tripleSeen.insert(key).second) { errors.push_back(ctx + ": (mapId=" + std::to_string(e.mapId) + ", areaId=" + std::to_string(e.areaId) + ", hour=" + std::to_string(e.timeOfDayHour) + ") triple already bound by another sky " "entry — diurnal interpolation would tie " "non-deterministically"); } if (!idsSeen.insert(e.skyId).second) { errors.push_back(ctx + ": duplicate skyId"); } } bool ok = errors.empty(); if (jsonOut) { nlohmann::json j; j["wskp"] = base + ".wskp"; j["ok"] = ok; j["errors"] = errors; j["warnings"] = warnings; std::printf("%s\n", j.dump(2).c_str()); return ok ? 0 : 1; } std::printf("validate-wskp: %s.wskp\n", base.c_str()); if (ok && warnings.empty()) { std::printf(" OK — %zu keyframes, all skyIds + " "(map,area,hour) triples unique\n", c.entries.size()); return 0; } if (!warnings.empty()) { std::printf(" warnings (%zu):\n", warnings.size()); for (const auto& w : warnings) std::printf(" - %s\n", w.c_str()); } if (!errors.empty()) { std::printf(" ERRORS (%zu):\n", errors.size()); for (const auto& e : errors) std::printf(" - %s\n", e.c_str()); } return ok ? 0 : 1; } } // namespace bool handleSkyParamsCatalog(int& i, int argc, char** argv, int& outRc) { if (std::strcmp(argv[i], "--gen-skp") == 0 && i + 1 < argc) { outRc = handleGenStormwind(i, argc, argv); return true; } if (std::strcmp(argv[i], "--gen-skp-arctic") == 0 && i + 1 < argc) { outRc = handleGenArctic(i, argc, argv); return true; } if (std::strcmp(argv[i], "--gen-skp-hellfire") == 0 && i + 1 < argc) { outRc = handleGenHellfire(i, argc, argv); return true; } if (std::strcmp(argv[i], "--info-wskp") == 0 && i + 1 < argc) { outRc = handleInfo(i, argc, argv); return true; } if (std::strcmp(argv[i], "--validate-wskp") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } return false; } } // namespace cli } // namespace editor } // namespace wowee