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 CAMPAIGNMANAGER_H
0021 #define CAMPAIGNMANAGER_H
0022 
0023 #include <QObject>
0024 #include <QString>
0025 #include <memory>
0026 
0027 #include "data/campaign.h"
0028 #include "media/mediatype.h"
0029 #include <core_global.h>
0030 
0031 class DiceRoller;
0032 namespace campaign
0033 {
0034 class Media;
0035 class CampaignEditor;
0036 class CampaignUpdater;
0037 class AntagonistBoardController;
0038 
0039 class CORE_EXPORT CampaignManager : public QObject
0040 {
0041     Q_OBJECT
0042     Q_PROPERTY(campaign::Campaign* campaign READ campaign NOTIFY campaignChanged)
0043 public:
0044     explicit CampaignManager(DiceRoller* diceparser, QObject* parent= nullptr);
0045     virtual ~CampaignManager();
0046 
0047     bool createCampaign(const QUrl& dir);
0048     QString importFile(const QUrl& dir);
0049     QString createFileFromData(const QString& name, const QByteArray& data);
0050     void removeFile(const QString& file);
0051     void reload();
0052 
0053     void saveCampaign();
0054     void copyCampaign(const QUrl& dir);
0055     void openCampaign(const QUrl& dir);
0056 
0057     campaign::Campaign* campaign() const;
0058     campaign::CampaignEditor* editor() const;
0059 
0060     DiceRoller* diceparser() const;
0061 
0062     QString campaignDir() const;
0063     QString placeDirectory(campaign::Campaign::Place place) const;
0064 
0065     void performAction(const QList<QPair<QString, Core::CampaignAction>>& actions);
0066 
0067 public slots:
0068     void shareModels();
0069     void setLocalIsGM(bool b);
0070     void importDataFrom(const QString& source, const QVector<Core::CampaignDataCategory>& categories);
0071 
0072 signals:
0073     void campaignChanged(const QString& str);
0074     void campaignLoaded(const QStringList missingFiles, const QStringList unmanagedFiles);
0075     void fileImported(campaign::Media* path);
0076     void errorOccured(const QString& error);
0077     void createBlankFile(const QString& path, Core::MediaType mediaType);
0078 
0079     void antagonistCtrlChanged();
0080 
0081 private:
0082     std::unique_ptr<CampaignEditor> m_editor;
0083     std::unique_ptr<CampaignUpdater> m_campaignUpdater;
0084 };
0085 } // namespace campaign
0086 
0087 #endif // CAMPAIGNMANAGER_H