26 #include "physfs.h" |
26 #include "physfs.h" |
27 #include "MapModel.h" |
27 #include "MapModel.h" |
28 #include "HWApplication.h" |
28 #include "HWApplication.h" |
29 #include "hwconsts.h" |
29 #include "hwconsts.h" |
30 |
30 |
31 MapModel::MapInfo MapModel::MapInfoRandom = {MapModel::GeneratedMap, "+rnd+", "", 0, "", "", ""}; |
31 MapModel::MapInfo MapModel::MapInfoRandom = {MapModel::GeneratedMap, "+rnd+", "", 0, "", "", "", false}; |
32 MapModel::MapInfo MapModel::MapInfoMaze = {MapModel::GeneratedMaze, "+maze+", "", 0, "", "", ""}; |
32 MapModel::MapInfo MapModel::MapInfoMaze = {MapModel::GeneratedMaze, "+maze+", "", 0, "", "", "", false}; |
33 MapModel::MapInfo MapModel::MapInfoDrawn = {MapModel::HandDrawnMap, "+drawn+", "", 0, "", "", ""}; |
33 MapModel::MapInfo MapModel::MapInfoDrawn = {MapModel::HandDrawnMap, "+drawn+", "", 0, "", "", "", false}; |
34 |
34 |
35 void MapModel::loadMaps(MapType maptype) |
35 |
36 { |
36 MapModel::MapModel(MapType maptype, QObject *parent) : QStandardItemModel(parent) |
|
37 { |
|
38 m_maptype = maptype; |
|
39 m_loaded = false; |
|
40 } |
|
41 |
|
42 bool MapModel::loadMaps() |
|
43 { |
|
44 if(m_loaded) |
|
45 return false; |
|
46 |
|
47 m_loaded = true; |
|
48 |
|
49 qDebug("[LAZINESS] MapModel::loadMaps()"); |
|
50 |
37 // this method resets the contents of this model (important to know for views). |
51 // this method resets the contents of this model (important to know for views). |
38 beginResetModel(); |
52 beginResetModel(); |
39 |
53 |
40 // we'll need the DataManager a few times, so let's get a reference to it |
54 // we'll need the DataManager a few times, so let's get a reference to it |
41 DataManager & datamgr = DataManager::instance(); |
55 DataManager & datamgr = DataManager::instance(); |
73 // if there is a lua file for this map, then it's a mission |
87 // if there is a lua file for this map, then it's a mission |
74 bool isMission = mapLuaFile.exists(); |
88 bool isMission = mapLuaFile.exists(); |
75 MapType type = isMission ? MissionMap : StaticMap; |
89 MapType type = isMission ? MissionMap : StaticMap; |
76 |
90 |
77 // if we're supposed to ignore this type, continue |
91 // if we're supposed to ignore this type, continue |
78 if (type != maptype) continue; |
92 if (type != m_maptype) continue; |
79 |
93 |
80 // load map info from file |
94 // load map info from file |
81 QTextStream input(&mapCfgFile); |
95 QTextStream input(&mapCfgFile); |
82 theme = input.readLine(); |
96 theme = input.readLine(); |
83 limit = input.readLine().toInt(); |
97 limit = input.readLine().toInt(); |
147 } |
161 } |
148 |
162 |
149 QStandardItemModel::appendColumn(mapList); |
163 QStandardItemModel::appendColumn(mapList); |
150 |
164 |
151 endResetModel(); |
165 endResetModel(); |
152 } |
166 |
153 |
167 return true; |
154 bool MapModel::mapExists(const QString & map) const |
168 } |
|
169 |
|
170 bool MapModel::mapExists(const QString & map) |
155 { |
171 { |
156 return findMap(map) >= 0; |
172 return findMap(map) >= 0; |
157 } |
173 } |
158 |
174 |
159 int MapModel::findMap(const QString & map) const |
175 int MapModel::findMap(const QString & map) |
160 { |
176 { |
|
177 loadMaps(); |
|
178 |
161 return m_mapIndexes.value(map, -1); |
179 return m_mapIndexes.value(map, -1); |
162 } |
180 } |
163 |
181 |
164 QStandardItem * MapModel::getMap(const QString & map) |
182 QStandardItem * MapModel::getMap(const QString & map) |
165 { |
183 { |