File indexing completed on 2024-05-12 05:39:49
0001 /*************************************************************************** 0002 * Copyright (C) 2021 by Renaud Guezennec * 0003 * http://www.rolisteam.org/contact * 0004 * * 0005 * This software is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0019 ***************************************************************************/ 0020 #ifndef CAMPAIGN_H 0021 #define CAMPAIGN_H 0022 0023 #include <QObject> 0024 #include <QString> 0025 #include <memory> 0026 0027 #include "data/rolisteamtheme.h" 0028 #include "media/mediatype.h" 0029 #include <core_global.h> 0030 0031 #include "model/characterstatemodel.h" 0032 #include "model/dicealiasmodel.h" 0033 #include "model/nonplayablecharactermodel.h" 0034 0035 class DiceAliasModel; 0036 class CharacterStateModel; 0037 namespace campaign 0038 { 0039 class Media; 0040 class NonPlayableCharacterModel; 0041 constexpr char const* TRASH_FOLDER{".trash"}; 0042 constexpr char const* MODEL_FILE{"data.json"}; 0043 constexpr char const* THEME_FILE{"theme.json"}; 0044 constexpr char const* FIRST_AUDIO_PLAYER_FILE{"audioplayer1.json"}; 0045 constexpr char const* SECOND_AUDIO_PLAYER_FILE{"audioplayer2.json"}; 0046 constexpr char const* THIRD_AUDIO_PLAYER_FILE{"audioplayer3.json"}; 0047 constexpr char const* DICE_ALIAS_MODEL{"dice_command.json"}; 0048 constexpr char const* STATE_MODEL{"states.json"}; 0049 constexpr char const* MEDIA_ROOT{"media"}; 0050 constexpr char const* STATE_ROOT{"states"}; 0051 constexpr char const* CHARACTER_ROOT{"npcs"}; 0052 constexpr char const* CHARACTER_MODEL{"npc.json"}; 0053 0054 class CORE_EXPORT Campaign : public QObject 0055 { 0056 Q_OBJECT 0057 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 0058 Q_PROPERTY(QString rootDirectory READ rootDirectory WRITE setRootDirectory NOTIFY rootDirectoryChanged) 0059 Q_PROPERTY(QString currentChapter READ currentChapter WRITE setCurrentChapter NOTIFY currentChapterChanged) 0060 Q_PROPERTY(DiceAliasModel* diceAliases READ diceAliases NOTIFY diceAliasesChanged) 0061 Q_PROPERTY(CharacterStateModel* stateModel READ stateModel NOTIFY stateModelChanged) 0062 Q_PROPERTY(NonPlayableCharacterModel* npcModel READ npcModel NOTIFY npcModelChanged) 0063 Q_PROPERTY(RolisteamTheme* currentTheme READ currentTheme WRITE setCurrentTheme NOTIFY currentThemeChanged) 0064 Q_PROPERTY(State state READ state WRITE setState NOTIFY stateChanged) 0065 Q_PROPERTY(qint64 diskUsage READ diskUsage NOTIFY diskUsageChanged) 0066 Q_PROPERTY(int fileCount READ fileCount NOTIFY fileCountChanged) 0067 public: 0068 explicit Campaign(QObject* parent= nullptr); 0069 enum class State : quint8 0070 { 0071 None, 0072 Checking, 0073 Ready 0074 }; 0075 Q_ENUM(State); 0076 enum class Move 0077 { 0078 UP, 0079 DOWN, 0080 BOTTOM, 0081 TOP 0082 }; 0083 enum class Place : quint8 0084 { 0085 MEDIA_ROOT, 0086 STATE_ROOT, 0087 STATE_MODEL, 0088 TRASH_ROOT, 0089 NPC_ROOT, 0090 NPC_MODEL, 0091 THEME_FILE, 0092 DICE_MODEL, 0093 FIRST_AUDIO_PLAYER_FILE, 0094 SECOND_AUDIO_PLAYER_FILE, 0095 THIRD_AUDIO_PLAYER_FILE, 0096 }; 0097 Q_ENUM(Place); 0098 0099 virtual ~Campaign(); 0100 0101 QString name() const; 0102 QString rootDirectory() const; 0103 QString currentChapter() const; 0104 DiceAliasModel* diceAliases() const; 0105 CharacterStateModel* stateModel() const; 0106 RolisteamTheme* currentTheme() const; 0107 NonPlayableCharacterModel* npcModel() const; 0108 State state() const; 0109 qint64 diskUsage() const; 0110 int fileCount() const; 0111 0112 QString currentStorePath() const; 0113 0114 void addMedia(std::unique_ptr<Media>&& media); 0115 void removeMedia(const QString& id); 0116 const std::vector<std::unique_ptr<Media>>& medias() const; 0117 Media* mediaFromPath(const QString& path) const; 0118 Media* mediaFromUuid(const QString& uuid) const; 0119 QString pathFromUuid(const QString& uuid) const; 0120 0121 QString directory(Place place) const; 0122 0123 public slots: 0124 void setRootDirectory(const QString& root); 0125 void setCurrentChapter(const QString& chapter); 0126 void setCurrentTheme(RolisteamTheme* themeuri); 0127 void setName(const QString& name); 0128 void postError(const QString& msg); 0129 void renameMedia(const QString& id, const QString& name); 0130 0131 // alias 0132 void addAlias(); 0133 void deleteAlias(const QModelIndex& index); 0134 void moveAlias(const QModelIndex& index, campaign::Campaign::Move move); 0135 QString convertAlias(const QString& str); 0136 0137 // states 0138 void addState(); 0139 void deleteState(const QModelIndex& index); 0140 void moveState(const QModelIndex& index, campaign::Campaign::Move move); 0141 0142 // Characters 0143 void addCharacter(); 0144 void removeCharacter(const QString& id); 0145 0146 private slots: 0147 void setState(campaign::Campaign::State state); 0148 0149 signals: 0150 void rootDirectoryChanged(); 0151 void currentChapterChanged(); 0152 0153 // models 0154 void diceAliasesChanged(); 0155 void stateModelChanged(); 0156 void npcModelChanged(); 0157 0158 void currentThemeChanged(); 0159 void stateChanged(); 0160 void nameChanged(); 0161 void errorOccured(QString msg); 0162 void mediaAdded(campaign::Media* media); 0163 void mediaNameChanged(); 0164 void mediaRemoved(const QString& id); 0165 void diskUsageChanged(); 0166 void fileCountChanged(); 0167 0168 private: 0169 std::vector<std::unique_ptr<campaign::Media>> m_mediaList; 0170 std::unique_ptr<DiceAliasModel> m_diceModel; 0171 std::unique_ptr<CharacterStateModel> m_stateModel; 0172 std::unique_ptr<campaign::NonPlayableCharacterModel> m_npcModel; 0173 QString m_name; 0174 QString m_root; 0175 QString m_currentChapter; 0176 std::unique_ptr<RolisteamTheme> m_theme; 0177 State m_state= State::None; 0178 }; 0179 } // namespace campaign 0180 #endif // CAMPAIGN_H