94
SDL_Surface* File::loadImage(string filename, bool alpha)
96
SDL_Surface* tmp = IMG_Load(filename.c_str());
99
cerr << _("ERROR: Couldn't load image ") << filename << endl;
103
SDL_Surface* convertedImage;
106
convertedImage = SDL_DisplayFormatAlpha(tmp);
107
// strip alpha channel if any
109
convertedImage = SDL_DisplayFormat(tmp);
110
SDL_FreeSurface(tmp);
112
return convertedImage;
94
std::string getArmysetDir()
96
return Configuration::s_dataPath + "/" + ARMYSETDIR + "/";
99
std::string getTilesetDir()
101
return Configuration::s_dataPath + "/" + TILESETDIR + "/";
104
std::string getCitysetDir()
106
return Configuration::s_dataPath + "/" + CITYSETDIR + "/";
109
std::string getShieldsetDir()
111
return Configuration::s_dataPath + "/" + SHIELDSETDIR + "/";
114
std::string getCampaignDir()
116
return Configuration::s_dataPath + "/" + CAMPAIGNDIR + "/";
116
119
std::list<std::string> File::scanArmysets()
118
string path = Configuration::s_dataPath + "/army/";
120
std::list<std::string> retlist = get_xml_files_in_immediate_subdirs(path);
121
std::list<std::string> retlist =
122
get_xml_files_in_immediate_subdirs(getArmysetDir());
122
124
if (retlist.empty())
124
cerr << _("Couldn't find any armysets!") << endl;
125
cerr << _("Please check the path settings in /etc/lordsawarrc or ~/.lordsawarrc") << endl;
126
cerr << _("Exiting!") << endl;
126
std::cerr << "Couldn't find any armysets!" << std::endl;
127
std::cerr << "Please check the path settings in /etc/lordsawarrc or ~/.lordsawarrc" << std::endl;
128
std::cerr << "Exiting!" << std::endl;
134
string File::getArmyset(string armysetname)
136
return Configuration::s_dataPath + "/army/" + armysetname + "/" +
137
armysetname + ".xml";
140
SDL_Surface* File::getArmyPicture(string armysetname, string pic)
142
return loadImage(Configuration::s_dataPath + "/army/" + armysetname + "/" + pic);
146
string File::getTileset(string tilesetname)
148
return Configuration::s_dataPath + "/tilesets/" + tilesetname + "/" + tilesetname + ".xml";
151
std::string File::getTilesetFile(string tilesetname, string picname)
153
return Configuration::s_dataPath + "/tilesets/" + tilesetname + "/" + picname;
156
SDL_Surface* File::getTilesetPicture(string tilesetname, string picname)
158
return loadImage(getTilesetFile(tilesetname, picname));
161
string File::getMiscFile(string filename)
163
return Configuration::s_dataPath + "/" + filename;
166
string File::getCityset(string citysetname)
168
return Configuration::s_dataPath + "/citysets/" + citysetname + "/" + citysetname + ".xml";
171
std::string File::getCitysetFile(string citysetname, string picname)
173
return Configuration::s_dataPath + "/citysets/" + citysetname + "/" + picname;
176
SDL_Surface* File::getCitysetPicture(string citysetname, string picname)
178
return loadImage(getCitysetFile(citysetname, picname));
181
SDL_Surface* File::getMiscPicture(string picname, bool alpha)
183
return loadImage(Configuration::s_dataPath + "/various/" + picname,alpha);
187
SDL_Surface* File::getItemPicture(string picname)
189
return loadImage(Configuration::s_dataPath + "/various/items/" + picname + ".png");
192
string File::getItemDescription()
194
return Configuration::s_dataPath + "/various/items/items.xml";
135
std::string File::getArmyset(std::string armysetsubdir)
137
return getArmysetDir() + armysetsubdir + "/" + armysetsubdir + ".xml";
140
std::string File::getTileset(std::string tilesetsubdir)
142
return getTilesetDir() + tilesetsubdir + "/" + tilesetsubdir + ".xml";
145
std::string File::getTilesetFile(std::string tilesetsubdir, std::string picname)
147
return getTilesetDir() + tilesetsubdir + "/" + picname;
150
std::string File::getShieldsetFile(std::string shieldsetsubdir, std::string picname)
152
return getShieldsetDir() + shieldsetsubdir + "/" + picname;
155
std::string File::getMiscFile(std::string filename)
157
return Configuration::s_dataPath + "/" + filename;
160
std::string File::getCityset(std::string citysetdir)
162
return getCitysetDir() + citysetdir + "/" + citysetdir + ".xml";
165
std::string File::getCitysetFile(std::string citysetsubdir, std::string picname)
167
return getCitysetDir() + citysetsubdir + "/" + picname;
170
std::string File::getItemDescription()
172
return Configuration::s_dataPath + "/various/items/items.xml";
198
175
std::string File::getEditorFile(std::string filename)
200
return Configuration::s_dataPath + "/various/editor/" + filename + ".png";
203
SDL_Surface* File::getEditorPic(std::string filename)
205
return loadImage(getEditorFile(filename));
177
return Configuration::s_dataPath + "/various/editor/" + filename + ".png";
208
180
std::string File::getMusicFile(std::string filename)
210
return std::string(Configuration::s_dataPath + "/music/" + filename.c_str());
213
string File::getSavePath()
182
return std::string(Configuration::s_dataPath + "/music/" + filename.c_str());
185
std::string File::getCampaignFile(std::string filename)
187
return getCampaignDir() + "/" + filename;
190
std::string File::getSavePath()
215
192
return Configuration::s_savePath + "/";
218
list<string> File::scanTilesets()
220
string path = Configuration::s_dataPath + "/tilesets/";
221
std::list<std::string> retlist = get_xml_files_in_immediate_subdirs(path);
225
cerr << _("Couldn't find any tilesets!") << endl;
226
cerr << _("Please check the path settings in /etc/lordsawarrc or ~/.lordsawarrc") << endl;
227
cerr << _("Exiting!") << endl;
234
list<string> File::scanCitysets()
236
string path = Configuration::s_dataPath + "/citysets/";
237
std::list<std::string> retlist = get_xml_files_in_immediate_subdirs(path);
241
cerr << _("Couldn't find any citysets!") << endl;
242
cerr << _("Please check the path settings in /etc/lordsawarrc or ~/.lordsawarrc") << endl;
243
cerr << _("Exiting!") << endl;
250
list<string> File::scanMaps()
252
string path = Configuration::s_dataPath + "/map/";
254
std::list<std::string> retlist;
257
for (Glib::Dir::iterator i = dir.begin(), end = dir.end(); i != end; ++i)
260
string::size_type idx = entry.find(".map");
261
if (idx != string::npos)
263
retlist.push_back(Glib::filename_to_utf8(entry));
269
cerr << _("Couldn't find a single map!") << endl;
270
cerr << _("Please check the path settings in /etc/lordsawarrc or ~/.lordsawarrc") << endl;
195
std::list<std::string> File::scanTilesets()
197
std::list<std::string> retlist =
198
get_xml_files_in_immediate_subdirs(getTilesetDir());
202
std::cerr << "Couldn't find any tilesets!" << std::endl;
203
std::cerr << "Please check the path settings in /etc/lordsawarrc or ~/.lordsawarrc" << std::endl;
204
std::cerr << "Exiting!" << std::endl;
211
std::list<std::string> File::scanCitysets()
213
std::list<std::string> retlist =
214
get_xml_files_in_immediate_subdirs(getCitysetDir());
218
std::cerr << "Couldn't find any citysets!" << std::endl;
219
std::cerr << "Please check the path settings in /etc/lordsawarrc or ~/.lordsawarrc" << std::endl;
220
std::cerr << "Exiting!" << std::endl;
227
std::list<std::string> File::scanCampaigns()
229
std::string campaign;
230
std::string path = getCampaignDir();
231
std::list<std::string> retlist;
234
for (Glib::Dir::iterator i = dir.begin(), end = dir.end(); i != end; ++i)
236
std::string entry = *i;
237
std::string::size_type idx = entry.find(".map");
238
if (idx != std::string::npos)
240
retlist.push_back(Glib::filename_to_utf8(entry));
246
std::cerr << "Couldn't find a single campaign!" << std::endl;
247
std::cerr << "Please check the path settings in /etc/lordsawarrc or ~/.lordsawarrc" << std::endl;
250
//now we find the ones that are pointed to, and remove them
251
for (std::list<std::string>::iterator it = retlist.begin();
252
it != retlist.end();)
254
campaign = Campaign::get_campaign_from_scenario_file(path + "/" + *it);
255
std::list<std::string>::iterator cit;
256
cit = find (retlist.begin(), retlist.end(), campaign);
257
if (cit != retlist.end())
268
std::list<std::string> File::scanMaps()
270
std::string path = Configuration::s_dataPath + "/" + MAPDIR + "/";
272
std::list<std::string> retlist;
275
for (Glib::Dir::iterator i = dir.begin(), end = dir.end(); i != end; ++i)
277
std::string entry = *i;
278
std::string::size_type idx = entry.find(".map");
279
if (idx != std::string::npos)
281
retlist.push_back(Glib::filename_to_utf8(entry));
287
std::cerr << "Couldn't find a single map!" << std::endl;
288
std::cerr << "Please check the path settings in /etc/lordsawarrc or ~/.lordsawarrc" << std::endl;
277
294
std::list<std::string> File::scanShieldsets()
279
string path = Configuration::s_dataPath + "/shield/";
281
std::list<std::string> retlist = get_xml_files_in_immediate_subdirs(path);
296
std::list<std::string> retlist =
297
get_xml_files_in_immediate_subdirs(getShieldsetDir());
283
299
if (retlist.empty())
285
cerr << _("Couldn't find any shieldsets!") << endl;
286
cerr << _("Please check the path settings in /etc/lordsawarrc or ~/.lordsawarrc") << endl;
287
cerr << _("Exiting!") << endl;
301
std::cerr << "Couldn't find any shieldsets!" << std::endl;
302
std::cerr << "Please check the path settings in /etc/lordsawarrc or ~/.lordsawarrc" << std::endl;
303
std::cerr << "Exiting!" << std::endl;
295
string File::getShieldset(string shieldsetname)
297
return Configuration::s_dataPath + "/shield/" + shieldsetname + "/" +
298
shieldsetname + ".xml";
301
SDL_Surface* File::getShieldPicture(string shieldsetname, string pic)
303
return loadImage(Configuration::s_dataPath + "/shield/" + shieldsetname + "/" + pic);
310
std::string File::getShieldset(std::string shieldsetsubdir)
312
return getShieldsetDir() + shieldsetsubdir + "/" + shieldsetsubdir + ".xml";