TileMapDefs2D.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. //
  2. // Copyright (c) 2008-2014 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "RefCounted.h"
  24. #include "Sprite2D.h"
  25. namespace Urho3D
  26. {
  27. class XMLElement;
  28. /// Orientation.
  29. enum Orientation2D
  30. {
  31. /// Orthogonal.
  32. O_ORTHOGONAL = 0,
  33. /// Isometric.
  34. O_ISOMETRIC,
  35. /// Staggered.
  36. O_STAGGERED
  37. };
  38. /// Tile map infomation.
  39. struct URHO3D_API TileMapInfo2D
  40. {
  41. /// Orientation.
  42. Orientation2D orientation_;
  43. /// Width.
  44. int width_;
  45. /// Height.
  46. int height_;
  47. /// Tile width.
  48. float tileWidth_;
  49. /// Tile height.
  50. float tileHeight_;
  51. /// Return map width.
  52. float GetMapWidth() const;
  53. /// return map height.
  54. float GetMapHeight() const;
  55. /// Convert tmx position to Urho position.
  56. Vector2 ConvertPosition(const Vector2& position) const;
  57. /// Convert tile index to position.
  58. Vector2 TileIndexToPosition(int x, int y) const;
  59. /// Convert position to tile index, if out of map return false.
  60. bool PositionToTileIndex(int& x, int& y, const Vector2& positon) const;
  61. };
  62. /// Tile map layer type.
  63. enum TileMapLayerType2D
  64. {
  65. /// Tile layer.
  66. LT_TILE_LAYER = 0,
  67. /// Object group.
  68. LT_OBJECT_GROUP,
  69. /// Image layer.
  70. LT_IMAGE_LAYER,
  71. /// Invalid.
  72. LT_INVALID = 0xffff
  73. };
  74. /// Tile map object type.
  75. enum TileMapObjectType2D
  76. {
  77. /// Rectangle.
  78. OT_RECTANGLE = 0,
  79. /// Ellipse.
  80. OT_ELLIPSE,
  81. /// Polygon.
  82. OT_POLYGON,
  83. /// Polyline.
  84. OT_POLYLINE,
  85. /// Tile.
  86. OT_TILE,
  87. /// Invalid.
  88. OT_INVALID = 0xffff
  89. };
  90. /// Property set.
  91. class URHO3D_API PropertySet2D : public RefCounted
  92. {
  93. public:
  94. PropertySet2D();
  95. virtual ~PropertySet2D();
  96. /// Load from XML element.
  97. void Load(const XMLElement& element);
  98. /// Return has property.
  99. bool HasProperty(const String& name) const;
  100. /// Return property value.
  101. const String& GetProperty(const String& name) const;
  102. protected:
  103. /// Property name to property value mapping.
  104. HashMap<String, String> nameToValueMapping_;
  105. };
  106. /// Tile define.
  107. class URHO3D_API Tile2D : public RefCounted
  108. {
  109. public:
  110. /// Construct.
  111. Tile2D();
  112. /// Return gid.
  113. int GetGid() const { return gid_; }
  114. /// Return sprite.
  115. Sprite2D* GetSprite() const;
  116. /// Return has property.
  117. bool HasProperty(const String& name) const;
  118. /// Return property.
  119. const String& GetProperty(const String& name) const;
  120. private:
  121. friend class TmxTileLayer2D;
  122. /// Gid.
  123. int gid_;
  124. /// Sprite.
  125. SharedPtr<Sprite2D> sprite_;
  126. /// Property set.
  127. SharedPtr<PropertySet2D> propertySet_;
  128. };
  129. /// Tile map object.
  130. class URHO3D_API TileMapObject2D : public RefCounted
  131. {
  132. public:
  133. TileMapObject2D();
  134. /// Return type.
  135. TileMapObjectType2D GetObjectType() const { return objectType_; }
  136. /// Return name.
  137. const String& GetName() const { return name_; }
  138. /// Return type.
  139. const String& GetType() const { return type_; }
  140. /// Return position.
  141. const Vector2& GetPosition() const { return position_; }
  142. /// Return size (for rectangle and ellipse).
  143. const Vector2& GetSize() const { return size_; }
  144. /// Return number of points (use for script).
  145. unsigned GetNumPoints() const;
  146. /// Return point at index (use for script).
  147. const Vector2& GetPoint(unsigned index) const;
  148. /// Return tile Gid.
  149. int GetTileGid() const { return gid_; }
  150. /// Return tile sprite.
  151. Sprite2D* GetTileSprite() const;
  152. /// Return has property.
  153. bool HasProperty(const String& name) const;
  154. /// Return property value.
  155. const String& GetProperty(const String& name) const;
  156. private:
  157. friend class TmxObjectGroup2D;
  158. /// Object type.
  159. TileMapObjectType2D objectType_;
  160. /// Name.
  161. String name_;
  162. /// Type.
  163. String type_;
  164. /// Position.
  165. Vector2 position_;
  166. /// Size (for rectangle and ellipse).
  167. Vector2 size_;
  168. /// Points(for polygon and polyline).
  169. Vector<Vector2> points_;
  170. /// Gid (for tile).
  171. int gid_;
  172. /// Sprite (for tile).
  173. SharedPtr<Sprite2D> sprite_;
  174. /// Property set.
  175. SharedPtr<PropertySet2D> propertySet_;
  176. };
  177. }