Skip to content

Commit 902bfaa

Browse files
committed
use ArrayIndex for property getter
1 parent 03b793d commit 902bfaa

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

libsave/include/SatisfactorySave/GameTypes/Properties/Base/PropertyList.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@ namespace SatisfactorySave {
1919

2020
void serialize(Archive& ar);
2121

22-
[[nodiscard]] inline const std::shared_ptr<Property>& getPtr(const std::string& name) const {
22+
[[nodiscard]] inline const std::shared_ptr<Property>& getPtr(const std::string& name,
23+
int32_t arrayIndex = 0) const {
2324
for (const auto& p : *this) {
24-
if (p->Name() == name) {
25+
if (p->Name() == name && p->ArrayIndex() == arrayIndex) {
2526
return p;
2627
}
2728
}
28-
throw std::runtime_error("Property name invalid: " + name);
29+
throw std::runtime_error("Property not found: " + name + "[" + std::to_string(arrayIndex) + "]");
2930
}
3031

3132
template<typename T>
32-
inline T& get(const std::string& name) const {
33-
T* property = dynamic_cast<T*>(getPtr(name).get());
33+
inline T& get(const std::string& name, int32_t arrayIndex = 0) const {
34+
T* property = dynamic_cast<T*>(getPtr(name, arrayIndex).get());
3435
if (property != nullptr) {
3536
return *property;
3637
}

libsavepy/src/GameTypes/Properties.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ void init_GameTypes_Properties(py::module_& m) {
4040

4141
py::bind_vector<s::PropertyList, py::smart_holder>(m, "PropertyList")
4242
.def("get",
43-
[](s::PropertyList& l, const std::string& name) -> std::shared_ptr<s::Property> {
44-
return l.getPtr(name);
45-
});
43+
[](s::PropertyList& l, const std::string& name, int32_t arrayIndex) -> std::shared_ptr<s::Property> {
44+
return l.getPtr(name, arrayIndex);
45+
},
46+
py::arg("name"), py::arg("arrayIndex") = 0);
4647

4748
py::classh<s::ArrayProperty, s::Property>(m, "ArrayProperty")
4849
.def(py::init<>())

map/src/MapWindow/UI/ObjectWidgets.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,11 @@ bool Satisfactory3DMap::UI::EditorUniqueNetIdRepl(const char* label, s::FUniqueN
358358
}
359359

360360
bool Satisfactory3DMap::UI::EditorProperty(s::Property& p, const EventContext& ctx) {
361-
const bool open = EditorTreeNode(p.Name().toString().c_str(), ImGuiTreeNodeFlags_DefaultOpen);
361+
std::string name = p.Name().toString();
362+
if (p.ArrayIndex() > 0) {
363+
name += "[" + std::to_string(p.ArrayIndex()) + "]";
364+
}
365+
const bool open = EditorTreeNode(name.c_str(), ImGuiTreeNodeFlags_DefaultOpen);
362366
ImGui::TableNextColumn();
363367
ImGui::TextDisabled("%s", p.Type().toString().c_str());
364368
if (open) {

0 commit comments

Comments
 (0)