TileMapDefs2D.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. #include "Precompiled.h"
  23. #include "TileMapDefs2D.h"
  24. #include "XMLElement.h"
  25. #include "DebugNew.h"
  26. namespace Urho3D
  27. {
  28. PropertySet2D::PropertySet2D()
  29. {
  30. }
  31. PropertySet2D::~PropertySet2D()
  32. {
  33. }
  34. void PropertySet2D::Load(const XMLElement& element)
  35. {
  36. assert(element.GetName() == "properties");
  37. for (XMLElement propertyElem = element.GetChild("property"); propertyElem; propertyElem = propertyElem.GetNext("property"))
  38. nameToValueMapping_[propertyElem.GetAttribute("name")] = propertyElem.GetAttribute("value");
  39. }
  40. bool PropertySet2D::HasProperty(const String& name) const
  41. {
  42. return nameToValueMapping_.Find(name) != nameToValueMapping_.End();
  43. }
  44. const String& PropertySet2D::GetProperty(const String& name) const
  45. {
  46. HashMap<String, String>::ConstIterator i = nameToValueMapping_.Find(name);
  47. if (i == nameToValueMapping_.End())
  48. return String::EMPTY;
  49. return i->second_;
  50. }
  51. Tile2D::Tile2D() :
  52. gid_(0)
  53. {
  54. }
  55. Sprite2D* Tile2D::GetSprite() const
  56. {
  57. return sprite_;
  58. }
  59. bool Tile2D::HasProperty(const String& name) const
  60. {
  61. if (!propertySet_)
  62. return false;
  63. return propertySet_->HasProperty(name);
  64. }
  65. const String& Tile2D::GetProperty(const String& name) const
  66. {
  67. if (!propertySet_)
  68. return String::EMPTY;
  69. return propertySet_->GetProperty(name);
  70. }
  71. TileObject2D::TileObject2D()
  72. {
  73. }
  74. unsigned TileObject2D::GetNumPoints() const
  75. {
  76. return points_.Size();
  77. }
  78. const Vector2& TileObject2D::GetPoint(unsigned index) const
  79. {
  80. if (index >= points_.Size())
  81. return Vector2::ZERO;
  82. return points_[index];
  83. }
  84. Sprite2D* TileObject2D::GetTileSprite() const
  85. {
  86. return sprite_;
  87. }
  88. bool TileObject2D::HasProperty(const String& name) const
  89. {
  90. if (!propertySet_)
  91. return false;
  92. return propertySet_->HasProperty(name);
  93. }
  94. const String& TileObject2D::GetProperty(const String& name) const
  95. {
  96. if (!propertySet_)
  97. return String::EMPTY;
  98. return propertySet_->GetProperty(name);
  99. }
  100. }