diff --git a/src/Core/Crawl/clientapp.cpp b/src/Core/Crawl/clientapp.cpp index 77d11d7..45efbc2 100644 --- a/src/Core/Crawl/clientapp.cpp +++ b/src/Core/Crawl/clientapp.cpp @@ -132,7 +132,7 @@ void ClientApp::addLvl(IWorld *levelWordl) { data.model = levelWordl; data.viewModel = new WorldViewData(data.model); - _availableLvls.insert(data.model->name(), data); + _availableLvls.insert(data.model->itemName(), data); _menu->addWorldViewModel(data.viewModel); } diff --git a/src/Core/Crawl/iitem.cpp b/src/Core/Crawl/iitem.cpp new file mode 100644 index 0000000..504b66b --- /dev/null +++ b/src/Core/Crawl/iitem.cpp @@ -0,0 +1,30 @@ +//# +//# Copyright (C) 2021-2021 QuasarApp. +//# Distributed under the GPLv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + + +#include "iitem.h" +#include <QHash> + +namespace CRAWL { + +IItem::IItem() { + +} + +unsigned int IItem::itemId() { + if (_id) { + return _id; + } + + _id = qHash(itemTextId()); + return _id; +} + +unsigned int IItem::itemId() const { + return _id; +} +} diff --git a/src/Core/Crawl/iitem.h b/src/Core/Crawl/iitem.h new file mode 100644 index 0000000..6bfaf27 --- /dev/null +++ b/src/Core/Crawl/iitem.h @@ -0,0 +1,77 @@ +//# +//# Copyright (C) 2021-2021 QuasarApp. +//# Distributed under the GPLv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + + +#ifndef IITEM_H +#define IITEM_H + +#include <QString> +#include "global.h" + +namespace CRAWL { + +/** + * @brief The IItem class contains base description of the game items (player perks, game levels, and levels items.) + */ +class CRAWL_EXPORT IItem +{ +public: + IItem(); + + /** + * @brief itemTextId All items contains own ids, override this method for create base for generate new item id. + * @return item text id. + * @see IItem::itemId + * @note do not use the tr function for implementation of this method. + * If you want to translate the name of the item then use the IItem::itemName method. + */ + virtual QString itemTextId() const = 0; + + /** + * @brief itemName This method should be return name of the item. + * @return Name of the item (translated to all supported languages) + */ + virtual QString itemName() const = 0; + + /** + * @brief description This method must be return full description of this item. The description should be translated to all supported languages. + * @return Full description of this item. + */ + virtual QString description() const = 0; + + /** + * @brief image This method should be return path to image preview of the item object. + * @return path to image form qt resources. + */ + virtual QString image() const = 0; + + /** + * @brief cost This method should be return costo to unlock. + * @return costo to unlock. + */ + virtual int cost() const = 0; + + /** + * @brief itemId This method return hash of the IItem::itemTextId. + * @return hash of the IItem::itemTextId. + * @note The not const implementation inlike const implementation write a id to cache. + */ + unsigned int itemId(); + + /** + * @brief itemId This method return hash of the IItem::itemTextId. + * @return hash of the IItem::itemTextId. + * @warning if the object are const and not const implementation of the IItem::itemId method never invoked then this method return 0. + */ + unsigned int itemId() const; + +private: + unsigned int _id = 0; +}; + +} +#endif // IITEM_H diff --git a/src/Core/Crawl/iworld.h b/src/Core/Crawl/iworld.h index 9256ea6..fd6dfd4 100644 --- a/src/Core/Crawl/iworld.h +++ b/src/Core/Crawl/iworld.h @@ -9,6 +9,7 @@ #define CRAWL_IWORLD_H #include "gameresult.h" +#include "iitem.h" #include "playableobject.h" #include <QHash> @@ -55,7 +56,7 @@ typedef QMap<int, WorldObjects> WorldRule; /** * @brief The IWorld class use this interface for implementation your own game levels */ -class CRAWL_EXPORT IWorld : public QObject, public IRender +class CRAWL_EXPORT IWorld : public QObject, public IRender, public IItem { Q_OBJECT Q_PROPERTY(QVector3D cameraReleativePosition READ cameraReleativePosition NOTIFY cameraReleativePositionChanged) @@ -118,30 +119,6 @@ public: */ virtual QString initHdrBackGround() const = 0; - /** - * @brief description This method shold be return lvl description. - * @return lvel description string. - */ - virtual QString description() const = 0; - - /** - * @brief imagePreview This method should be return path to banner of the lvl. - * @return path to level banner. - */ - virtual QString imagePreview() const = 0; - - /** - * @brief name This method shold be return lvl name. - * @return lvl name. - */ - virtual QString name() const = 0; - - /** - * @brief costToUnlock This method shold be return unlock cost. - * @return unlock cost - */ - virtual int costToUnlock() const = 0; - /** * @brief render this method recursive invoke all render functions of the all world items. * The render function is main function of the SnakeEngine This method recal all propertys of all objects. diff --git a/src/Core/private/engine.cpp b/src/Core/private/engine.cpp index f01a0b9..d8c9b3b 100644 --- a/src/Core/private/engine.cpp +++ b/src/Core/private/engine.cpp @@ -49,7 +49,7 @@ void Engine::setWorld(IWorld *world) { emit worldChanged(); if (!prepareNewWorld()) { - QuasarAppUtils::Params::log("Failed to init world. World name: " + _currentWorld->name(), + QuasarAppUtils::Params::log("Failed to init world. World name: " + _currentWorld->itemName(), QuasarAppUtils::Error); _currentWorld = nullptr; diff --git a/src/Core/private/worldviewdata.cpp b/src/Core/private/worldviewdata.cpp index dba250b..db4068a 100644 --- a/src/Core/private/worldviewdata.cpp +++ b/src/Core/private/worldviewdata.cpp @@ -15,7 +15,7 @@ WorldViewData::WorldViewData(const IWorld *data) { QString WorldViewData::name() const { if (_worldObject) { - return _worldObject->name(); + return _worldObject->itemName(); } return ""; @@ -31,7 +31,7 @@ QString WorldViewData::desc() const { int WorldViewData::cost() const { if (_worldObject) { - return _worldObject->costToUnlock(); + return _worldObject->cost(); } return 0; @@ -50,7 +50,7 @@ void WorldViewData::setUnlocked(bool newUnlocked) { QString WorldViewData::image() const { if (_worldObject) { - return _worldObject->imagePreview(); + return _worldObject->image(); } return ""; diff --git a/src/CrawlAbstractLvl/private/abslvlworld.cpp b/src/CrawlAbstractLvl/private/abslvlworld.cpp index 5b3aeee..5050c43 100644 --- a/src/CrawlAbstractLvl/private/abslvlworld.cpp +++ b/src/CrawlAbstractLvl/private/abslvlworld.cpp @@ -60,16 +60,16 @@ QString AbsLvlWorld::description() const { return tr("This a abstract lvl"); } -QString AbsLvlWorld::imagePreview() const { +QString AbsLvlWorld::image() const { return "qrc:/hdr/hdr/testHDR.jpg"; } -QString AbsLvlWorld::name() const { +QString AbsLvlWorld::itemName() const { return tr("AbstractLvl"); } -int AbsLvlWorld::costToUnlock() const { +int AbsLvlWorld::cost() const { return 0; } @@ -81,4 +81,8 @@ void AbsLvlWorld::initPlayerControl(CRAWL::IControl *control) { return IWorld::initPlayerControl(control); } +QString AbsLvlWorld::itemTextId() const { + return "AbstractLevel"; +} + } diff --git a/src/CrawlAbstractLvl/private/abslvlworld.h b/src/CrawlAbstractLvl/private/abslvlworld.h index 2f075cf..2944ae4 100644 --- a/src/CrawlAbstractLvl/private/abslvlworld.h +++ b/src/CrawlAbstractLvl/private/abslvlworld.h @@ -19,16 +19,16 @@ public: AbsLvlWorld(); - CRAWL::PlayableObject *initPlayer() const override; CRAWL::WorldRule *initWorldRules() override; QString initHdrBackGround() const override; QString description() const override; - QString imagePreview() const override; - QString name() const override; - int costToUnlock() const override; + QString image() const override; + QString itemName() const override; + int cost() const override; CRAWL::IControl *initUserInterface() const override; void initPlayerControl(CRAWL::IControl *control) override; + QString itemTextId() const override; }; diff --git a/src/CrawlTestLvl/private/world.cpp b/src/CrawlTestLvl/private/world.cpp index 281bb39..dc8b0fe 100644 --- a/src/CrawlTestLvl/private/world.cpp +++ b/src/CrawlTestLvl/private/world.cpp @@ -48,15 +48,15 @@ QString World::description() const { return "This a test lvl"; } -QString World::imagePreview() const { +QString World::image() const { return "qrc:/hdr/hdr/testHDR.jpg"; } -QString World::name() const { +QString World::itemName() const { return "Test"; } -int World::costToUnlock() const { +int World::cost() const { return 0; } @@ -81,6 +81,10 @@ CRAWL::IAI *World::initBackGroundAI() const { return IWorld::initBackGroundAI(); } +QString World::itemTextId() const { + return "TestLevel"; +} + void World::handleXViewChanged(double dx) { auto eilorRotation = cameraRotation().toEulerAngles(); eilorRotation.setX(eilorRotation.x() + dx); diff --git a/src/CrawlTestLvl/private/world.h b/src/CrawlTestLvl/private/world.h index f8038f7..a1f42f2 100644 --- a/src/CrawlTestLvl/private/world.h +++ b/src/CrawlTestLvl/private/world.h @@ -23,18 +23,22 @@ public: CRAWL::WorldRule *initWorldRules() override; QString initHdrBackGround() const override; QString description() const override; - QString imagePreview() const override; - QString name() const override; - int costToUnlock() const override; + QString image() const override; + QString itemName() const override; + int cost() const override; CRAWL::IControl *initUserInterface() const override; void initPlayerControl(CRAWL::IControl *control) override; CRAWL::PlayableObject *initPlayer() const override; CRAWL::IAI *initBackGroundAI() const override; + QString itemTextId() const override; private slots: void handleXViewChanged(double dx); void handleYViewChanged(double dy); + + + }; diff --git a/src/JungleLvl/private/world.cpp b/src/JungleLvl/private/world.cpp index b036387..e80ebb7 100644 --- a/src/JungleLvl/private/world.cpp +++ b/src/JungleLvl/private/world.cpp @@ -88,15 +88,15 @@ QString World::description() const { return tr("Jungle world."); } -QString World::imagePreview() const { +QString World::image() const { return "qrc:/hdr/hdr/jungleBanner.jpg"; } -QString World::name() const { +QString World::itemName() const { return tr("Jungle"); } -int World::costToUnlock() const { +int World::cost() const { return 0; } @@ -116,6 +116,10 @@ CRAWL::IAI *World::initBackGroundAI() const { return IWorld::initBackGroundAI(); } +QString World::itemTextId() const { + return "JungleLevel"; +} + void World::handleXViewChanged(double dx) { auto eilorRotation = cameraRotation().toEulerAngles(); eilorRotation.setX(eilorRotation.x() + dx); diff --git a/src/JungleLvl/private/world.h b/src/JungleLvl/private/world.h index 98bf398..3c323e3 100644 --- a/src/JungleLvl/private/world.h +++ b/src/JungleLvl/private/world.h @@ -22,13 +22,14 @@ public: CRAWL::WorldRule *initWorldRules() override; QString initHdrBackGround() const override; QString description() const override; - QString imagePreview() const override; - QString name() const override; - int costToUnlock() const override; + QString image() const override; + QString itemName() const override; + int cost() const override; CRAWL::IControl *initUserInterface() const override; void initPlayerControl(CRAWL::IControl *control) override; CRAWL::PlayableObject *initPlayer() const override; CRAWL::IAI *initBackGroundAI() const override; + QString itemTextId() const override; private slots: void handleXViewChanged(double dx); diff --git a/tests/units/clasterstest.cpp b/tests/units/clasterstest.cpp index 219c0e6..a63bcc5 100644 --- a/tests/units/clasterstest.cpp +++ b/tests/units/clasterstest.cpp @@ -45,14 +45,14 @@ public: // IWorld interface public: - CRAWL::PlayableObject *initPlayer() const {return nullptr;}; - CRAWL::WorldRule *initWorldRules() {return nullptr;}; - QString initHdrBackGround() const {return "";}; - QString description() const {return "";}; - QString imagePreview() const {return "";}; - QString name() const {return "TestWorld";}; - int costToUnlock() const {return 0;}; - + CRAWL::PlayableObject *initPlayer() const override {return nullptr;}; + CRAWL::WorldRule *initWorldRules() override {return nullptr;}; + QString initHdrBackGround() const override {return "";}; + QString description() const override {return "";}; + QString image() const override {return "";}; + QString itemName() const override {return "TestWorld";}; + int cost() const override {return 0;}; + QString itemTextId() const override {return "TestWorld";}; friend class ClastersTest; };