2026-05-05 10:01:05 -07:00
|
|
|
#include "pipeline/custom_zone_discovery.hpp"
|
|
|
|
|
#include "core/logger.hpp"
|
2026-05-05 13:10:07 -07:00
|
|
|
#include <nlohmann/json.hpp>
|
2026-05-05 10:01:05 -07:00
|
|
|
#include <fstream>
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
|
|
|
|
|
namespace wowee {
|
|
|
|
|
namespace pipeline {
|
|
|
|
|
|
|
|
|
|
std::vector<CustomZoneInfo> CustomZoneDiscovery::scan(const std::vector<std::string>& searchPaths) {
|
|
|
|
|
std::vector<CustomZoneInfo> results;
|
|
|
|
|
for (const auto& path : searchPaths) {
|
|
|
|
|
auto found = scanDirectory(path);
|
|
|
|
|
results.insert(results.end(), found.begin(), found.end());
|
|
|
|
|
}
|
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<CustomZoneInfo> CustomZoneDiscovery::scanDirectory(const std::string& path) {
|
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
|
std::vector<CustomZoneInfo> results;
|
|
|
|
|
|
|
|
|
|
if (!fs::exists(path)) return results;
|
|
|
|
|
|
|
|
|
|
for (auto& entry : fs::directory_iterator(path)) {
|
|
|
|
|
if (!entry.is_directory()) continue;
|
|
|
|
|
|
|
|
|
|
std::string zoneJson = entry.path().string() + "/zone.json";
|
|
|
|
|
if (!fs::exists(zoneJson)) continue;
|
|
|
|
|
|
|
|
|
|
std::ifstream f(zoneJson);
|
|
|
|
|
if (!f) continue;
|
2026-05-05 13:10:07 -07:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
auto j = nlohmann::json::parse(f);
|
|
|
|
|
|
|
|
|
|
CustomZoneInfo info;
|
|
|
|
|
info.name = j.value("mapName", "");
|
|
|
|
|
if (info.name.empty()) info.name = j.value("name", "");
|
|
|
|
|
info.author = j.value("author", "");
|
|
|
|
|
info.description = j.value("description", "");
|
|
|
|
|
info.mapId = j.value("mapId", 9000u);
|
|
|
|
|
info.directory = entry.path().string();
|
|
|
|
|
info.hasCreatures = j.value("hasCreatures", false) ||
|
|
|
|
|
fs::exists(entry.path().string() + "/creatures.json");
|
|
|
|
|
info.hasQuests = fs::exists(entry.path().string() + "/quests.json");
|
|
|
|
|
|
|
|
|
|
if (j.contains("tiles") && j["tiles"].is_array()) {
|
|
|
|
|
for (const auto& t : j["tiles"]) {
|
|
|
|
|
if (t.is_array() && t.size() >= 2)
|
|
|
|
|
info.tiles.push_back({t[0].get<int>(), t[1].get<int>()});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!info.name.empty()) {
|
|
|
|
|
results.push_back(info);
|
|
|
|
|
LOG_INFO("Discovered custom zone: ", info.name, " in ", info.directory);
|
|
|
|
|
}
|
|
|
|
|
} catch (const std::exception& e) {
|
|
|
|
|
LOG_WARNING("Failed to parse zone.json in ", entry.path().string(), ": ", e.what());
|
2026-05-05 10:01:05 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace pipeline
|
|
|
|
|
} // namespace wowee
|