added base interace for game items

This commit is contained in:
Andrei Yankovich 2021-08-07 17:46:37 +03:00
parent a2ba48e76f
commit efca1133ce
13 changed files with 158 additions and 57 deletions

View File

@ -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);
}

30
src/Core/Crawl/iitem.cpp Normal file
View File

@ -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;
}
}

77
src/Core/Crawl/iitem.h Normal file
View File

@ -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

View File

@ -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.

View File

@ -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;

View File

@ -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 "";

View File

@ -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";
}
}

View File

@ -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;
};

View File

@ -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);

View File

@ -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);
};

View File

@ -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);

View File

@ -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);

View File

@ -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;
};