84 lines
1.6 KiB
C++
84 lines
1.6 KiB
C++
#pragma once
|
|
#include <QObject>
|
|
#include <vector>
|
|
#include <QRandomGenerator>
|
|
#include <QSettings>
|
|
#include <QJsonObject>
|
|
#include <memory>
|
|
|
|
class Actor;
|
|
|
|
class ItemData
|
|
{
|
|
protected:
|
|
QString name_;
|
|
uint8_t value_;
|
|
uint32_t itemId_;
|
|
|
|
public:
|
|
|
|
ItemData(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0);
|
|
|
|
inline bool operator==(const ItemData& in) const
|
|
{
|
|
return itemId_==in.itemId_;
|
|
}
|
|
inline bool operator!=(const ItemData& in) const
|
|
{
|
|
return itemId_!=in.itemId_;
|
|
}
|
|
|
|
uint32_t id() const;
|
|
|
|
void setName(QString name);
|
|
uint8_t getValue() const;
|
|
virtual QString getName() const;
|
|
};
|
|
|
|
|
|
class Item: public QObject, public ItemData
|
|
{
|
|
Q_OBJECT
|
|
private:
|
|
std::vector< std::shared_ptr<Actor> > actors_;
|
|
|
|
bool override_ = false;
|
|
|
|
public:
|
|
|
|
static bool secondaryFlag;
|
|
|
|
signals:
|
|
|
|
void valueChanged(uint8_t value);
|
|
|
|
private slots:
|
|
virtual void actorSetValue(uint8_t value);
|
|
|
|
public slots:
|
|
|
|
virtual void setValue(uint8_t value);
|
|
|
|
public:
|
|
|
|
Item(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0,
|
|
QObject *parent = nullptr);
|
|
Item(const ItemData& itemData, QObject *parent = nullptr);
|
|
|
|
virtual ~Item();
|
|
|
|
std::vector< std::shared_ptr<Actor> >& getActors();
|
|
bool hasActors();
|
|
void addActor(std::shared_ptr<Actor> actor);
|
|
bool removeActor(std::shared_ptr<Actor> actor);
|
|
void removeAllActors();
|
|
void setActorsActive(bool in);
|
|
void setOverride(const bool in);
|
|
bool getOverride();
|
|
void informValue(uint8_t value);
|
|
|
|
virtual void store(QJsonObject& json);
|
|
virtual void load(const QJsonObject& json, const bool preserve = false);
|
|
|
|
};
|
|
|