Skip to content

Commit

Permalink
Update directional enums and related logic
Browse files Browse the repository at this point in the history
Expanded the enum class `Dir` to include intermediate directions (NorthEast, SouthEast, SouthWest, NorthWest). Adjusted related logic in `Level.cpp` to accommodate these new options.
  • Loading branch information
scastd authored and Madour committed Feb 15, 2024
1 parent 0e4f91f commit 76aa17e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
6 changes: 5 additions & 1 deletion include/LDtkLoader/DataTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,13 @@ namespace ldtk {
enum class Dir {
None,
North,
NorthEast,
East,
SouthEast,
South,
West
SouthWest,
West,
NorthWest
};

class FilePath : std::string {
Expand Down
26 changes: 20 additions & 6 deletions src/Level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,33 @@ depth(j.contains("worldDepth") ? j["worldDepth"].get<int>() : 0)
m_layers.emplace_back(level, w, this);
}

m_neighbours_id[Dir::North]; m_neighbours_id[Dir::East];
m_neighbours_id[Dir::South]; m_neighbours_id[Dir::West];
m_neighbours_id[Dir::North]; m_neighbours_id[Dir::NorthEast];
m_neighbours_id[Dir::East]; m_neighbours_id[Dir::SouthEast];
m_neighbours_id[Dir::South]; m_neighbours_id[Dir::SouthWest];
m_neighbours_id[Dir::West]; m_neighbours_id[Dir::NorthWest];
for (const auto& neighbour : j["__neighbours"]) {
const auto& dir = neighbour["dir"].get<std::string>();
const auto& level_iid = IID(neighbour["levelIid"].get<std::string>());
Dir direction;

if (dir == "n")
m_neighbours_id[Dir::North].push_back(level_iid);
direction = Dir::North;
else if (dir == "ne")
direction = Dir::NorthEast;
else if (dir == "e")
m_neighbours_id[Dir::East].push_back(level_iid);
direction = Dir::East;
else if (dir == "se")
direction = Dir::SouthEast;
else if (dir == "s")
m_neighbours_id[Dir::South].push_back(level_iid);
direction = Dir::South;
else if (dir == "sw")
direction = Dir::SouthWest;
else if (dir == "w")
direction = Dir::West;
else
m_neighbours_id[Dir::West].push_back(level_iid);
direction = Dir::NorthWest;

m_neighbours_id[direction].push_back(level_iid);
}

if (j["bgRelPath"].is_null())
Expand Down

0 comments on commit 76aa17e

Please sign in to comment.