extract loadUnlocks into ConfigLoaderUnlocks.cpp
Finishes the ConfigLoader.cpp domain split. ConfigLoader.cpp now holds only the cross-domain validateUnlocks pass and loadFromDirectory orchestrator, as intended — everything else lives in its own ConfigLoader<Domain>.cpp. Pure move; no logic change. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YHcUerKAZKWNvSKJxYKbnG
This commit is contained in:
@@ -27,6 +27,7 @@ SET(SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ConfigLoaderShips.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ConfigLoaderStations.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ConfigLoaderModules.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ConfigLoaderUnlocks.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/SurfaceMask.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BlueprintSerializer.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ShipLayoutBlueprintSerializer.cpp
|
||||
|
||||
@@ -1,72 +1,11 @@
|
||||
#include "ConfigLoader.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "toml.hpp"
|
||||
|
||||
#include "TomlHelpers.h"
|
||||
|
||||
// --- Per-file loaders -----------------------------------------------------
|
||||
|
||||
UnlocksConfig ConfigLoader::loadUnlocks(const std::string& path)
|
||||
{
|
||||
const std::string file = "unlocks.toml";
|
||||
toml::table tbl = parseFile(path, file);
|
||||
|
||||
UnlocksConfig cfg;
|
||||
if (!tbl.contains("unlock"))
|
||||
{
|
||||
return cfg;
|
||||
}
|
||||
|
||||
const toml::array& arr = requireArray(tbl["unlock"], file, "unlock");
|
||||
|
||||
for (std::size_t i = 0; i < arr.size(); ++i)
|
||||
{
|
||||
const std::string elemPath = "unlock[" + std::to_string(i) + "]";
|
||||
const toml::table* ut = arr[i].as_table();
|
||||
if (ut == nullptr)
|
||||
{
|
||||
throw makeError(file, elemPath, "not a table");
|
||||
}
|
||||
toml::table& mt = const_cast<toml::table&>(*ut);
|
||||
|
||||
UnlockGroupDef def;
|
||||
def.id = requireString(mt["id"], file, elemPath + ".id");
|
||||
def.stationLevel = static_cast<int>(
|
||||
requireInt(mt["station_level"], file, elemPath + ".station_level"));
|
||||
if (mt.contains("requires"))
|
||||
{
|
||||
def.requiredGroupIds = requireStringArray(mt["requires"], file, elemPath + ".requires");
|
||||
}
|
||||
if (mt.contains("ships"))
|
||||
{
|
||||
def.ships = requireStringArray(mt["ships"], file, elemPath + ".ships");
|
||||
}
|
||||
if (mt.contains("modules"))
|
||||
{
|
||||
def.modules = requireStringArray(mt["modules"], file, elemPath + ".modules");
|
||||
}
|
||||
if (mt.contains("buildings"))
|
||||
{
|
||||
def.buildings = requireStringArray(mt["buildings"], file, elemPath + ".buildings");
|
||||
}
|
||||
if (mt.contains("recipes"))
|
||||
{
|
||||
def.recipes = requireStringArray(mt["recipes"], file, elemPath + ".recipes");
|
||||
}
|
||||
|
||||
cfg.groups.push_back(std::move(def));
|
||||
}
|
||||
|
||||
return cfg;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
|
||||
62
src/lib/config/ConfigLoaderUnlocks.cpp
Normal file
62
src/lib/config/ConfigLoaderUnlocks.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "ConfigLoader.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "toml.hpp"
|
||||
|
||||
#include "TomlHelpers.h"
|
||||
|
||||
UnlocksConfig ConfigLoader::loadUnlocks(const std::string& path)
|
||||
{
|
||||
const std::string file = "unlocks.toml";
|
||||
toml::table tbl = parseFile(path, file);
|
||||
|
||||
UnlocksConfig cfg;
|
||||
if (!tbl.contains("unlock"))
|
||||
{
|
||||
return cfg;
|
||||
}
|
||||
|
||||
const toml::array& arr = requireArray(tbl["unlock"], file, "unlock");
|
||||
|
||||
for (std::size_t i = 0; i < arr.size(); ++i)
|
||||
{
|
||||
const std::string elemPath = "unlock[" + std::to_string(i) + "]";
|
||||
const toml::table* ut = arr[i].as_table();
|
||||
if (ut == nullptr)
|
||||
{
|
||||
throw makeError(file, elemPath, "not a table");
|
||||
}
|
||||
toml::table& mt = const_cast<toml::table&>(*ut);
|
||||
|
||||
UnlockGroupDef def;
|
||||
def.id = requireString(mt["id"], file, elemPath + ".id");
|
||||
def.stationLevel = static_cast<int>(
|
||||
requireInt(mt["station_level"], file, elemPath + ".station_level"));
|
||||
if (mt.contains("requires"))
|
||||
{
|
||||
def.requiredGroupIds = requireStringArray(mt["requires"], file, elemPath + ".requires");
|
||||
}
|
||||
if (mt.contains("ships"))
|
||||
{
|
||||
def.ships = requireStringArray(mt["ships"], file, elemPath + ".ships");
|
||||
}
|
||||
if (mt.contains("modules"))
|
||||
{
|
||||
def.modules = requireStringArray(mt["modules"], file, elemPath + ".modules");
|
||||
}
|
||||
if (mt.contains("buildings"))
|
||||
{
|
||||
def.buildings = requireStringArray(mt["buildings"], file, elemPath + ".buildings");
|
||||
}
|
||||
if (mt.contains("recipes"))
|
||||
{
|
||||
def.recipes = requireStringArray(mt["recipes"], file, elemPath + ".recipes");
|
||||
}
|
||||
|
||||
cfg.groups.push_back(std::move(def));
|
||||
}
|
||||
|
||||
return cfg;
|
||||
}
|
||||
Reference in New Issue
Block a user