qt6windows7/examples/corelib/serialization/savegame/character.h

47 lines
922 B
C
Raw Normal View History

2023-10-30 06:33:08 +08:00
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef CHARACTER_H
#define CHARACTER_H
#include <QJsonObject>
#include <QObject>
#include <QString>
2023-11-02 01:02:52 +08:00
QT_FORWARD_DECLARE_CLASS(QTextStream)
2023-10-30 06:33:08 +08:00
//! [0]
class Character
{
Q_GADGET
public:
2023-11-02 01:02:52 +08:00
enum ClassType { Warrior, Mage, Archer };
2023-10-30 06:33:08 +08:00
Q_ENUM(ClassType)
Character();
Character(const QString &name, int level, ClassType classType);
QString name() const;
void setName(const QString &name);
int level() const;
void setLevel(int level);
ClassType classType() const;
void setClassType(ClassType classType);
2023-11-02 01:02:52 +08:00
static Character fromJson(const QJsonObject &json);
QJsonObject toJson() const;
void print(QTextStream &s, int indentation = 0) const;
2023-10-30 06:33:08 +08:00
private:
QString mName;
int mLevel = 0;
ClassType mClassType = Warrior;
};
//! [0]
#endif // CHARACTER_H