mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-09 18:43:51 +00:00
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:
parent
f36309a96f
commit
db068d480b
4 changed files with 48 additions and 31 deletions
|
|
@ -67,6 +67,15 @@ public:
|
||||||
|
|
||||||
// Convert WMOModel to WOB (for editor export)
|
// Convert WMOModel to WOB (for editor export)
|
||||||
static WoweeBuilding fromWMO(const class WMOModel& wmo, const std::string& name = "");
|
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
|
} // namespace pipeline
|
||||||
|
|
|
||||||
|
|
@ -431,5 +431,29 @@ WoweeBuilding WoweeBuildingLoader::fromWMO(const WMOModel& wmo, const std::strin
|
||||||
return bld;
|
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 pipeline
|
||||||
} // namespace wowee
|
} // namespace wowee
|
||||||
|
|
|
||||||
|
|
@ -614,22 +614,17 @@ std::shared_ptr<PendingTile> TerrainManager::prepareTile(int x, int y) {
|
||||||
bool wobLoaded = false;
|
bool wobLoaded = false;
|
||||||
pipeline::WMOModel wmoModel;
|
pipeline::WMOModel wmoModel;
|
||||||
{
|
{
|
||||||
std::string wobBase = wmoPath;
|
// Per-zone overrides win over global custom_zones/ overrides.
|
||||||
auto wobDot = wobBase.rfind('.');
|
std::vector<std::string> extraPrefixes = {
|
||||||
if (wobDot != std::string::npos) wobBase = wobBase.substr(0, wobDot);
|
"output/" + mapName + "/buildings/",
|
||||||
std::replace(wobBase.begin(), wobBase.end(), '\\', '/');
|
"custom_zones/" + mapName + "/buildings/",
|
||||||
std::vector<std::string> wobPrefixes = {"custom_zones/buildings/", "output/" + mapName + "/buildings/"};
|
};
|
||||||
for (const auto& prefix : wobPrefixes) {
|
auto wob = pipeline::WoweeBuildingLoader::tryLoadByGamePath(
|
||||||
if (pipeline::WoweeBuildingLoader::exists(prefix + wobBase)) {
|
wmoPath, extraPrefixes);
|
||||||
auto wob = pipeline::WoweeBuildingLoader::load(prefix + wobBase);
|
if (wob.isValid() &&
|
||||||
if (wob.isValid()) {
|
pipeline::WoweeBuildingLoader::toWMOModel(wob, wmoModel)) {
|
||||||
if (pipeline::WoweeBuildingLoader::toWMOModel(wob, wmoModel)) {
|
LOG_INFO("Loaded WOB building: ", wmoPath);
|
||||||
LOG_INFO("Loaded WOB building: ", prefix + wobBase);
|
wobLoaded = true;
|
||||||
wobLoaded = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -210,21 +210,10 @@ void EditorViewport::rebuildObjects(const std::vector<PlacedObject>& objects,
|
||||||
bool loaded = false;
|
bool loaded = false;
|
||||||
|
|
||||||
// Try WOB open format first (replaces proprietary WMO when available)
|
// Try WOB open format first (replaces proprietary WMO when available)
|
||||||
{
|
if (auto wob = pipeline::WoweeBuildingLoader::tryLoadByGamePath(obj.path);
|
||||||
std::string wobBase = obj.path;
|
wob.isValid() &&
|
||||||
auto wobDot = wobBase.rfind('.');
|
pipeline::WoweeBuildingLoader::toWMOModel(wob, model)) {
|
||||||
if (wobDot != std::string::npos) wobBase = wobBase.substr(0, wobDot);
|
loaded = true;
|
||||||
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 (!loaded) {
|
if (!loaded) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue