forked from damar1st/TSTO-Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassetmanager.h
89 lines (71 loc) · 2.9 KB
/
assetmanager.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
#ifndef ASSETMANAGER_H
#define ASSETMANAGER_H
#include <QMap>
#include <QImage>
#include <QColor>
#include <QPoint>
#include <QXmlStreamReader>
#include "buildinginfo.h"
class RGBFile;
class QuaZip;
class QIODevice;
class QStandardItemModel;
typedef QMap< int, BuildingInfo* > BuildingsMapById;
typedef QMap< QString, BuildingInfo* > BuildingsMapByName;
typedef QMultiMap< QString, BuildingInfo* > BuildingsMultiMap;
typedef QVector< QuaZip* > ZipsVector;
class AssetManager {
friend class DlcFilesModel;
public:
static AssetManager* instance();
bool setBaseDirs(const QString & scripts, const QStringList & game);
// get info for building/decoration
BuildingInfo * getBuildingInfo(int id, int flipState = 0, QImage ** rimg = nullptr);
bool isBuildingUnique(int id) const;
bool isBuildingWithCharacterOrJob(int id) const;
int getBuildingGridType(int id, int flipState, QPoint &s) const;
// models for categories
QStandardItemModel * modelByName();
QStandardItemModel * modelByType();
QStandardItemModel * modelByGroup();
QStandardItemModel * modelByFile();
QStandardItemModel * modelByRating();
QStandardItemModel * modelByBonus();
QStandardItemModel * modelByGridType();
QStandardItemModel * modelById();
// tiles for roads/rivers/ocean
const QVector<QImage> tileSheets() const { return mTileSheet; }
QImage * getRoadTile(int idx) { return mRoadTiles[idx]; }
QImage * getRiverTile(int idx) { return mRiverTiles[idx]; }
QImage * getOceanTile(int idx) { return mOceanTiles[idx]; }
const QList<int> roadTilesNames() const { return mRoadTiles.keys(); }
const QList<int> riverTilesNames() const { return mRiverTiles.keys(); }
const QList<int> oceanTilesNames() const { return mOceanTiles.keys(); }
private:
static AssetManager * mSelf;
BuildingsMapById mById;
BuildingsMapByName mByName;
BuildingsMultiMap mByType;
BuildingsMultiMap mByGroup;
BuildingsMultiMap mByFile;
BuildingsMultiMap mByRating;
BuildingsMultiMap mByBonus;
BuildingsMultiMap mByGridType;
ZipsVector mGameAssets;
QVector<QImage> mTileSheet;
QMap<int, QImage*> mRoadTiles;
QMap<int, QImage*> mRiverTiles;
QMap<int, QImage*> mOceanTiles;
AssetManager();
~AssetManager();
bool loadScripts(const QString &scriptsPath);
void loadAssets(const QStringList & assetsPaths);
void loadTiles(QColor defaultTile = QColor(102, 187, 102));
void generateTileAlphaChannel(QImage & alpha, int & w, int & h);
QImage * makeTile(int w, int h, const QImage & l, const QImage & t, const QImage & r, const QImage & b);
QIODevice* openGameAsset(const QString & name, QuaZip ** zip = nullptr);
bool fetchBuildingsData(const QString &, QIODevice *);
bool fetchBuildingsAssetData(const QString &, QIODevice *);
QStandardItemModel * modelFromMap(BuildingsMultiMap &);
};
#endif // ASSETMANAGER_H