worldmap_sector_parser.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // SuperTux
  2. // Copyright (C) 2023 Vankata453
  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 "worldmap/worldmap_sector_parser.hpp"
  17. #include "object/tilemap.hpp"
  18. #include "supertux/d_scope.hpp"
  19. #include "supertux/game_object_factory.hpp"
  20. #include "worldmap/spawn_point.hpp"
  21. #include "worldmap/worldmap_sector.hpp"
  22. namespace worldmap {
  23. std::unique_ptr<WorldMapSector>
  24. WorldMapSectorParser::from_reader(WorldMap& worldmap, const ReaderMapping& reader)
  25. {
  26. auto sector = std::make_unique<WorldMapSector>(worldmap);
  27. BIND_WORLDMAP_SECTOR(*sector);
  28. WorldMapSectorParser parser(*sector);
  29. parser.parse(reader);
  30. return sector;
  31. }
  32. WorldMapSectorParser::WorldMapSectorParser(WorldMapSector& sector) :
  33. SectorParser(sector, false)
  34. {
  35. }
  36. WorldMapSector&
  37. WorldMapSectorParser::get_sector() const
  38. {
  39. return static_cast<WorldMapSector&>(m_sector);
  40. }
  41. bool
  42. WorldMapSectorParser::parse_object_additional(const std::string& name, const ReaderMapping& reader)
  43. {
  44. if (name == "worldmap-spawnpoint") // Custom rule for adding spawnpoints
  45. {
  46. get_sector().m_spawnpoints.push_back(std::make_unique<SpawnPoint>(reader));
  47. return true;
  48. }
  49. else if (name == "tilemap") // Custom rule for adding tilemaps on worldmaps
  50. {
  51. get_sector().add<TileMap>(get_sector().get_tileset(), reader);
  52. return true;
  53. }
  54. // Proceed adding the object only if it's flagged as allowed for worldmaps
  55. return !GameObjectFactory::instance().has_params(name, ObjectFactory::RegisteredObjectParam::OBJ_PARAM_WORLDMAP);
  56. }
  57. } // namespace worldmap
  58. /* EOF */