diff --git a/cpp/tiledmap.cc b/cpp/tiledmap.cc index 2f27c71..3539d68 100644 --- a/cpp/tiledmap.cc +++ b/cpp/tiledmap.cc @@ -80,33 +80,35 @@ namespace f8 } } - std::shared_ptr objgroup_node = xobj.At("child_node.objectgroup")->At(0); - for (int i = 0; i < objgroup_node->At("child_node.object")->Size(); i++) { - std::shared_ptr object_node = objgroup_node->At("child_node.object")->At(i); - TiledObject object; - { - for (int ii = 0; ii < object_node->At("attr_names")->Size(); ii++) { - std::string attr_name = object_node->At("attr_names")->At(ii)->AsXValue(); - object.prop_hash[attr_name] = object_node->At("attrs." + attr_name)->AsXValue(); - } - std::shared_ptr prop_nodes = object_node->At("child_node.properties")->At(0)->At("child_node.property"); - for (int j = 0; j < prop_nodes->Size(); j++) { - std::shared_ptr prop_node = prop_nodes->At(j); - object.prop_hash[prop_node->At("attrs.name")->AsXValue()] = prop_node->At("attrs.value")->AsXValue(); + for (int group_id = 0; group_id < xobj.At("child_node.objectgroup")->Size(); group_id++) { + std::shared_ptr objgroup_node = xobj.At("child_node.objectgroup")->At(group_id); + for (int i = 0; i < objgroup_node->At("child_node.object")->Size(); i++) { + std::shared_ptr object_node = objgroup_node->At("child_node.object")->At(i); + TiledObject object; + { + for (int ii = 0; ii < object_node->At("attr_names")->Size(); ii++) { + std::string attr_name = object_node->At("attr_names")->At(ii)->AsXValue(); + object.prop_hash[attr_name] = object_node->At("attrs." + attr_name)->AsXValue(); + } + std::shared_ptr prop_nodes = object_node->At("child_node.properties")->At(0)->At("child_node.property"); + for (int j = 0; j < prop_nodes->Size(); j++) { + std::shared_ptr prop_node = prop_nodes->At(j); + object.prop_hash[prop_node->At("attrs.name")->AsXValue()] = prop_node->At("attrs.value")->AsXValue(); + } } + + std::string object_name = object_node->At("attrs.name")->AsXValue(); + auto itr = object_group_hash.find(object_name); + if (itr != object_group_hash.end()) { + itr->second.push_back(object); + } + else + { + object_group_hash[object_name] = std::list({ object }); + } + } - - std::string object_name = object_node->At("attrs.name")->AsXValue(); - auto itr = object_group_hash.find(object_name); - if (itr != object_group_hash.end()) { - itr->second.push_back(object); - } - else - { - object_group_hash[object_name] = std::list({ object }); - } - - } + } return true;