Kelsidavis-WoWee/tools/editor/cli_loading_screens_catalog.cpp
Kelsi 07137acc89 feat(pipeline): add WLDS (Wowee Loading Screen) catalog
63rd open format — replaces LoadingScreens.dbc plus the
per-zone background-image tables. Defines the loading-screen
images shown when the client crosses into a new map /
instance, with optional level-bracket gating and expansion
gating (TBC art only shown if expansion installed).

When multiple screens match the player's current map + level
+ expansion, displayWeight selects randomly between them — a
zone with 3 weighted variants gets a different image roughly
proportional to weight.

4 expansion gates (Classic / TBC / WotLK / TurtleWoW),
isAnimated flag for screens with subtle animation,
isWideAspect flag for 16:9 raid intro art (vs 4:3 standard).

Cross-references with prior formats — mapId points at
WMS.map.mapId (which map triggers this loading screen);
mapId=0 is the catch-all sentinel for screens shown when
no map-specific screen matches.

CLI: --gen-lds (3 base screens — Elwynn level 1-30, Orgrimmar,
GenericFallback level 31-80 catch-all), --gen-lds-instances
(5 WotLK dungeon screens with mapId+expansion cross-refs:
Halls of Lightning/Stone, Utgarde Pinnacle, Violet Hold,
Old Kingdom), --gen-lds-raid (3 raid intro screens —
Naxxramas/Ulduar/ToC at isWideAspect=1 with weight=3),
--info-wlds, --validate-wlds with --json variants. Validator
catches id+name+texture required, expansion 0..3, level range
valid, weight=0 (in pool but never picked), and the practical
catch-all overlap warning when multiple mapId=0 screens share
overlapping level brackets (random pick becomes
non-deterministic).

Format graph: 62 → 63 binary formats. CLI flag count: 847
→ 854.
2026-05-09 20:59:25 -07:00

255 lines
9.2 KiB
C++

