diff --git a/src/lib/config/CMakeLists.txt b/src/lib/config/CMakeLists.txt index 7dbd62f..b46b91d 100644 --- a/src/lib/config/CMakeLists.txt +++ b/src/lib/config/CMakeLists.txt @@ -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 diff --git a/src/lib/config/ConfigLoader.cpp b/src/lib/config/ConfigLoader.cpp index 9558616..522921f 100644 --- a/src/lib/config/ConfigLoader.cpp +++ b/src/lib/config/ConfigLoader.cpp @@ -1,72 +1,11 @@ #include "ConfigLoader.h" -#include -#include #include #include -#include #include -#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(*ut); - - UnlockGroupDef def; - def.id = requireString(mt["id"], file, elemPath + ".id"); - def.stationLevel = static_cast( - 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 { diff --git a/src/lib/config/ConfigLoaderUnlocks.cpp b/src/lib/config/ConfigLoaderUnlocks.cpp new file mode 100644 index 0000000..eb6442e --- /dev/null +++ b/src/lib/config/ConfigLoaderUnlocks.cpp @@ -0,0 +1,62 @@ +#include "ConfigLoader.h" + +#include +#include + +#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(*ut); + + UnlockGroupDef def; + def.id = requireString(mt["id"], file, elemPath + ".id"); + def.stationLevel = static_cast( + 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; +}