MCPcopy Create free account
hub / github.com/The-Powder-Toy/The-Powder-Toy / GetNestedSaveIDs

Function GetNestedSaveIDs

src/client/GameSave.cpp:2773–2802  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2771}
2772
2773static std::set<int> GetNestedSaveIDs(const Bson &j)
2774{
2775 std::set<int> saveIDs;
2776 for (auto &[ key, member ] : j.As<Bson::Object>())
2777 {
2778 if (member.Is<int32_t>())
2779 {
2780 saveIDs.insert(member.As<int32_t>());
2781 }
2782 else if (member.Is<Bson::Array>())
2783 {
2784 for (auto &link : member.As<Bson::Array>())
2785 {
2786 // only supports objects and ints here because that is all we need
2787 if (link.Is<int32_t>())
2788 {
2789 saveIDs.insert(link.As<int32_t>());
2790 continue;
2791 }
2792 if (!link.Is<Bson::Object>())
2793 {
2794 continue;
2795 }
2796 auto nestedSaveIDs = GetNestedSaveIDs(link);
2797 saveIDs.insert(nestedSaveIDs.begin(), nestedSaveIDs.end());
2798 }
2799 }
2800 }
2801 return saveIDs;
2802}
2803
2804// converts a json object to bson
2805static void TrimAuthorsOut(Bson &b, int depth)

Callers 1

TrimAuthorsOutFunction · 0.85

Calls 2

beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected