extract loadBuildings into ConfigLoaderBuildings.cpp
Continues the ConfigLoader.cpp domain split. Pure move of loadBuildings; no domain-specific helpers to relocate here. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YHcUerKAZKWNvSKJxYKbnG
This commit is contained in:
@@ -22,6 +22,7 @@ SET(SRCS
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/Formula.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/Formula.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/ConfigLoader.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/ConfigLoader.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/ConfigLoaderWorld.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/ConfigLoaderWorld.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/ConfigLoaderBuildings.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/SurfaceMask.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/SurfaceMask.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/BlueprintSerializer.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/BlueprintSerializer.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/ShipLayoutBlueprintSerializer.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/ShipLayoutBlueprintSerializer.cpp
|
||||||
|
|||||||
@@ -91,55 +91,6 @@ std::vector<PlacedModule> parsePlacedModules(const toml::array& arr,
|
|||||||
|
|
||||||
// --- Per-file loaders -----------------------------------------------------
|
// --- Per-file loaders -----------------------------------------------------
|
||||||
|
|
||||||
BuildingsConfig ConfigLoader::loadBuildings(const std::string& path)
|
|
||||||
{
|
|
||||||
const std::string file = "buildings.toml";
|
|
||||||
toml::table tbl = parseFile(path, file);
|
|
||||||
|
|
||||||
BuildingsConfig cfg;
|
|
||||||
const toml::array& arr = requireArray(tbl["building"], file, "building");
|
|
||||||
|
|
||||||
for (std::size_t i = 0; i < arr.size(); ++i)
|
|
||||||
{
|
|
||||||
const std::string elemPath = "building[" + std::to_string(i) + "]";
|
|
||||||
const toml::table* bt = arr[i].as_table();
|
|
||||||
if (bt == nullptr)
|
|
||||||
{
|
|
||||||
throw makeError(file, elemPath, "not a table");
|
|
||||||
}
|
|
||||||
toml::table& mt = const_cast<toml::table&>(*bt);
|
|
||||||
|
|
||||||
BuildingDef def;
|
|
||||||
def.id = requireString(mt["id"], file, elemPath + ".id");
|
|
||||||
def.cost = static_cast<int>(requireInt(mt["cost"], file, elemPath + ".cost"));
|
|
||||||
def.playerPlaceable = requireBool(mt["player_placeable"], file, elemPath + ".player_placeable");
|
|
||||||
def.constructionTimeSeconds = requireDouble(mt["construction_time_seconds"], file, elemPath + ".construction_time_seconds");
|
|
||||||
def.surfaceMask = requireStringArray(mt["surface_mask"], file, elemPath + ".surface_mask");
|
|
||||||
|
|
||||||
if (mt.contains("output_buffer_capacity"))
|
|
||||||
{
|
|
||||||
def.outputBufferCapacity = static_cast<int>(
|
|
||||||
requireInt(mt["output_buffer_capacity"], file, elemPath + ".output_buffer_capacity"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mt.contains("tooltip"))
|
|
||||||
{
|
|
||||||
def.tooltip = requireString(mt["tooltip"], file, elemPath + ".tooltip");
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::optional<BuildingType> parsedType = parseBuildingType(def.id);
|
|
||||||
if (!parsedType)
|
|
||||||
{
|
|
||||||
throw makeError(file, elemPath + ".id", "unknown building id '" + def.id + "'");
|
|
||||||
}
|
|
||||||
def.type = *parsedType;
|
|
||||||
|
|
||||||
cfg.buildings.push_back(std::move(def));
|
|
||||||
}
|
|
||||||
|
|
||||||
return cfg;
|
|
||||||
}
|
|
||||||
|
|
||||||
RecipesConfig ConfigLoader::loadRecipes(const std::string& path)
|
RecipesConfig ConfigLoader::loadRecipes(const std::string& path)
|
||||||
{
|
{
|
||||||
const std::string file = "recipes.toml";
|
const std::string file = "recipes.toml";
|
||||||
|
|||||||
58
src/lib/config/ConfigLoaderBuildings.cpp
Normal file
58
src/lib/config/ConfigLoaderBuildings.cpp
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
#include "ConfigLoader.h"
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "toml.hpp"
|
||||||
|
|
||||||
|
#include "TomlHelpers.h"
|
||||||
|
|
||||||
|
BuildingsConfig ConfigLoader::loadBuildings(const std::string& path)
|
||||||
|
{
|
||||||
|
const std::string file = "buildings.toml";
|
||||||
|
toml::table tbl = parseFile(path, file);
|
||||||
|
|
||||||
|
BuildingsConfig cfg;
|
||||||
|
const toml::array& arr = requireArray(tbl["building"], file, "building");
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < arr.size(); ++i)
|
||||||
|
{
|
||||||
|
const std::string elemPath = "building[" + std::to_string(i) + "]";
|
||||||
|
const toml::table* bt = arr[i].as_table();
|
||||||
|
if (bt == nullptr)
|
||||||
|
{
|
||||||
|
throw makeError(file, elemPath, "not a table");
|
||||||
|
}
|
||||||
|
toml::table& mt = const_cast<toml::table&>(*bt);
|
||||||
|
|
||||||
|
BuildingDef def;
|
||||||
|
def.id = requireString(mt["id"], file, elemPath + ".id");
|
||||||
|
def.cost = static_cast<int>(requireInt(mt["cost"], file, elemPath + ".cost"));
|
||||||
|
def.playerPlaceable = requireBool(mt["player_placeable"], file, elemPath + ".player_placeable");
|
||||||
|
def.constructionTimeSeconds = requireDouble(mt["construction_time_seconds"], file, elemPath + ".construction_time_seconds");
|
||||||
|
def.surfaceMask = requireStringArray(mt["surface_mask"], file, elemPath + ".surface_mask");
|
||||||
|
|
||||||
|
if (mt.contains("output_buffer_capacity"))
|
||||||
|
{
|
||||||
|
def.outputBufferCapacity = static_cast<int>(
|
||||||
|
requireInt(mt["output_buffer_capacity"], file, elemPath + ".output_buffer_capacity"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mt.contains("tooltip"))
|
||||||
|
{
|
||||||
|
def.tooltip = requireString(mt["tooltip"], file, elemPath + ".tooltip");
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::optional<BuildingType> parsedType = parseBuildingType(def.id);
|
||||||
|
if (!parsedType)
|
||||||
|
{
|
||||||
|
throw makeError(file, elemPath + ".id", "unknown building id '" + def.id + "'");
|
||||||
|
}
|
||||||
|
def.type = *parsedType;
|
||||||
|
|
||||||
|
cfg.buildings.push_back(std::move(def));
|
||||||
|
}
|
||||||
|
|
||||||
|
return cfg;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user