-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
varianttomapconverter.h
120 lines (103 loc) · 4.09 KB
/
varianttomapconverter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* varianttomapconverter.h
* Copyright 2011, Porfírio José Pereira Ribeiro <porfirioribeiro@gmail.com>
* Copyright 2011-2015, Thorbjørn Lindeijer <thorbjorn@lindeijer.nl>
*
* This file is part of Tiled.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "gidmapper.h"
#include "mapobject.h"
#include <QCoreApplication>
#include <QDir>
#include <QVariant>
namespace Tiled {
class GroupLayer;
class Layer;
class Map;
class ObjectGroup;
class ObjectTemplate;
class Tileset;
class WangColor;
/**
* Converts a QVariant to a Map instance. Meant to be used together with
* JsonReader.
*/
class TILEDSHARED_EXPORT VariantToMapConverter
{
// Using the MapReader context since the messages are the same
Q_DECLARE_TR_FUNCTIONS(MapReader)
public:
VariantToMapConverter()
: mMap(nullptr)
, mReadingExternalTileset(false)
{}
/**
* Tries to convert the given \a variant to a Map instance. The \a mapDir
* is necessary to resolve any relative references to external images.
*
* Returns 0 in case of an error. The error can be obstained using
* errorString().
*/
std::unique_ptr<Map> toMap(const QVariant &variant, const QDir &mapDir);
/**
* Tries to convert the given \a variant to a Tileset instance. The
* \a directory is necessary to resolve any relative references to external
* images.
*
* Returns 0 in case of an error. The error can be obstained using
* errorString().
*/
SharedTileset toTileset(const QVariant &variant, const QDir &directory);
/**
* Tries to convert the given \a variant to an ObjectTemplate instance. The
* \a directory is necessary to resolve any relative references to external
* tilesets.
*/
std::unique_ptr<ObjectTemplate> toObjectTemplate(const QVariant &variant, const QDir &directory);
/**
* Returns the last error, if any.
*/
QString errorString() const { return mError; }
private:
Properties toProperties(const QVariant &propertiesVariant,
const QVariant &propertyTypesVariant) const;
SharedTileset toTileset(const QVariant &variant);
std::unique_ptr<WangSet> toWangSet(const QVariantMap &variantMap, Tileset *tileset);
QSharedPointer<WangColor> toWangColor(const QVariantMap &variantMap);
std::unique_ptr<ObjectTemplate> toObjectTemplate(const QVariant &variant);
std::unique_ptr<Layer> toLayer(const QVariant &variant);
std::unique_ptr<TileLayer> toTileLayer(const QVariantMap &variantMap);
std::unique_ptr<ObjectGroup> toObjectGroup(const QVariantMap &variantMap);
std::unique_ptr<MapObject> toMapObject(const QVariantMap &variantMap);
std::unique_ptr<ImageLayer> toImageLayer(const QVariantMap &variantMap);
std::unique_ptr<GroupLayer> toGroupLayer(const QVariantMap &variantMap);
QPolygonF toPolygon(const QVariant &variant) const;
TextData toTextData(const QVariantMap &variant) const;
void readMapEditorSettings(Map &map, const QVariantMap &editorSettings);
void readTilesetEditorSettings(Tileset &tileset, const QVariantMap &editorSettings);
bool readTileLayerData(TileLayer &tileLayer,
const QVariant &dataVariant,
Map::LayerDataFormat layerDataFormat,
QRect bounds);
Properties extractProperties(const QVariantMap &variantMap) const;
Map *mMap;
QDir mDir;
bool mReadingExternalTileset;
GidMapper mGidMapper;
QString mError;
};
} // namespace Tiled