Skip to content

Commit

Permalink
PathGameObject saveable check now checks for references in all sectors
Browse files Browse the repository at this point in the history
Fixes an issue, introduced in SuperTux#2320, regarding the `PathGameObject::is_saveable()` function's implementation.

The issue caused paths to not be saveable, if the current sector, opened in the editor, does not have any PathObjects that reference them. The check is now performed for all sectors in a level.
  • Loading branch information
Vankata453 committed Jul 13, 2023
1 parent 23131b0 commit ab13865
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/object/path_gameobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "sprite/sprite.hpp"
#include "sprite/sprite_manager.hpp"
#include "supertux/debug.hpp"
#include "supertux/level.hpp"
#include "supertux/sector.hpp"
#include "util/log.hpp"
#include "util/reader_mapping.hpp"
Expand Down Expand Up @@ -215,11 +216,12 @@ PathGameObject::is_saveable() const
if (!Sector::current())
return false;

const auto& path_objects = Sector::get().get_objects_by_type<PathObject>();

for (const auto& path_obj : path_objects)
if (path_obj.get_path_gameobject() == this)
return true;
for (const auto& sector : Level::current()->get_sectors())
{
for (const auto& path_obj : sector->get_objects_by_type<PathObject>())
if (path_obj.get_path_gameobject() == this)
return true;
}

return false;
}
Expand Down
1 change: 1 addition & 0 deletions src/supertux/level.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Level final

size_t get_sector_count() const;
Sector* get_sector(size_t num) const;
const std::vector<std::unique_ptr<Sector> >& get_sectors() const { return m_sectors; }

std::string get_tileset() const { return m_tileset; }

Expand Down

0 comments on commit ab13865

Please sign in to comment.