tileset.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Flexlay - A Generic 2D Game Editor
  2. // Copyright (C) 2000 Ingo Ruhnke <grumbel@gmx.de>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #include <string>
  17. #include <ClanLib/Core/System/system.h>
  18. #include <assert.h>
  19. #include <iostream>
  20. #include "globals.hpp"
  21. #include "string_converter.hpp"
  22. #include "tile.hpp"
  23. #include "tileset.hpp"
  24. typedef std::vector<Tile*> Tiles;
  25. typedef std::vector<int> TileIds;
  26. typedef Tiles::iterator iterator;
  27. class TilesetImpl
  28. {
  29. public:
  30. TilesetImpl()
  31. {
  32. }
  33. ~TilesetImpl()
  34. {
  35. for(Tiles::iterator i = tiles.begin(); i != tiles.end(); ++i)
  36. {
  37. delete *i;
  38. }
  39. }
  40. TileIds tile_ids;
  41. Tiles tiles;
  42. int tile_size;
  43. };
  44. Tileset::Tileset()
  45. : impl(new TilesetImpl())
  46. {
  47. impl->tile_size = 1;
  48. }
  49. Tileset::Tileset(int tile_size_)
  50. : impl(new TilesetImpl())
  51. {
  52. assert(tile_size_ > 0);
  53. impl->tile_size = tile_size_;
  54. }
  55. Tileset::~Tileset()
  56. {
  57. }
  58. void
  59. Tileset::add_tile(int id, Tile* tile)
  60. {
  61. // FIXME: Check for tile-id dups
  62. if (id >= int(impl->tiles.size()))
  63. impl->tiles.resize(id+1, 0);
  64. if (tile)
  65. impl->tiles[id] = new Tile(*tile);
  66. else
  67. impl->tiles[id] = 0;
  68. impl->tile_ids.push_back(id);
  69. }
  70. Tile*
  71. Tileset::create (int id)
  72. {
  73. if (id >= 0 && id < int(impl->tiles.size()))
  74. return impl->tiles[id];
  75. else
  76. return 0;
  77. }
  78. int
  79. Tileset::get_tile_size() const
  80. {
  81. return impl->tile_size;
  82. }
  83. std::vector<int>
  84. Tileset::get_tiles() const
  85. {
  86. return impl->tile_ids;
  87. }
  88. /* EOF */