ship layout blueprints
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "toml.hpp"
|
||||
|
||||
#include "Rotation.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@@ -35,6 +37,14 @@ std::string requireString(NodeView node, const std::string& path)
|
||||
return *value;
|
||||
}
|
||||
|
||||
Rotation parseRotation(const std::string& s)
|
||||
{
|
||||
if (s == "east") { return Rotation::East; }
|
||||
if (s == "south") { return Rotation::South; }
|
||||
if (s == "west") { return Rotation::West; }
|
||||
return Rotation::North;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
BalancingConfig loadBalancingConfig(const std::string& path)
|
||||
@@ -119,6 +129,36 @@ BalancingConfig loadBalancingConfig(const std::string& path)
|
||||
requireInt((*shipTbl)["level"], sPrefix + ".level"));
|
||||
entry.count = static_cast<int>(
|
||||
requireInt((*shipTbl)["count"], sPrefix + ".count"));
|
||||
|
||||
const toml::array* modArray = (*shipTbl)["modules"].as_array();
|
||||
if (modArray && !modArray->empty())
|
||||
{
|
||||
ShipLayoutConfig layout;
|
||||
for (std::size_t mi = 0; mi < modArray->size(); ++mi)
|
||||
{
|
||||
const toml::table* modTbl = (*modArray)[mi].as_table();
|
||||
if (!modTbl) { continue; }
|
||||
|
||||
const std::optional<std::string> type =
|
||||
(*modTbl)["type"].value<std::string>();
|
||||
const std::optional<int64_t> x =
|
||||
(*modTbl)["x"].value<int64_t>();
|
||||
const std::optional<int64_t> y =
|
||||
(*modTbl)["y"].value<int64_t>();
|
||||
const std::optional<std::string> rotStr =
|
||||
(*modTbl)["rotation"].value<std::string>();
|
||||
if (!type || !x || !y || !rotStr) { continue; }
|
||||
|
||||
PlacedModule pm;
|
||||
pm.moduleId = *type;
|
||||
pm.position = QPoint(static_cast<int>(*x),
|
||||
static_cast<int>(*y));
|
||||
pm.rotation = parseRotation(*rotStr);
|
||||
layout.placedModules.push_back(std::move(pm));
|
||||
}
|
||||
entry.layout = std::move(layout);
|
||||
}
|
||||
|
||||
team.ships.push_back(entry);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user