Skip to content

Commit

Permalink
add missing Python API converter for allocated PP
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffthemedio committed Jun 30, 2023
1 parent 773627c commit 7cbf331
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion python/EmpireWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ namespace {
return out;
}

auto MapFlatSetFloatToMapSetFloat(const auto& in) -> std::map<std::set<int>, float>
{
std::map<std::set<int>, float> out;
std::transform(in.begin(), in.end(), std::inserter(out, out.end()),
[](auto set_float)
{ return std::pair{std::set<int>{set_float.first.begin(), set_float.first.end()},
set_float.second}; });
return out;
}

template <typename T, typename AoC>
std::vector<T> ToVec(const boost::container::flat_set<T, AoC>& in)
{ return std::vector<T>(in.begin(), in.end()); }
Expand Down Expand Up @@ -410,7 +420,7 @@ namespace FreeOrionPython {
.add_property("totalSpent", &ProductionQueue::TotalPPsSpent)
.add_property("empireID", &ProductionQueue::EmpireID)

.add_property("allocatedPP", make_function(&ProductionQueue::AllocatedPP, py::return_internal_reference<>()))
.add_property("allocatedPP", +[](const ProductionQueue& p) -> std::map<std::set<int>, float> { return MapFlatSetFloatToMapSetFloat(p.AllocatedPP()); })
;

////////////////////
Expand Down

0 comments on commit 7cbf331

Please sign in to comment.