The names are generic (makeError, requireInt, parseFile), and at global scope with external linkage they would form an overload set with the same-named anonymous-namespace helpers in VisualsLoader.cpp and BalancingConfig.cpp the moment either file includes TomlHelpers.h — silently, since the signatures differ. Namespacing keeps that door shut. Call sites are qualified explicitly rather than pulled in with a using directive, matching how utility::getRandomInt and friends are already called. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YHcUerKAZKWNvSKJxYKbnG
63 lines
1.9 KiB
C++
63 lines
1.9 KiB
C++
#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 = utility::parseFile(path, file);
|
|
|
|
UnlocksConfig cfg;
|
|
if (!tbl.contains("unlock"))
|
|
{
|
|
return cfg;
|
|
}
|
|
|
|
const toml::array& arr = utility::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 utility::makeError(file, elemPath, "not a table");
|
|
}
|
|
toml::table& mt = const_cast<toml::table&>(*ut);
|
|
|
|
UnlockGroupDef def;
|
|
def.id = utility::requireString(mt["id"], file, elemPath + ".id");
|
|
def.stationLevel = static_cast<int>(
|
|
utility::requireInt(mt["station_level"], file, elemPath + ".station_level"));
|
|
if (mt.contains("requires"))
|
|
{
|
|
def.requiredGroupIds = utility::requireStringArray(mt["requires"], file, elemPath + ".requires");
|
|
}
|
|
if (mt.contains("ships"))
|
|
{
|
|
def.ships = utility::requireStringArray(mt["ships"], file, elemPath + ".ships");
|
|
}
|
|
if (mt.contains("modules"))
|
|
{
|
|
def.modules = utility::requireStringArray(mt["modules"], file, elemPath + ".modules");
|
|
}
|
|
if (mt.contains("buildings"))
|
|
{
|
|
def.buildings = utility::requireStringArray(mt["buildings"], file, elemPath + ".buildings");
|
|
}
|
|
if (mt.contains("recipes"))
|
|
{
|
|
def.recipes = utility::requireStringArray(mt["recipes"], file, elemPath + ".recipes");
|
|
}
|
|
|
|
cfg.groups.push_back(std::move(def));
|
|
}
|
|
|
|
return cfg;
|
|
}
|