diff options
Diffstat (limited to 'src/server/util')
-rw-r--r-- | src/server/util/global.cpp | 16 | ||||
-rw-r--r-- | src/server/util/global.h | 9 |
2 files changed, 22 insertions, 3 deletions
diff --git a/src/server/util/global.cpp b/src/server/util/global.cpp index 3021ca9..8bb89d0 100644 --- a/src/server/util/global.cpp +++ b/src/server/util/global.cpp @@ -6,6 +6,7 @@ */ #include "global.h" +#include <QDebug> QString Global::_sessionName = QString(); QByteArray Global::_sessionNameArray = QByteArray(); @@ -34,3 +35,18 @@ void Global::setCurrentRoom(QString room) { Global::_currentRoom = room; } + +const Room* Global::getCurrentRoom() { + if (_rooms.contains(_currentRoom)) { + qDebug() << "returning actual room: " << _currentRoom; + return _rooms[_currentRoom]; + } else { + qDebug() << "couldn't find the room name " << _currentRoom << " in the _rooms-Map"; + static Room* defaultRoom = NULL; + if (defaultRoom == NULL) { + defaultRoom = new Room(QMap<QString, QPoint>(), QSize(8, 6), QSize(1,1), ""); + } + qDebug() << "returned default room"; + return defaultRoom; + } +} diff --git a/src/server/util/global.h b/src/server/util/global.h index c258b4a..f9dc327 100644 --- a/src/server/util/global.h +++ b/src/server/util/global.h @@ -28,8 +28,7 @@ struct Room { QString imagePath; }; -class Global -{ +class Global { private: Global(){} ~Global(){} @@ -51,7 +50,11 @@ public: } static void setCurrentRoom(QString room); - static const QString& getCurrentRoom() { return _currentRoom; } + static const QString& getCurrentRoomName() { return _currentRoom; } + + /* returns a pointer to the current room or a pointer to the constant "defaultRoom". + * (NEVER returns NULL or undefined) */ + static const Room* getCurrentRoom(); }; #endif /* GLOBAL_H_ */ |