From 13dce1b9aca190a9cb07ece77d76e07887fbb305 Mon Sep 17 00:00:00 2001 From: Julian Dreuth <julian.dreuth@informatik.hs-fulda.de> Date: Thu, 6 Feb 2025 22:38:37 +0100 Subject: [PATCH] Fix/editor doors --- editor/src/CenterGrid.cpp | 4 ++++ editor/src/CenterGrid.hpp | 5 +++++ editor/src/HDF5Handler.cpp | 6 +++--- editor/src/MainWindow.cpp | 14 +++++++------- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/editor/src/CenterGrid.cpp b/editor/src/CenterGrid.cpp index f2e43a5..fbf246e 100644 --- a/editor/src/CenterGrid.cpp +++ b/editor/src/CenterGrid.cpp @@ -92,6 +92,10 @@ void CenterGrid::onTileClicked(int row, int col) if (m_spriteType == 0) { m_tileIDs[row][col] = m_currentSpriteID; + if (std::find(m_doorIDList.begin(), m_doorIDList.end(), m_currentSpriteID) != m_doorIDList.end()) + { + m_objectIDs[row][col] = m_currentSpriteID; + } } else if (m_spriteType == 1) { diff --git a/editor/src/CenterGrid.hpp b/editor/src/CenterGrid.hpp index f1dcbbc..d322af1 100644 --- a/editor/src/CenterGrid.hpp +++ b/editor/src/CenterGrid.hpp @@ -139,6 +139,11 @@ class CenterGrid : public QWidget 82, 83, 84, 85, 86, 87, 88, 89, 114, 115, 116, 117, 118, 119, 120, 121, 146, 147, 148, 149, 150, 151, 152, 153, 178, 179, 180, 181, 182, 183, 184, 185, 210, 211, 212, 213, 214, 215, 216, 242, 243, 244, 245, 246, 247, 248}; + + /** + * @brief List of all spriteIDs that are doors + */ + std::vector<int> m_doorIDList = {102,103,104,134,135,136,166,167,168,198,199}; }; } // namespace editor \ No newline at end of file diff --git a/editor/src/HDF5Handler.cpp b/editor/src/HDF5Handler.cpp index f5c02c8..504163b 100644 --- a/editor/src/HDF5Handler.cpp +++ b/editor/src/HDF5Handler.cpp @@ -45,14 +45,14 @@ void HDF5Handler::saveRoom(int id, QString name, QVector<QVector<int>> tileIDs, { for (int col = 0; col < 64; col++) { - newRoom.placeTile({row, col}, tileIDs[row][col]); + newRoom.placeTile({col, row}, tileIDs[row][col]); if (mobIDs[row][col] != -1) { - newRoom.placeEnemy({row, col}, mobIDs[row][col]); + newRoom.placeEnemy({col, row}, mobIDs[row][col]); } if (objectIDs[row][col] != -1) { - newRoom.placeObject({row, col}, objectIDs[row][col]); + newRoom.placeObject({col, row}, objectIDs[row][col]); } } } diff --git a/editor/src/MainWindow.cpp b/editor/src/MainWindow.cpp index 5877dd0..161dd75 100644 --- a/editor/src/MainWindow.cpp +++ b/editor/src/MainWindow.cpp @@ -96,9 +96,9 @@ MainWindow::MainWindow(DialogSelection selected, const std::filesystem::path &pa int32_t tileID = *it; if (tileID != -1) { - std::size_t index = std::distance(foundRoom.tilesBegin(), it++); - int x = index % width; - int y = index / width; + std::size_t index = std::distance(foundRoom.tilesBegin(), it); + int y = index % width; + int x = index / width; m_centerGrid->setCurrentSprite(m_leftWidget->getPixmapByIndex(tileID), tileID); m_centerGrid->onTileClicked(x, y); } @@ -106,8 +106,8 @@ MainWindow::MainWindow(DialogSelection selected, const std::filesystem::path &pa for (auto it = foundRoom.objectsBegin(); it != foundRoom.objectsEnd(); it++) { lvl::Placement gameObject = *it; - int x = gameObject.position.x; - int y = gameObject.position.y; + int y = gameObject.position.x; + int x = gameObject.position.y; int tileID = gameObject.id; m_centerGrid->setCurrentSprite(m_leftWidget->getPixmapByIndex(tileID), tileID); m_centerGrid->onTileClicked(x, y); @@ -115,8 +115,8 @@ MainWindow::MainWindow(DialogSelection selected, const std::filesystem::path &pa for (auto it = foundRoom.enemiesBegin(); it != foundRoom.enemiesEnd(); it++) { lvl::Placement gameObject = *it; - int x = gameObject.position.x; - int y = gameObject.position.y; + int y = gameObject.position.x; + int x = gameObject.position.y; int tileID = gameObject.id; switch (tileID) { -- GitLab