diff --git a/cpp/tiledmap.cc b/cpp/tiledmap.cc new file mode 100644 index 0000000..bc90b77 --- /dev/null +++ b/cpp/tiledmap.cc @@ -0,0 +1,41 @@ +#include + +#include "tiledmap.h" + +a8::XValue TiledObject::GetProperty(const std::string& prop_name) +{ + auto itr = prop_hash.find(prop_name); + return itr == prop_hash.end() ? itr->second : a8::XValue(); +} + +bool TiledObject::HasProperty(const std::string& prop_name) +{ + auto itr = prop_hash.find(prop_name); + return itr != prop_hash.end(); +} + + +a8::XValue TiledLayer::GetProperty(const std::string& prop_name) +{ + auto itr = prop_hash.find(prop_name); + return itr != prop_hash.end() ? itr->second : a8::XValue(); +} + +bool TiledLayer::HasProperty(const std::string& prop_name) +{ + auto itr = prop_hash.find(prop_name); + return itr != prop_hash.end(); +} + +bool TiledMap::LoadTmxFile(const std::string& filename) +{ + a8::XObject xobj; + xobj.ReadFromXmlFile(filename); + return true; +} + +std::list* TiledMap::GetObjectGroup(const std::string& object_class_name) +{ + auto itr = object_group_hash.find(object_class_name); + return itr != object_group_hash.end() ? &itr->second : nullptr; +} diff --git a/cpp/tiledmap.h b/cpp/tiledmap.h new file mode 100644 index 0000000..a70f0f1 --- /dev/null +++ b/cpp/tiledmap.h @@ -0,0 +1,38 @@ +#pragma once + +class TiledObject +{ + public: + a8::XValue GetProperty(const std::string& prop_name); + bool HasProperty(const std::string& prop_name); + + private: + std::map prop_hash; +}; + +class TiledLayer +{ + public: + + a8::XValue GetProperty(const std::string& prop_name); + bool HasProperty(const std::string& prop_name); + + private: + std::map prop_hash; +}; + +class TiledMap +{ + public: + TiledLayer* ground_layer = nullptr; + std::list speed_layers; + int map_size = 0; //瓦片地图的尺寸。(以瓦片数量为单位) + int tile_size = 0; //瓦片的尺寸。(以像素点为单位) + + bool LoadTmxFile(const std::string& filename); + std::list* GetObjectGroup(const std::string& object_class_name); + + private: + std::map> object_group_hash; + +};