1 /* 2 * tmxmapformat.h 3 * Copyright 2008-2015, Thorbjørn Lindeijer <bjorn@lindeijer.nl> 4 * 5 * This file is part of Tiled. 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License as published by the Free 9 * Software Foundation; either version 2 of the License, or (at your option) 10 * any later version. 11 * 12 * This program is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 15 * more details. 16 * 17 * You should have received a copy of the GNU General Public License along with 18 * this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #pragma once 22 23 #include "mapformat.h" 24 #include "tilesetformat.h" 25 #include "objecttemplateformat.h" 26 27 namespace Tiled { 28 29 class Tileset; 30 class MapObject; 31 32 33 /** 34 * A reader and writer for Tiled's .tmx map format. 35 */ 36 class TmxMapFormat : public MapFormat 37 { 38 Q_OBJECT 39 Q_INTERFACES(Tiled::MapFormat) 40 41 public: 42 TmxMapFormat(QObject *parent = nullptr); 43 44 std::unique_ptr<Map> read(const QString &fileName) override; 45 46 bool write(const Map *map, const QString &fileName, Options options) override; 47 48 /** 49 * Converts the given map to a utf8 byte array (in .tmx format). This is 50 * for storing a map in the clipboard. References to other files (like 51 * tileset images) will be saved as absolute paths. 52 * 53 * @see fromByteArray 54 */ 55 QByteArray toByteArray(const Map *map); 56 57 /** 58 * Reads the map given from \a data. This is for retrieving a map from the 59 * clipboard. Returns null on failure. 60 * 61 * @see toByteArray 62 */ 63 std::unique_ptr<Map> fromByteArray(const QByteArray &data); 64 nameFilter()65 QString nameFilter() const override { return tr("Tiled map files (*.tmx *.xml)"); } 66 shortName()67 QString shortName() const override { return QStringLiteral("tmx"); } 68 69 bool supportsFile(const QString &fileName) const override; 70 errorString()71 QString errorString() const override { return mError; } 72 73 private: 74 QString mError; 75 }; 76 77 78 /** 79 * A reader and writer for Tiled's .tsx tileset format. 80 */ 81 class TsxTilesetFormat : public TilesetFormat 82 { 83 Q_OBJECT 84 Q_INTERFACES(Tiled::TilesetFormat) 85 86 public: 87 TsxTilesetFormat(QObject *parent = nullptr); 88 89 SharedTileset read(const QString &fileName) override; 90 91 bool write(const Tileset &tileset, const QString &fileName, Options options) override; 92 nameFilter()93 QString nameFilter() const override { return tr("Tiled tileset files (*.tsx *.xml)"); } 94 shortName()95 QString shortName() const override { return QStringLiteral("tsx"); } 96 97 bool supportsFile(const QString &fileName) const override; 98 errorString()99 QString errorString() const override { return mError; } 100 101 private: 102 QString mError; 103 }; 104 105 /** 106 * A reader and writer for Tiled's .tgx template format. 107 */ 108 class XmlObjectTemplateFormat : public ObjectTemplateFormat 109 { 110 Q_OBJECT 111 Q_INTERFACES(Tiled::ObjectTemplateFormat) 112 113 public: 114 XmlObjectTemplateFormat(QObject *parent = nullptr); 115 116 std::unique_ptr<ObjectTemplate> read(const QString &fileName) override; 117 118 bool write(const ObjectTemplate *objectTemplate, const QString &fileName) override; 119 nameFilter()120 QString nameFilter() const override { return tr("Tiled template files (*.tx)"); } 121 shortName()122 QString shortName() const override { return QStringLiteral("tx"); } 123 124 bool supportsFile(const QString &fileName) const override; 125 errorString()126 QString errorString() const override { return mError; } 127 128 private: 129 QString mError; 130 }; 131 132 } // namespace Tiled 133