#include "main.h"
CLevelLoader::CLevelLoader(IrrlichtDevice* dev, CLog* logger, const char mapname[128])
{
device = dev;
log = logger;
memcpy(name, mapname, 128);
memset(&info, 0, sizeof(SLevelInfo));
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
gui::IGUIEnvironment* env = device->getGUIEnvironment();
char map[128];
snprintf(map, 128, "levels/%s.zip", name);
IFileSystem* filesystem = device->getFileSystem();
#ifdef _IRR_WINDOWS_
bool addstate = filesystem->addZipFileArchive(map, true, false); //Ignorowanie wielkosci liter = true
#else
bool addstate = filesystem->addZipFileArchive(map, false, false); //Ignorowanie wielkosci liter = false
#endif
if(!addstate) {
log->error(0, "LVLLOAD", "Failed to add ZIP to filesystem.");
return;
}
log->debug("LVLLOAD", "Added ZIP to filesystem.");
IXMLReader* lvlinfo = filesystem->createXMLReader("level.xml");
if(!lvlinfo) {
log->error(0, "LVLLOAD","Failed to open file.");
return;
}
log->debug("LVLLOAD", "level.dat loaded.");
//Wczytujemy tytul misji:
while(lvlinfo && lvlinfo->read()) {
if(core::stringw("info") == lvlinfo->getNodeName()) {
cout << "Reading title... ";
cout << lvlinfo->getAttributeValueSafe(L"title") << " " << endl;
core::stringw tit = lvlinfo->getAttributeValueSafe(L"title");
core::stringc tit2 = tit.c_str();
const c8* tit3 = tit2.c_str();
memcpy(&(info.title), tit3, 256); //info.title = tit3;
cout << "Viewing... ";
cout << info.title << endl;
}
}
log->debug("LVLLOAD", "Game title loaded.");
//Koniec tego pliku:
lvlinfo->drop();
log->debug("LVLLOAD", "level.dat unloaded.");
char str[128];
snprintf(str, 128, "Loaded level: %s (%s)", info.title, name);
log->info("LVLLOAD", str);
}
CLevelLoader::~CLevelLoader()
{
char map[128];
snprintf(map, 128, "levels/%s.zip", name);
device->getFileSystem()->removeFileArchive(map);
char str[128];
snprintf(str, 128, "Unloaded level: %s (%s)", info.title, name);
log->info("LVLLOAD", str);
}