#include "cli_loading_screens_catalog.hpp"
#include "cli_arg_parse.hpp"
#include "cli_box_emitter.hpp"
#include "pipeline/wowee_loading_screens.hpp"
#include <nlohmann/json.hpp>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <string>
#include <vector>
namespace wowee {
namespace editor {
namespace cli {
namespace {
std::string stripWldsExt(std::string base) {
stripExt(base, ".wlds");
return base;
}
bool saveOrError(const wowee::pipeline::WoweeLoadingScreen& c,
const std::string& base, const char* cmd) {
if (!wowee::pipeline::WoweeLoadingScreenLoader::save(c, base)) {
std::fprintf(stderr, "%s: failed to save %s.wlds\n",
cmd, base.c_str());
return false;
}
return true;
}
void printGenSummary(const wowee::pipeline::WoweeLoadingScreen& c,
const std::string& base) {
std::printf("Wrote %s.wlds\n", base.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" screens : %zu\n", c.entries.size());
}
int handleGenStarter(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "StarterLoadingScreens";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWldsExt(base);
auto c = wowee::pipeline::WoweeLoadingScreenLoader::makeStarter(name);
if (!saveOrError(c, base, "gen-lds")) return 1;
printGenSummary(c, base);
return 0;
}
int handleGenInstances(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "InstanceLoadingScreens";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWldsExt(base);
auto c = wowee::pipeline::WoweeLoadingScreenLoader::makeInstances(name);
if (!saveOrError(c, base, "gen-lds-instances")) return 1;
printGenSummary(c, base);
return 0;
}
int handleGenRaidIntros(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "RaidIntroLoadingScreens";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWldsExt(base);
auto c = wowee::pipeline::WoweeLoadingScreenLoader::makeRaidIntros(name);
if (!saveOrError(c, base, "gen-lds-raid")) 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 = stripWldsExt(base);
if (!wowee::pipeline::WoweeLoadingScreenLoader::exists(base)) {
std::fprintf(stderr, "WLDS not found: %s.wlds\n", base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeLoadingScreenLoader::load(base);
if (jsonOut) {
nlohmann::json j;
j["wlds"] = base + ".wlds";
j["name"] = c.name;
j["count"] = c.entries.size();
nlohmann::json arr = nlohmann::json::array();
for (const auto& e : c.entries) {
arr.push_back({
{"screenId", e.screenId},
{"mapId", e.mapId},
{"name", e.name},
{"description", e.description},
{"texturePath", e.texturePath},
{"iconPath", e.iconPath},
{"attribution", e.attribution},
{"minLevel", e.minLevel},
{"maxLevel", e.maxLevel},
{"displayWeight", e.displayWeight},
{"expansionRequired", e.expansionRequired},
{"expansionRequiredName", wowee::pipeline::WoweeLoadingScreen::expansionGateName(e.expansionRequired)},
{"isAnimated", e.isAnimated},
{"isWideAspect", e.isWideAspect},
});
}
j["entries"] = arr;
std::printf("%s\n", j.dump(2).c_str());
return 0;
}
std::printf("WLDS: %s.wlds\n", base.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" screens : %zu\n", c.entries.size());
if (c.entries.empty()) return 0;
std::printf(" id map levels wt exp anim wide name\n");
for (const auto& e : c.entries) {
std::printf(" %4u %4u %3u-%3u %3u %-7s %u %u %s\n",
e.screenId, e.mapId,
e.minLevel, e.maxLevel,
e.displayWeight,
wowee::pipeline::WoweeLoadingScreen::expansionGateName(e.expansionRequired),
e.isAnimated, e.isWideAspect, 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 = stripWldsExt(base);
if (!wowee::pipeline::WoweeLoadingScreenLoader::exists(base)) {
std::fprintf(stderr,
"validate-wlds: WLDS not found: %s.wlds\n", base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeLoadingScreenLoader::load(base);
std::vector<std::string> errors;
std::vector<std::string> warnings;
if (c.entries.empty()) {
warnings.push_back("catalog has zero entries");
}
std::vector<uint32_t> idsSeen;
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.screenId);
if (!e.name.empty()) ctx += " " + e.name;
ctx += ")";
if (e.screenId == 0)
errors.push_back(ctx + ": screenId is 0");
if (e.name.empty())
errors.push_back(ctx + ": name is empty");
if (e.texturePath.empty())
errors.push_back(ctx + ": texturePath is empty "
"(screen has no image to display)");
if (e.expansionRequired > wowee::pipeline::WoweeLoadingScreen::TurtleWoW) {
errors.push_back(ctx + ": expansionRequired " +
std::to_string(e.expansionRequired) + " not in 0..3");
}
if (e.minLevel > e.maxLevel) {
errors.push_back(ctx + ": minLevel " +
std::to_string(e.minLevel) + " > maxLevel " +
std::to_string(e.maxLevel));
}
if (e.displayWeight == 0) {
warnings.push_back(ctx +
": displayWeight=0 (screen is in pool but never picked)");
}
// mapId=0 means catch-all — flag if there are
// multiple catch-all screens in the same level
// bracket, since the random pick becomes ambiguous.
if (e.mapId == 0 && c.entries.size() > 1) {
uint32_t conflicts = 0;
for (size_t m = 0; m < c.entries.size(); ++m) {
if (m == k) continue;
const auto& other = c.entries[m];
if (other.mapId != 0) continue;
// Overlap level brackets count as conflicts.
if (other.minLevel <= e.maxLevel &&
other.maxLevel >= e.minLevel) {
++conflicts;
}
}
if (conflicts > 0) {
warnings.push_back(ctx +
": catch-all screen (mapId=0) overlaps " +
std::to_string(conflicts) +
" other catch-all in same level bracket "
"— random pick is non-deterministic");
}
}
for (uint32_t prev : idsSeen) {
if (prev == e.screenId) {
errors.push_back(ctx + ": duplicate screenId");
break;
}
}
idsSeen.push_back(e.screenId);
}
bool ok = errors.empty();
if (jsonOut) {
nlohmann::json j;
j["wlds"] = base + ".wlds";
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-wlds: %s.wlds\n", base.c_str());
if (ok && warnings.empty()) {
std::printf(" OK — %zu screens, all screenIds unique, no overlap conflicts\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 handleLoadingScreensCatalog(int& i, int argc, char** argv,
int& outRc) {
if (std::strcmp(argv[i], "--gen-lds") == 0 && i + 1 < argc) {
outRc = handleGenStarter(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--gen-lds-instances") == 0 && i + 1 < argc) {
outRc = handleGenInstances(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--gen-lds-raid") == 0 && i + 1 < argc) {
outRc = handleGenRaidIntros(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--info-wlds") == 0 && i + 1 < argc) {
outRc = handleInfo(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--validate-wlds") == 0 && i + 1 < argc) {
outRc = handleValidate(i, argc, argv); return true;
}
return false;
}
} // namespace cli
} // namespace editor
} // namespace wowee