tile_set.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // SuperTux
  2. // Copyright (C) 2008 Matthias Braun <matze@braunis.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. #ifndef HEADER_SUPERTUX_SUPERTUX_TILE_SET_HPP
  17. #define HEADER_SUPERTUX_SUPERTUX_TILE_SET_HPP
  18. #include <map>
  19. #include <memory>
  20. #include <stdint.h>
  21. #include <string>
  22. #include "math/fwd.hpp"
  23. #include "supertux/autotile.hpp"
  24. #include "supertux/tile.hpp"
  25. #include "video/color.hpp"
  26. #include "video/surface_ptr.hpp"
  27. class Canvas;
  28. class DrawingContext;
  29. class Tilegroup final
  30. {
  31. public:
  32. Tilegroup();
  33. bool developers_group = false;
  34. std::string name;
  35. std::vector<int> tiles;
  36. };
  37. class TileSet final
  38. {
  39. public:
  40. static std::unique_ptr<TileSet> from_file(const std::string& filename);
  41. public:
  42. TileSet();
  43. ~TileSet() = default;
  44. void add_tile(int id, std::unique_ptr<Tile> tile);
  45. /** Adds a group of tiles that haven't
  46. been assigned to any other group */
  47. void add_unassigned_tilegroup();
  48. /** Check for and remove any deprecated tiles from tilegroups. */
  49. void remove_deprecated_tiles();
  50. void add_tilegroup(const Tilegroup& tilegroup);
  51. const Tile& get(const uint32_t id) const;
  52. AutotileSet* get_autotileset_from_tile(uint32_t tile_id) const;
  53. uint32_t get_max_tileid() const {
  54. return static_cast<uint32_t>(m_tiles.size());
  55. }
  56. const std::vector<Tilegroup>& get_tilegroups() const {
  57. return m_tilegroups;
  58. }
  59. void print_debug_info(const std::string& filename);
  60. public:
  61. // Must be public because of tile_set_parser.cpp
  62. std::vector<std::unique_ptr<AutotileSet>> m_autotilesets;
  63. // Additional attributes
  64. // Must be public because of tile_set_parser.cpp and thunderstorm.cpp
  65. std::map<uint32_t, uint32_t> m_thunderstorm_tiles;
  66. private:
  67. std::vector<std::unique_ptr<Tile> > m_tiles;
  68. std::vector<Tilegroup> m_tilegroups;
  69. private:
  70. TileSet(const TileSet&) = delete;
  71. TileSet& operator=(const TileSet&) = delete;
  72. };
  73. #endif
  74. /* EOF */