tiledmap 多个objectgroup

This commit is contained in:
songhao 2019-05-10 14:13:20 +08:00
parent c9cfa04354
commit f66ba1b9a2

View File

@ -80,33 +80,35 @@ namespace f8
} }
} }
std::shared_ptr<a8::XObject> objgroup_node = xobj.At("child_node.objectgroup")->At(0); for (int group_id = 0; group_id < xobj.At("child_node.objectgroup")->Size(); group_id++) {
for (int i = 0; i < objgroup_node->At("child_node.object")->Size(); i++) { std::shared_ptr<a8::XObject> objgroup_node = xobj.At("child_node.objectgroup")->At(group_id);
std::shared_ptr<a8::XObject> object_node = objgroup_node->At("child_node.object")->At(i); for (int i = 0; i < objgroup_node->At("child_node.object")->Size(); i++) {
TiledObject object; std::shared_ptr<a8::XObject> 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(); for (int ii = 0; ii < object_node->At("attr_names")->Size(); ii++) {
object.prop_hash[attr_name] = object_node->At("attrs." + attr_name)->AsXValue(); 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<a8::XObject> 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<a8::XObject> prop_node = prop_nodes->At(j);
object.prop_hash[prop_node->At("attrs.name")->AsXValue()] = prop_node->At("attrs.value")->AsXValue();
}
} }
std::shared_ptr<a8::XObject> prop_nodes = object_node->At("child_node.properties")->At(0)->At("child_node.property");
for (int j = 0; j < prop_nodes->Size(); j++) { std::string object_name = object_node->At("attrs.name")->AsXValue();
std::shared_ptr<a8::XObject> prop_node = prop_nodes->At(j); auto itr = object_group_hash.find(object_name);
object.prop_hash[prop_node->At("attrs.name")->AsXValue()] = prop_node->At("attrs.value")->AsXValue(); if (itr != object_group_hash.end()) {
itr->second.push_back(object);
} }
} else
{
object_group_hash[object_name] = std::list<TiledObject>({ 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<TiledObject>({ object });
}
}
return true; return true;