diff --git a/data/maps/sample1.tmx b/data/maps/sample1.tmx index 9537802..d0f804d 100644 --- a/data/maps/sample1.tmx +++ b/data/maps/sample1.tmx @@ -31,6 +31,7 @@ + diff --git a/src/sagotmx/tmx_struct.h b/src/sagotmx/tmx_struct.h index bd9a02d..df785bc 100644 --- a/src/sagotmx/tmx_struct.h +++ b/src/sagotmx/tmx_struct.h @@ -241,6 +241,11 @@ struct TileLayer { TileLayerData data; }; +struct TileProperty { + std::string name; + std::string type; + std::string value; +}; struct TileObject { int id = 0; @@ -253,6 +258,7 @@ struct TileObject { bool isEllipse = false; bool isPoint = false; std::vector > polygon_points; + std::map properties; }; struct TileObjectGroup { @@ -411,6 +417,17 @@ inline TileMap string2tilemap(const std::string& tmx_content) { to.polygon_points.push_back(std::make_pair(x, y)); } } + rapidxml::xml_node<> * properties_node = object_node->first_node("properties"); + if (properties_node) { + for (rapidxml::xml_node<> * property_node = properties_node->first_node("property"); + property_node; property_node = property_node->next_sibling("property") ) { + TileProperty tp; + setValueFromAttribute(property_node, "name", tp.name); + setValueFromAttribute(property_node, "type", tp.type); + setValueFromAttribute(property_node, "value", tp.value); + to.properties[tp.name] = tp; + } + } group.objects.push_back(to); } m.object_groups.push_back(group); @@ -491,6 +508,18 @@ inline void xml_add_objectgroup(std::iostream& io, const TileMap& m, size_t obje } io << "\"/>\n"; } + if (to.properties.size() > 0) { + io << "\n"; + for (const auto& prop : to.properties) { + io << " 0) { + io << "type=\"" << prop.second.type << "\" "; + } + io << "value=\"" << prop.second.value << "\" "; + io << "/>\n"; + } + io << "\n"; + } io << "\n"; } io << "\n"; diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp index 6cebe7e..21561e2 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp @@ -425,6 +425,18 @@ void Game::Update() { data->lastUpdate = nowTime; data->gameRegion.physicsBox->Step(deltaTime / 1000.0f / 60.0f, velocityIterations, positionIterations); std::sort(data->gameRegion.placeables.begin(), data->gameRegion.placeables.end(), sort_placeable); + const std::vector& object_groups = data->gameRegion.world.tm.object_groups; + for (const auto& group : object_groups) { + for (const auto& item : group.objects) { + if (item.isEllipse) { + continue; + } + if (item.x < data->human->X && item.y < data->human->Y && item.width+item.x > data->human->X + && item.height+item.y > data->human->Y && item.type == "text") { + std::cout << "text\n"; + } + } + } if (data->human->X < 0) { ResetWorld(data->gameRegion.GetRegionX()-1, data->gameRegion.GetRegionY(), false); data->human->body->SetTransform(b2Vec2(data->gameRegion.world.tm.width, data->gameRegion.world.tm.height/2),data->human->body->GetAngle()) ;