File indexing completed on 2024-05-12 05:39:54

0001 /***************************************************************************
0002  *  Copyright (C) 2019 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 CORE_FILESERIALIZER_H
0021 #define CORE_FILESERIALIZER_H
0022 
0023 #include <QFuture>
0024 #include <QJsonArray>
0025 #include <QJsonObject>
0026 #include <QObject>
0027 #include <QStringList>
0028 
0029 #include <memory>
0030 #include <vector>
0031 
0032 #include "media/mediatype.h"
0033 #include <core_global.h>
0034 class DiceAlias;
0035 class CharacterState;
0036 namespace campaign
0037 {
0038 class CampaignManager;
0039 class Campaign;
0040 class NonPlayableCharacter;
0041 struct CORE_EXPORT CampaignInfo
0042 {
0043     bool status;
0044     QJsonObject asset;
0045     QJsonObject theme;
0046     QJsonArray dices;
0047     QJsonArray states;
0048     QJsonArray npcs;
0049     QStringList errors;
0050     QStringList unmanagedFiles;
0051     QStringList missingFiles;
0052 };
0053 
0054 class CORE_EXPORT FileSerializer
0055 {
0056 public:
0057     FileSerializer();
0058     static Core::MediaType typeFromExtention(const QString& filename);
0059     static CampaignInfo readCampaignDirectory(const QString& directory);
0060 
0061     static QJsonObject campaignToObject(Campaign* campaign);
0062 
0063     static QJsonArray statesToArray(const std::vector<std::unique_ptr<CharacterState>>& vec,
0064                                     const QString& destination);
0065     static QJsonArray dicesToArray(const std::vector<std::unique_ptr<DiceAlias>>& vec);
0066     static QJsonArray npcToArray(const std::vector<std::unique_ptr<campaign::NonPlayableCharacter>>& vec,
0067                                  const QString& destination);
0068 
0069     static void writeStatesIntoCampaign(const QString& destination, const QJsonArray& array);
0070     static void writeDiceAliasIntoCampaign(const QString& destination, const QJsonArray& array);
0071     static void writeCampaignInfo(const QString& destination, const QJsonObject& object);
0072     static void writeNpcIntoCampaign(const QString& destination, const QJsonArray& array);
0073     static bool createCampaignDirectory(const QString& path);
0074     static QFuture<bool> writeFileIntoCampaign(const QString& destination, const QByteArray& array);
0075 
0076     static QString contentTypeToDefaultExtension(Core::ContentType type);
0077     static QString addExtention(const QString& name, Core::ContentType);
0078 
0079     static bool isValidCampaignDirectory(const QString& path, bool acceptEmpty= true);
0080     static bool hasContent(const QString& path, Core::CampaignDataCategory category);
0081 };
0082 } // namespace campaign
0083 
0084 #endif // CORE_FILESERIALIZER_H