TileMapDefs2D.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. //
  2. // Copyright (c) 2008-2016 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 "../Container/RefCounted.h"
  24. #include "../Atomic2D/Sprite2D.h"
  25. namespace Atomic
  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. /// Hexagonal
  38. O_HEXAGONAL
  39. };
  40. /// Tile map information.
  41. struct ATOMIC_API TileMapInfo2D
  42. {
  43. /// Orientation.
  44. Orientation2D orientation_;
  45. /// Width.
  46. int width_;
  47. /// Height.
  48. int height_;
  49. /// Tile width.
  50. float tileWidth_;
  51. /// Tile height.
  52. float tileHeight_;
  53. /// Return map width.
  54. float GetMapWidth() const;
  55. /// return map height.
  56. float GetMapHeight() const;
  57. /// Convert tmx position to Urho position.
  58. Vector2 ConvertPosition(const Vector2& position) const;
  59. /// Convert tile index to position.
  60. Vector2 TileIndexToPosition(int x, int y) const;
  61. /// Convert position to tile index, if out of map return false.
  62. bool PositionToTileIndex(int& x, int& y, const Vector2& positon) const;
  63. };
  64. /// Tile map layer type.
  65. enum TileMapLayerType2D
  66. {
  67. /// Tile layer.
  68. LT_TILE_LAYER = 0,
  69. /// Object group.
  70. LT_OBJECT_GROUP,
  71. /// Image layer.
  72. LT_IMAGE_LAYER,
  73. /// Invalid.
  74. LT_INVALID = 0xffff
  75. };
  76. /// Tile map object type.
  77. enum TileMapObjectType2D
  78. {
  79. /// Rectangle.
  80. OT_RECTANGLE = 0,
  81. /// Ellipse.
  82. OT_ELLIPSE,
  83. /// Polygon.
  84. OT_POLYGON,
  85. /// Polyline.
  86. OT_POLYLINE,
  87. /// Tile.
  88. OT_TILE,
  89. /// Invalid.
  90. OT_INVALID = 0xffff
  91. };
  92. /// Property set.
  93. class ATOMIC_API PropertySet2D : public RefCounted
  94. {
  95. ATOMIC_REFCOUNTED(PropertySet2D)
  96. public:
  97. PropertySet2D();
  98. virtual ~PropertySet2D();
  99. /// Load from XML element.
  100. void Load(const XMLElement& element);
  101. /// Return has property.
  102. bool HasProperty(const String& name) const;
  103. /// Return property value.
  104. const String& GetProperty(const String& name) const;
  105. protected:
  106. /// Property name to property value mapping.
  107. HashMap<String, String> nameToValueMapping_;
  108. };
  109. /// Tile define.
  110. class ATOMIC_API Tile2D : public RefCounted
  111. {
  112. ATOMIC_REFCOUNTED(Tile2D)
  113. public:
  114. /// Construct.
  115. Tile2D();
  116. /// Return gid.
  117. int GetGid() const { return gid_; }
  118. /// Return sprite.
  119. Sprite2D* GetSprite() const;
  120. /// Return has property.
  121. bool HasProperty(const String& name) const;
  122. /// Return property.
  123. const String& GetProperty(const String& name) const;
  124. private:
  125. friend class TmxTileLayer2D;
  126. /// Gid.
  127. int gid_;
  128. /// Sprite.
  129. SharedPtr<Sprite2D> sprite_;
  130. /// Property set.
  131. SharedPtr<PropertySet2D> propertySet_;
  132. };
  133. /// Tile map object.
  134. class ATOMIC_API TileMapObject2D : public RefCounted
  135. {
  136. ATOMIC_REFCOUNTED(TileMapObject2D)
  137. public:
  138. TileMapObject2D();
  139. /// Return type.
  140. TileMapObjectType2D GetObjectType() const { return objectType_; }
  141. /// Return name.
  142. const String& GetName() const { return name_; }
  143. /// Return type.
  144. const String& GetType() const { return type_; }
  145. /// Return position.
  146. const Vector2& GetPosition() const { return position_; }
  147. /// Return size (for rectangle and ellipse).
  148. const Vector2& GetSize() const { return size_; }
  149. /// Return number of points (use for script).
  150. unsigned GetNumPoints() const;
  151. /// Return point at index (use for script).
  152. const Vector2& GetPoint(unsigned index) const;
  153. /// Return tile Gid.
  154. int GetTileGid() const { return gid_; }
  155. /// Return tile sprite.
  156. Sprite2D* GetTileSprite() const;
  157. /// Return has property.
  158. bool HasProperty(const String& name) const;
  159. /// Return property value.
  160. const String& GetProperty(const String& name) const;
  161. private:
  162. friend class TmxObjectGroup2D;
  163. /// Object type.
  164. TileMapObjectType2D objectType_;
  165. /// Name.
  166. String name_;
  167. /// Type.
  168. String type_;
  169. /// Position.
  170. Vector2 position_;
  171. /// Size (for rectangle and ellipse).
  172. Vector2 size_;
  173. /// Points(for polygon and polyline).
  174. Vector<Vector2> points_;
  175. /// Gid (for tile).
  176. int gid_;
  177. /// Sprite (for tile).
  178. SharedPtr<Sprite2D> sprite_;
  179. /// Property set.
  180. SharedPtr<PropertySet2D> propertySet_;
  181. };
  182. }