1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00
vcmi/CPreGameTextHandler.cpp

127 lines
2.1 KiB
C++
Raw Normal View History

#include "stdafx.h"
#include "CPreGameTextHandler.h"
std::string CPreGameTextHandler::getTitle(std::string text)
{
std::string ret;
int i=0;
while ((text[i++]!='{'));
while ((text[i]!='}') && (i<text.length()))
ret+=text[i++];
return ret;
}
std::string CPreGameTextHandler::getDescr(std::string text)
{
std::string ret;
int i=0;
while ((text[i++]!='}'));
i+=2;
while ((text[i]!='"') && (i<text.length()))
ret+=text[i++];
return ret;
}
void CPreGameTextHandler::loadTexts()
{
std::ifstream inp("H3bitmap.lod\\ZELP.TXT", std::ios::in|std::ios::binary);
inp.seekg(0,std::ios::end); // na koniec
int andame = inp.tellg(); // read length
inp.seekg(0,std::ios::beg); // wracamy na poczatek
char * bufor = new char[andame]; // allocate memory
inp.read((char*)bufor, andame); // read map file to buffer
std::string buf = std::string(bufor);
delete [andame] bufor;
int i=0; //buf iterator
int hmcr=0;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
++hmcr;
if(hmcr==3)
break;
}
i+=3;
int befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
mainNewGame = buf.substr(befi, i-befi);
++i;
hmcr = 0;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
++hmcr;
if(hmcr==1)
break;
}
i+=3;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
mainLoadGame = buf.substr(befi, i-befi);
++i;
hmcr = 0;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
++hmcr;
if(hmcr==1)
break;
}
i+=3;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
mainHighScores = buf.substr(befi, i-befi);
++i;
hmcr = 0;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
++hmcr;
if(hmcr==1)
break;
}
i+=3;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
mainCredits = buf.substr(befi, i-befi);
++i;
hmcr = 0;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
++hmcr;
if(hmcr==1)
break;
}
i+=3;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
mainQuit = buf.substr(befi, i-befi);
++i;
}