feat(wob): tryLoadByGamePath helper, used by editor + terrain_manager

Mirrors the WOM tryLoadByGamePath API: probes custom_zones/buildings/ +
output/buildings/ by default, with optional extraPrefixes (e.g. per-zone
output/<map>/buildings/) checked first. Both the editor and the main
game's terrain_manager now use the helper, removing duplicate inline
lookup loops in two more places.
This commit is contained in:
Kelsi 2026-05-06 04:10:12 -07:00
parent f36309a96f
commit db068d480b
4 changed files with 48 additions and 31 deletions

View file

@ -67,6 +67,15 @@ public:
// Convert WMOModel to WOB (for editor export)
static WoweeBuilding fromWMO(const class WMOModel& wmo, const std::string& name = "");
// Convenience: try loading <path-without-ext>.wob from the standard editor
// search paths (custom_zones/buildings/, output/buildings/). `extraPrefixes`
// are tried before the defaults — pass per-zone roots like
// {"output/<map>/buildings/", "custom_zones/<map>/buildings/"} when the
// caller knows the active zone. Returns valid building on hit.
static WoweeBuilding tryLoadByGamePath(
const std::string& gamePath,
const std::vector<std::string>& extraPrefixes = {});
};
} // namespace pipeline

View file

@ -431,5 +431,29 @@ WoweeBuilding WoweeBuildingLoader::fromWMO(const WMOModel& wmo, const std::strin
return bld;
}
WoweeBuilding WoweeBuildingLoader::tryLoadByGamePath(
const std::string& gamePath,
const std::vector<std::string>& extraPrefixes) {
std::string base = gamePath;
auto dot = base.rfind('.');
if (dot != std::string::npos) base = base.substr(0, dot);
std::replace(base.begin(), base.end(), '\\', '/');
auto tryPrefix = [&](const std::string& prefix) -> WoweeBuilding {
std::string full = prefix + base;
if (exists(full)) {
auto wob = load(full);
if (wob.isValid()) return wob;
}
return {};
};
for (const auto& p : extraPrefixes) {
if (auto w = tryPrefix(p); w.isValid()) return w;
}
for (const char* p : {"custom_zones/buildings/", "output/buildings/"}) {
if (auto w = tryPrefix(p); w.isValid()) return w;
}
return {};
}
} // namespace pipeline
} // namespace wowee

View file

@ -614,22 +614,17 @@ std::shared_ptr<PendingTile> TerrainManager::prepareTile(int x, int y) {
bool wobLoaded = false;
pipeline::WMOModel wmoModel;
{
std::string wobBase = wmoPath;
auto wobDot = wobBase.rfind('.');
if (wobDot != std::string::npos) wobBase = wobBase.substr(0, wobDot);
std::replace(wobBase.begin(), wobBase.end(), '\\', '/');
std::vector<std::string> wobPrefixes = {"custom_zones/buildings/", "output/" + mapName + "/buildings/"};
for (const auto& prefix : wobPrefixes) {
if (pipeline::WoweeBuildingLoader::exists(prefix + wobBase)) {
auto wob = pipeline::WoweeBuildingLoader::load(prefix + wobBase);
if (wob.isValid()) {
if (pipeline::WoweeBuildingLoader::toWMOModel(wob, wmoModel)) {
LOG_INFO("Loaded WOB building: ", prefix + wobBase);
wobLoaded = true;
}
}
break;
}
// Per-zone overrides win over global custom_zones/ overrides.
std::vector<std::string> extraPrefixes = {
"output/" + mapName + "/buildings/",
"custom_zones/" + mapName + "/buildings/",
};
auto wob = pipeline::WoweeBuildingLoader::tryLoadByGamePath(
wmoPath, extraPrefixes);
if (wob.isValid() &&
pipeline::WoweeBuildingLoader::toWMOModel(wob, wmoModel)) {
LOG_INFO("Loaded WOB building: ", wmoPath);
wobLoaded = true;
}
}

View file

@ -210,21 +210,10 @@ void EditorViewport::rebuildObjects(const std::vector<PlacedObject>& objects,
bool loaded = false;
// Try WOB open format first (replaces proprietary WMO when available)
{
std::string wobBase = obj.path;
auto wobDot = wobBase.rfind('.');
if (wobDot != std::string::npos) wobBase = wobBase.substr(0, wobDot);
std::replace(wobBase.begin(), wobBase.end(), '\\', '/');
for (const char* prefix : {"custom_zones/buildings/", "output/buildings/"}) {
if (pipeline::WoweeBuildingLoader::exists(std::string(prefix) + wobBase)) {
auto wob = pipeline::WoweeBuildingLoader::load(std::string(prefix) + wobBase);
if (wob.isValid() &&
pipeline::WoweeBuildingLoader::toWMOModel(wob, model)) {
loaded = true;
break;
}
}
}
if (auto wob = pipeline::WoweeBuildingLoader::tryLoadByGamePath(obj.path);
wob.isValid() &&
pipeline::WoweeBuildingLoader::toWMOModel(wob, model)) {
loaded = true;
}
if (!loaded) {