TileMapDefs2D.h 5.7 KB

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